HD44780 character LCD connected via PCF8574 on I2C


I’m trying to implement an interface to my 16x2 LCD (HD44780 character LCD connected via PCF8574 on I2C).  In both standard Python and MicoPython, I’ve used the lcd_api.py (Found here: https://github.com/dhylands/python_lcd/blob/master/lcd/lcd_api.py) as the base class and implemented my own HAL on top of that (see that git for examples).  This is all being done on a ESP32 dev board (LOLIN32).

In the init, I start with the following to initialize I2C:

self.i2c = i2c.I2C(I2C0, i2c_addr, clock=100000)
self.addr = i2c_addr
</div>self._write then does this (cmd is a bytearray):<br><pre class="CodeBlock">try:<br>&nbsp; self.i2c.lock()<br>&nbsp; self.i2c.set_addr(self.addr)<br>&nbsp; self.i2c.write_bytes(self.addr, cmd[0])<br>except Exception as e:<br>&nbsp; &nbsp;print(e)<br>finally:<br>&nbsp; self.i2c.unlock()
The problem is that whenever I try to run this, I get a very useless InvalidHardwareStatusError thrown (useless in that there is nothing in the documentation to tell me what it even means!).  I've tried various combinations on how to write commands to the LCD:
self.i2c.write_bytes(0x00, cmd[0])
self.i2c.write_bytes(0x20, cmd[0])
No luck.

Just for my own sanity, I did load my Micropython build on and was able to verify that I had the correct I2C address and the hardware all worked as expected so it appears to be something I'm doing wrong in Zerynth.

To add to the confusion, the documentation could use some extra details.  For example (https://docs.zerynth.com/latest/official/core.zerynth.stdlib/docs/official_core.zerynth.stdlib_i2c.html):
args is converted to bytes and sent.`
data is written. ```
How is args converted?
What is data? (string? bytearray?)

Some I2C examples and troubleshooting guidelines would be greatly appreciated!  Thanks!


Hi Jaron,

thanks for joining our community; regarding your issue I need some other info to better understand the problem.
Which device are you using??Which device name you have in the Zerynth Studio Device Manager Toolbar??

LOLIN32, if I am not wrong, is an ESP32 dev board produced by Wemos that is not already supported in Zerynth (here you can find the list of Zerynth Supported Devices and related documentation); LOLIN32 will be available very soon in one of our future releases!!!

By the way, by clicking the InvalidHardwareStatusError a more verbose message should appear in the Zerynth Studio console; can you post me the error message??

The write_bytes() method takes as argument the bytes (ex: write_bytes(0x01,0x02,0x03,…)) you want to transmit that are converted in a bytearray and are sent on the I2C bus; the write() method take as argument a bytearray including the list of bytes you want to transmit.

Here you can find some advice to implement your own I2C library in Zerynth.
Remember to check in the Zerynth Pinmap where the SDA and SCL pin are mapped and connect to them the SDA and SCL pin of your sensor.

Keep me posted :slight_smile:


@“Matteo Cipriani” 
Thanks for the prompt response.  Jaron and I were working together on this.  I don’t get any additional info on the console when I click the 
InvalidHardwareStatusError other than details about exactly which line failed (which was .write_bytes.    However,calling it as you suggested works – that is we don’t get a hardware failure :slight_smile:

From the Z-info box:
Name: ESP32 DevKitC
Model: Expressif esp32.

Thanks again
 - Ryan.



I’m sorry for not responding sooner!  I was waiting for an email notification but apparently didn’t have notifications enabled properly!

The exception appears to be originating in line 118 of your i2c.write() method (main and lcd.* are mine):

InvalidHardwareStatusError  at line 26 of main
raised at line 21 of lcd.init
raised at line 48 of lcd._write
raised at line 118 of i2c.write




I actually just got it working!  Your response reminded me that the LOLIN32 is not “officially” supported so I wondered if the pins for I2C were off.  I found your port def file (zerynth2\dist\r2.0.10\devices
odemcu_esp32\port\port.def) and confirmed that the none of your built-in I2C classes (I2C0-2) used the pins marked on the hardware.  After recovering from my foolishness, I changed my hardware SDA/SLA to pins 18/19 (I2C2) and everything worked as expected.

Thanks again for your help!



Great; I’m glad to read that!!! :smiley: 

Good job and keep me posted for any other help or issue!!!
Soon will be available also the LOLIN32 device; Stay tuned