Building the firmware broke I2C

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
Lornioiz
Posts: 36
Joined: Wed Aug 03, 2016 11:39 am
Location: Florence, Italy

Building the firmware broke I2C

Post by Lornioiz » Mon Nov 28, 2016 5:57 pm

Hello there!

I built my first Micropython firmware because I need to freeze some bytecode in order to reduce memory usage.
I don't have any problem building or flashing the firmware.
Everything seems to work fine until I try to create an I2C object. This is the error I got:

Code: Select all

>>> a = machine.I2C(machine.Pin(5), machine.Pin(4))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid I2C peripheral
I got this error no matter if I add some custom modules or not. Tried different mcus with the same outcome.
I tried multiple times to erased the local folder were I have the micropython repository and cloned the repository from scratch (git clone https://github.com/micropython/micropython ; git submodule update --init; make axtls; make -C mpy-cross).
However, I can't make I2C work with the firmware that I compiled. With the precompiled firmware everything is working fine.

This is the version of the esp sdk (as read in the readme.txt):
ESP8266_NONOS_SDK_V2.0.0_16_07_19

Can someone give me an hint why I2C is not working while the rest seems to be working fine?

Thank you!
Last edited by Lornioiz on Wed Nov 30, 2016 11:21 am, edited 1 time in total.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Building the firmware broke I2C

Post by deshipu » Mon Nov 28, 2016 6:29 pm

The function's signature changed. You need to provide the id of the peripheral as the first argument now. Check the documentation for details.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Building the firmware broke I2C

Post by deshipu » Mon Nov 28, 2016 6:36 pm

Oh, sorry, seems like the docs are not updated. Too bad.

jamesb
Posts: 13
Joined: Tue Nov 29, 2016 3:31 am

Re: Building the firmware broke I2C

Post by jamesb » Tue Nov 29, 2016 3:34 am

[quote="deshipu"]Oh, sorry, seems like the docs are not updated. Too bad.[/quote]

Hi @deshipu,

Could you provide an example of using the new signature?

I'm using the

i2c.init(scl=Pin(5), sda=Pin(4), freq=100000)

i2c.scan() is finding my device (TMP112 on address 72), but I don't seem to be able to read/write sensible values to config or measurement registers. This is on a ESP12 device.

Thanks,
James

Lornioiz
Posts: 36
Joined: Wed Aug 03, 2016 11:39 am
Location: Florence, Italy

Re: Building the firmware broke I2C

Post by Lornioiz » Tue Nov 29, 2016 8:17 am

deshipu wrote:Oh, sorry, seems like the docs are not updated. Too bad.
Thank you very much Deshipu!! I wasn't going anywhere by myself.
Would you be so kind to give me an example while I'm waiting the updated documentation? I'm stuck unless I'm able to make I2C work again.

Thanks!

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Building the firmware broke I2C

Post by deshipu » Tue Nov 29, 2016 9:02 pm

You can always check-out non-broken code from before the change was made, and compile that (or even check out one of the tags for stable releases).

I don't really have time to figure out what they broke (since there is now a 6-month embargo on contributions, I moved on to other projects), but from the suddenly interrupted discussions about refactoring that part, I remember it should be something like:

Code: Select all

from machine import I2C, Pin
i2c = I2C(-1, Pin(5), Pin(4))
I hope that helps.

Lornioiz
Posts: 36
Joined: Wed Aug 03, 2016 11:39 am
Location: Florence, Italy

Re: Building the firmware broke I2C

Post by Lornioiz » Wed Nov 30, 2016 11:20 am

deshipu wrote:You can always check-out non-broken code from before the change was made, and compile that (or even check out one of the tags for stable releases).

I don't really have time to figure out what they broke (since there is now a 6-month embargo on contributions, I moved on to other projects), but from the suddenly interrupted discussions about refactoring that part, I remember it should be something like:

Code: Select all

from machine import I2C, Pin
i2c = I2C(-1, Pin(5), Pin(4))
I hope that helps.
Very helpfull, thank you very much!
I must admit that I have never used github and I missed the repository of old releases. Now I where to look!
Thanks again!

trento
Posts: 1
Joined: Sat Feb 11, 2017 1:30 pm

Re: Building the firmware broke I2C

Post by trento » Sat Feb 11, 2017 1:35 pm

Hi all!
@deshipu: where is your reference? Where can I look to be "indipendent"?

I've tried your code with Pin(0)=SCL and Pin(1)=SDA but the REPL hangs on FW: esp8266-20170108-v1.8.7 and AI-THINKER Node-MCU board.
What could it be?

Thanks
Trento

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Building the firmware broke I2C

Post by deshipu » Sat Feb 11, 2017 6:14 pm

trento wrote: @deshipu: where is your reference? Where can I look to be "indipendent"?
The source code?
trento wrote: I've tried your code with Pin(0)=SCL and Pin(1)=SDA but the REPL hangs on FW: esp8266-20170108-v1.8.7 and AI-THINKER Node-MCU board.
What could it be?
Pin(1) is one of the serial pins, so it probably interferes with your REPL.

Post Reply