LCD1602 error I2C

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Maarten_apd
Posts: 4
Joined: Tue Mar 09, 2021 2:59 pm

LCD1602 error I2C

Post by Maarten_apd » Tue Mar 09, 2021 3:03 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LCD1602 error I2C

Post by dhylands » Tue Mar 09, 2021 3:06 pm

It would be good to see the results of the scan.

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

Maarten_apd
Posts: 4
Joined: Tue Mar 09, 2021 2:59 pm

Re: LCD1602 error I2C

Post by Maarten_apd » Tue Mar 09, 2021 3:10 pm

after the change i got the same error

Maarten_apd
Posts: 4
Joined: Tue Mar 09, 2021 2:59 pm

Re: LCD1602 error I2C

Post by Maarten_apd » Tue Mar 09, 2021 3:15 pm

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

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: LCD1602 error I2C

Post by fdufnews » Tue Mar 09, 2021 5:06 pm

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.

Maarten_apd
Posts: 4
Joined: Tue Mar 09, 2021 2:59 pm

Re: LCD1602 error I2C

Post by Maarten_apd » Wed Mar 10, 2021 8:42 am

this is the lcd with controller i use
Attachments
WhatsApp Image 2021-03-10 at 09.40.12.jpeg
lcd i use
WhatsApp Image 2021-03-10 at 09.40.12.jpeg (87.57 KiB) Viewed 11128 times

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

Re: LCD1602 error I2C

Post by fdufnews » Wed Mar 10, 2021 9:37 am

Default address on similar I2C adapter (using a PCF8574) is 0x27 (39 decimal) which is compliant with the address the scanner returned.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: LCD1602 error I2C

Post by dhylands » Wed Mar 10, 2021 11:16 pm

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.

federico
Posts: 34
Joined: Tue Feb 07, 2017 11:34 pm

Re: LCD1602 error I2C

Post by federico » Fri Jul 01, 2022 4:57 am

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)

Attachments
ver_1_19_OSError_no_5_EIO.png
ver_1_19_OSError_no_5_EIO.png (208.87 KiB) Viewed 9196 times
ver_1_18_OK.png
ver_1_18_OK.png (184.31 KiB) Viewed 9196 times

federico
Posts: 34
Joined: Tue Feb 07, 2017 11:34 pm

Re: LCD1602 error I2C

Post by federico » Sun Jul 03, 2022 6:55 am

A retest with another RPi Pico with micropython release 1.19 installed was successful - which rules out problems with the new micropython release

Post Reply