最後終於還是找到原因了,在這裡記錄一下
先來看一下我買到的商品,IIC chip 是 NXP Semiconductors (Philips) 的 PCF8574AT
組合..
<接線>
函式庫下載請到參考資料[1],[2] 下載,兩個都可以用,這裡我先以參考資料[3],使用 New LiquidCrystal 的 LiquidCrystal_V1.3.4
而程式也延用如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| /* YourDuino.com Example Software Sketch 16 character 2 line I2C Display Backpack Interface labelled "A0 A1 A2" at lower right. ..and Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1" MOST use address 0x27, a FEW use 0x3F terry@yourduino.com */ /*-----( Import needed libraries )-----*/ #include <Wire.h> // Comes with Arduino IDE // Get the LCD I2C Library here: // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads // Move any other LCD libraries to another folder or delete them // See Library "Docs" folder for possible commands etc. #include <LiquidCrystal_I2C.h> /*-----( Declare Constants )-----*/ /*-----( Declare objects )-----*/ // set the LCD address to 0x27 for a 16 chars 2 line display // A FEW use address 0x3F // Set the pins on the I2C chip used for LCD connections: // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address /*-----( Declare Variables )-----*/ //NONE void setup() /*----( SETUP: RUNS ONCE )----*/ { Serial.begin(9600); // Used to type in characters lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight // ------- Quick 3 blinks of backlight ------------- for(int i = 0; i< 3; i++) { lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); } lcd.backlight(); // finish with backlight on //-------- Write characters on the display ------------------ // NOTE: Cursor Position: (CHAR, LINE) start at 0 lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Hello, world!"); delay(1000); lcd.setCursor(0,1); lcd.print("HI! I'am KMode"); delay(8000); // Wait and then tell user they can start the Serial Monitor and type in characters to // Display. (Set Serial Monitor option to "No Line Ending") lcd.clear(); lcd.setCursor(0,0); //Start at character 0 on line 0 lcd.print("Use Serial Mon"); lcd.setCursor(0,1); lcd.print("Type to display"); }/*--(end setup )---*/ void loop() /*----( LOOP: RUNS CONSTANTLY )----*/ { { // when characters arrive over the serial port... if (Serial.available()) { // wait a bit for the entire message to arrive delay(100); // clear the screen lcd.clear(); // read all the available characters while (Serial.available() > 0) { // display each character to the LCD lcd.write(Serial.read()); } } } }/* --(end main loop )-- */ /* ( THE END ) */ |
<I2C Device Address>
當程式下載到 Arduino 後會發現完全沒有畫面!
一開始我想到的有兩件事
1. 線有沒有接對? →才兩條線,檢查了十次,把他們交換了,還是完全沒有畫面
2. I2C Address 有沒有正確? →用電錶檢查了 A0, A1, A2 電壓都在高準位,應該沒問題
但看了程式註解中有一段 "A FEW use address 0x3F" 所以試試看,果然一試就有畫面了
這一切都是阿共仔的陰謀啦!在淘寶上購買時附的"使用說明"內是這樣說的...
對照內附的 TI PCF8574 datasheet 也沒錯,表是複製過來的
But,人生最厲害的就是這個 But,模組上用的 IC 是 Philips Semiconductors (也就是現在的 NXP) 出的 PCF8574A,下載 NXP 版的 datasheet 就發現,第一頁開宗明義的說
"Address by 3 hardware address pins for use of up to 8 devices (up to 16 with PCF8574A)"
"The PCF8574 and PCF8574A versions differ only in their slave address as shown in Fig.10."
一看到 Fig.10 就明暸 "A FEW use address 0x3F" 其實是看你拿到的IC 型號啦,像我拿到的是 PCF8574AT,A0, A1, A2 電壓都是高準位,當然 address = 0x3F
這樣一切就都真象大白了,退堂!
參考資料
1. (函式庫) New LiquidCrystal
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
2. (函式庫) LiquidCrystal_I2C1602V1
https://github.com/openenergymonitor/LiquidCrystal_I2C1602V1
3. LCD Displays (Blue and Yellow) with I2C/TWI Interface
https://arduino-info.wikispaces.com/LCD-Blue-I2C
4. I2C 16x2 LCD 介紹
http://coopermaa2nd.blogspot.tw/2012/09/i2c-16x2-lcd.html
作者已經移除這則留言。
回覆刪除我在程式碼中改成
回覆刪除LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
為何還是沒有辦法顯出字 ??
懇請解惑~感恩 !
先確認一下你的IIC address 用以下這個程式, 先上傳至你的版子, 再用 序列埠監控視窗, 就可以看到你的IIC 設備的ADDRESS 了 再修改位置就可以顥示了.
刪除#include
#define SERIAL_BAUD 9600
void setup()
{
Wire.begin();
Serial.begin(SERIAL_BAUD);
Serial.println("I2C Scanner started");
Serial.println();
}
作者已經移除這則留言。
回覆刪除請問,I2C address 改成0x3F後,背光會閃3次,但之後就不顯文字。請問這是為什麼?
回覆刪除請問,I2C address 改成0x3F後,背光會閃3次,但之後就不顯文字。請問這是為什麼?
回覆刪除0x27 改成 0x3F 後真的WORK了
回覆刪除真是神來之筆阿!!!!!!!!!!!!!!