Nodemcu-firmware: Using am2320 on existing I²C bus

Created on 8 Mar 2017  ·  5Comments  ·  Source: nodemcu/nodemcu-firmware

Missing feature

Work with asm2320 on already initialized I²C bus with another slave devices.

Justification

I want to connect asm2320 and I²C display over one bus

Workarounds

Just comment i2c setup in asm2320.c

Most helpful comment

I also agree, but keep in mind that to keep consistency, all other i2c slaves (ADXL345, BME280, etc.) also need similar modifications.

All 5 comments

Agreed, the inherent i2c setup potentially conflicts with multiple slaves on the bus.

I also agree, but keep in mind that to keep consistency, all other i2c slaves (ADXL345, BME280, etc.) also need similar modifications.

I think, we need to split setup function into two: new begin, that initializes sensor on exiting bus and old setup, that setups new I²C bus and just runs begin (only for compatibility).

As @FrankX0 pointed out, a grep for platform_i2c_setup lists the following modules. IMO all of them need the same change to remove global I2C bus initialization:

  • adxl345.c, adxl345.init()
  • am2320.c, am2320.init()
  • bme280.c, bme280.init()
  • bmp085.c, bmp085.init()
  • hmc5883l.c, hmc5883l.init()
  • l3g4200d.c, l3g4200d.init()

Picking up @v1993's proposal, I see a two-step approach.

  1. Refactor xyz.init() into I2C bus setup and xyz.setup() for the bare module hardware. Has the same overall behavior as before, but emits a deprecation warning via #1538.
    Users should switch to xyz.setup() but can keep their scripts untouched for the time being.
  2. Remove xyz.init() after next drop.
    xyz.setup() is the only initialization / setup function remaining.

Is this the right way to go?

Sounds good to me!
Let's not forget to modify the new Hdc1080 module from initial implementation.

Was this page helpful?
0 / 5 - 0 ratings