Page 1 of 2

LCD1602 error I2C

Posted: Tue Mar 09, 2021 3:03 pm
by Maarten_apd
when i try to use my code to get started with using a lcd screen with my pico i get a error code

Code: Select all

import machine
sda=machine.Pin(0)
scl=machine.Pin(1)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
i2c.writeto(114, '\x7C')
i2c.writeto(114, '\x2D')
print(I2C.scan())

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
OSError: 5

Re: LCD1602 error I2C

Posted: Tue Mar 09, 2021 3:06 pm
by dhylands
It would be good to see the results of the scan.

You need to use i2c.scan() and not I2C.scan()

Re: LCD1602 error I2C

Posted: Tue Mar 09, 2021 3:10 pm
by Maarten_apd
after the change i got the same error

Re: LCD1602 error I2C

Posted: Tue Mar 09, 2021 3:15 pm
by Maarten_apd

Code: Select all

import machine
sda=machine.Pin(0)
scl=machine.Pin(1)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
print(i2c.scan())

Code: Select all

[39]
the scan worked with this code with the other one it din't work

Re: LCD1602 error I2C

Posted: Tue Mar 09, 2021 5:06 pm
by fdufnews
In the first program, you try to write at address 114. If you have no I2C slave at that address you have no acknowledge and the write probably crashes.

In the second program the scan tells you that you have a slave at address 39 which maybe is an I2C expander.

Re: LCD1602 error I2C

Posted: Wed Mar 10, 2021 8:42 am
by Maarten_apd
this is the lcd with controller i use

Re: LCD1602 error I2C

Posted: Wed Mar 10, 2021 9:37 am
by fdufnews
Default address on similar I2C adapter (using a PCF8574) is 0x27 (39 decimal) which is compliant with the address the scanner returned.

Re: LCD1602 error I2C

Posted: Wed Mar 10, 2021 11:16 pm
by dhylands
I have a driver already written for that board (or at least a board very similar to that), and I've tested it with the RPi Pico.

I had to power the LCD using 5v, so I used a 3.3v to 5v voltage converter for the SDA and SCL lines. The Pico doesn't have 5V tolerant pins.

See this post: viewtopic.php?f=12&t=9633&p=55356#p55356

You'll also need the lcd_api.py file: https://github.com/dhylands/python_lcd/ ... lcd_api.py (in addition to the 2 files mentioned in the post, although the test file is optional.

Re: LCD1602 error I2C

Posted: Fri Jul 01, 2022 4:57 am
by federico

Code: Select all

# Raspberry Pi Pico
# to test the with micropython 1.19
# OSError: [Errno 5]- EIO
# esp8266_i2c_lcd.py, line 55  in __init__

# the following is the code in line 55:
# self.i2c.writeto(self.i2c_addr, bytearray([0]))

# that set to OFF the LCD backlight

# !! with releases ver. <= 1.18 no problems

from machine import I2C, Pin

scl_pin=11
sda_pin=10
i2c_ID=1

i2c = I2C(i2c_ID, sda=Pin(sda_pin), scl=Pin(scl_pin))
i2c.scan()

if i2c.scan().count(39)  == 0:
    print("No i2c display found !")
else:
    from esp8266_i2c_lcd import I2cLcd, DEFAULT_I2C_ADDR
    lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 4, 20)


Re: LCD1602 error I2C

Posted: Sun Jul 03, 2022 6:55 am
by federico
A retest with another RPi Pico with micropython release 1.19 installed was successful - which rules out problems with the new micropython release