Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding I2C Micropython code #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

paulohumberto42
Copy link

Hello! I added some code to use I2C over a ESP32 using micropython. Instead of using smbus I am using Machine.I2C

@remcoder
Copy link

remcoder commented Nov 20, 2018

Hey @paulohumberto42, I just want to chime in and say I've run your test on a Huzzah32 and it works perfectly.

I happen to have an lcd backpack based on a PCF8574A and the only thing I noticed that its address is in between 0x30 and 0x3F, so it might be helpful to add that to the comment inline.

In terms of code, I noticed that DEFAULT_I2C_ADDR was defined twice: both in the actual driver and once the test. But it is never used directly in the driver code so it can safely be removed there.

Also, to be consistent, the filenames should probably be changed to esp32_i2c_lcd*

In any case, I'd like to thank you b/c now I can happily use my esp32 with that lcd ;-)

@paulohumberto42
Copy link
Author

paulohumberto42 commented Nov 21, 2018

Hello @remcoder !
I'm glad it helped you, and thanks for the feedbacks!
I will update the code ASAP ;)

@aseelye
Copy link

aseelye commented Jul 23, 2021

Thank you, @paulohumberto42 ! FWIW this code is working in the mainline 1.16 release (esp32-20210623-v1.16.bin from micropython.org site).

One note, it looks like things have changed with how micropython calls the I2C code, and your sda/scl pins are backwards. Referncing https://docs.micropython.org/en/latest/esp32/quickref.html#hardware-i2c-bus, sda should be 19, scl is pin 18. You can initiate the bus with

i2c = machine.I2C(0, freq=100000)

or

sda = machine.Pin(19)
scl = machine.Pin(18)
i2c = machine.I2C(0, sda=sda, scl=scl, freq=100000)
lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 4, 20)

if you want to specify the pins. Obviously alternate pins would require using the secondary I2C bus, or using machine.SofI2C. Either way, thank you for your PR, it sped my day up considerably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants