frame

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.i2c.start()
self.addr = i2c_addr
self._write(bytearray([0]))
self._write then does this (cmd is a bytearray):
try:
  self.i2c.lock()
  self.i2c.set_addr(self.addr)
  self.i2c.write_bytes(self.addr, cmd[0])
except Exception as e:
   print(e)
finally:
  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])
self.i2c.write(cmd)
etc
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):
write_bytes(*argstimeout=-1)
args is converted to bytes and sent.
write(datatimeout=-1)
data is written.
How is args converted?
What is data? (string? bytearray?)

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

Comments

  • 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 :)




    Matteo Cipriani
    Zerynth Support Team
  • @"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 :)

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

    Thanks again
     - Ryan.
  • Matteo,

    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

    -Jaron
  • Matteo,

    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\nodemcu_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!

    -Jaron
  • 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  ;) 
    Matteo Cipriani
    Zerynth Support Team
Sign In or Register to comment.

ZERYNTH Community

@ 2016 Zerynth.com, all rights reserved.