hardware i2c deprecated

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jbar
Posts: 11
Joined: Mon Nov 15, 2021 1:07 pm
Location: Nebraska USA
Contact:

Re: hardware i2c deprecated

Post by jbar » Mon Jan 03, 2022 2:00 am

Roberthh wrote:
Sat Jan 01, 2022 3:26 pm
You did not tell which board you use. Is it an ESP32? Or RPi Pico? And you could show the error message which you get.
The following message pops up in the shell:
Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead

I'm using an ESP32.

JDRBoston
Posts: 21
Joined: Mon Feb 19, 2018 9:43 pm

Re: hardware i2c deprecated

Post by JDRBoston » Thu Sep 08, 2022 3:35 pm

Thank you for this update about how i2c can be instantiated in the newer MicroPython versions. Is there a way to turn off the "Warning: I2C(-1,...)..." message that is sent to shell? I am using the hardware I2C pins of my device and the machine.I2C() instantiation accordingly. I don't want the user to see the "Warning" when it does not apply and worry. Alternatively, is there a down side to using machine.SoftI2C() with the hardware I2C pins declared. I'm likely wrong, but would this then cause bit banging the port and cause some speed and other software overhead when it isn't needed. Or, does SoftI2C() default to using the hardware I2C resources when the hardware I2C pins are defined. Thank you, J

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: hardware i2c deprecated

Post by jimmo » Thu Sep 08, 2022 3:44 pm

JDRBoston wrote:
Thu Sep 08, 2022 3:35 pm
Thank you for this update about how i2c can be instantiated in the newer MicroPython versions. Is there a way to turn off the "Warning: I2C(-1,...)..." message that is sent to shell? I am using the hardware I2C pins of my device and the machine.I2C() instantiation accordingly. I don't want the user to see the "Warning" when it does not apply and worry. Alternatively, is there a down side to using machine.SoftI2C() with the hardware I2C pins declared. I'm likely wrong, but would this then cause bit banging the port and cause some speed and other software overhead when it isn't needed. Or, does SoftI2C() default to using the hardware I2C resources when the hardware I2C pins are defined. Thank you, J
If you were previously using

Code: Select all

machine.I2C(-1, sda=..., scl=...)
then you were never using hardware I2C, it was always software (bit banged).

The deprecation warning is to encourage you to make it explicit (i.e. use SoftI2C).

On ESP32 pins can be anything, there's no "hardware i2c pins" because any pin can be mapped to a given i2c peripheral.

If you want to use the hardware I2C, you must specify a bus ID (0 or 1) and the pins.

JDRBoston
Posts: 21
Joined: Mon Feb 19, 2018 9:43 pm

Re: hardware i2c deprecated

Post by JDRBoston » Thu Sep 08, 2022 3:59 pm

Thank you, jimmo!

Post Reply