前回の記事 でRaspberry Piで16×2 LCDを作動するの方法を紹介しました、設定は簡単ですが、たくさんのジャンプワイヤが必要し、たくさんのGPIOポートも占有しまいました。
GPIOポートを節約のため、今回はI2Cを通じで、唯4本のワイヤーを使用し、 LCDを制御します。
Raspbian OSを装着済みのMicroSDカードが必要です。
Step 1: 回路図(画像をクリックして拡大イメージを表示):
PiI2C Pin
|
Step 2:using raspi-config utilityでi2cを有効にする
Terminalで下記のコマンドを入力してくださいませ:
Advance Optionsに入って、「-> I2C -> Enable I2C ->Finish」
デバイスは自動的にrebootします。
Piが再起動したら、config fileを編集必要です。Terminalで下記のコマンドを入力してくださいませ:
sudo nano /etc/modules
モジュールファイルで下記の内容を追加して下さい:
i2c-bcm2708
i2c-dev
Ctrl+Xボダンを押して、Yを入力して、ファイルを保存して下さい。
Step 3: smbusとi2c python libraryのインストールする
Terminalで下記のコマンドを入力してくださいませ
sudo apt-get update
sudo apt-get install -y python-smbus i2c-tools
sudo reboot
Piが再起動したら、Terminalで下記のコマンドを入力して下さい:
lsmod | grep i2c_
i2c_bcm2708がリストに表示されるはずです。libraryが正しくインストールしたと分かります。もし、i2c_bcm2708が見えない場合、Step2と3を再度操作して下さい。
Step 4:ハードウェアのテスト
Terminalで下記のコマンドを入力して下さい:
sudo i2cdetect -y 1
or
sudo i2cdetect -y 0
下記のように、表示します:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — — — — — — — — — — — — — —
30: — — — — — — — — — — — — — — — 27
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — —
数字なく、唯”– — –“と表示の場合、 回路の組み立ては問題あるあるいはソフトウエアのインストールが正しくないと判明できます。
Step 5: Python Codeをダウンロードして、 projectを開始する:
Terminalで下記のコマンドを入力して下さい:
wget http://osoyoo.com/driver/i2clcda.py
sudo python i2clcda.py
errorがありましたら、下記のコマンドを試して下さい:
wget http://osoyoo.com/driver/i2clcdb.py
sudo python i2clcdb.py
問題無ければ、LCDは下記の文字を表示します:
Created by
Osoyoo.com
> Tutorial Url:
> https://osoyoo.com
Raspberry Piで何のerrorもないても、LCDで何も表示しないの場合、LCD裏のつまみを調整して、見て下さい~
DownLoad Url osoyoo.com
You must be logged in to post a comment.
Why does my i2clcda.py or i2clcdb.py cause an error in line 109 and line 57 ERRno 5 input/output error?
I test the LCD according to the tutorial, and it works without error.
Do you add following two lines in modules file if they do not exist at step 2:
i2c-bcm2708
i2c-dev
Do you see “– — –” sign in the list with any numbers?
Pls confirm.
I am receiving the same errors as tarmbrester (line 57 and 109: Error no 5). The config file has: i2c-bcm2708 and i2c-dev. I also did get the matrix of”00: —” with number for the “sudo i2cdetect – y 1”.
The black integrated circuit (next to the potentiometer)is hot to the touch. Does your chip in your setup get very hot?
pls confirm the VCC and GND connect correct
I doubled checked the wiring before I turned it on the first time. Pin 2 (+5V) and pin 39 (gnd).
Do you have other LCD to test?
I afraid not. If “tarmbrester” (the original commenter) has solved his/her problem then I must have a bad board.
Does your LCD has backlight when you connect with the board?
If not, pls confirm whether there is a jumper cap at the I2C driver board.
Partial Solution:
I made a wiring mistake. I had the header numbering wrong, VCC and GND reversed. On raspberry PI 3 with the usb pointing down the top left pin is number 2.
When I run the program it runs but nothing appears. Adjusting the contrast quickly show some blocks but they then fade. When I disconnect one of the data lines the program errors out as expected. Any ideas? Is it possible there is damage from the voltage reversal?
The short circuit may defect the LCD.
Hi,
I followed the process, at step 4 the result is very similar to what you have described, I also noticed that the backlight flashes when I run the command, which I presume the detection is successful.
Step 5
Downloaded both python codes but when I try to run I get the following:
Traceback (most recent call last):
file “i2clcda.py”, line 57, in lcd_byte
bus.write_byte(I2C_ADDR, bits_high)
IOError: [Errno 5] Input/output error
Same happens both files ending with a and b. Seems both have LCD address incorrectly for my device.
Is there a utility you can provide so that I can fidn out the LCD module address? It will be very useful.
Thanks
I managed to find out LCD module address using a small script with Arduino UNO. All good now.
I am getting the following error when running the python code.
Traceback (most recent call last):
File “i2clcdb.py”, line 109, in
lcd_byte(0x01, LCD_CMD)
File “i2clcdb.py”, line 57, in lcd_byte
bus.write_byte(I2C_ADDR, bits_high)
IOError: [Errno 5] Input/output error
Nevermind, I changed the address and it works now.
Does script have function to turn off the backlight?
Hello,
I’m new here.
I use your example to show different temperatures for a pool control unit with node red an Raspberry PI.
I changed the main program as follow:
def main():
# Main program block
# Initialise display
lcd_init()
while True:
T1 = “10°C”
T2 = “20°C”
T3 = “30°C”
T4 = “40°C”
# Send some test
lcd_string(“Pooltemperatur:”,LCD_LINE_1)
lcd_string(T1,LCD_LINE_2)
time.sleep(10)
lcd_string(“Ruecklauf Pool:”, LCD_LINE_1)
lcd_string(T2,LCD_LINE_2)
time.sleep(10)
lcd_string(“Solarabsorber :”,LCD_LINE_1)
lcd_string(T3,LCD_LINE_2)
time.sleep(10)
lcd_string(“Aussen :”,LCD_LINE_1)
lcd_string(T4,LCD_LINE_2)
time.sleep(10)
if __name__ == ‘__main__’:
try:
main()
except KeyboardInterrupt:
pass
finally:
lcd_byte(0x01, LCD_CMD)
Now I’m wondering how I could show variables Temeratures (T1,T2,T3,T4) on the display.
The red node T1 = parseFloat(global.get(‘T1’)) doesn’t work.
I would be happy, if someone have an idea, how can I solve the problem.
Best regards from Germany.