Multiple devices I2C bus?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
olleman
Normal user
Posts: 39
Joined: 27 Aug 2017, 08:10

Multiple devices I2C bus?

#1 Post by olleman » 11 Feb 2018, 10:59

As I understand it the I2C bus supports up to 121 devices connected to it. I would need 2 or maybe 3 is this supported by ESP Easy?

I'd like to use one INA219 sensor and BME280 and perhaps something more in the future.

,Olle

User avatar
grovkillen
Core team member
Posts: 3200
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Multiple devices I2C bus?

#2 Post by grovkillen » 11 Feb 2018, 11:00

Should be little to no problem.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Multiple devices I2C bus?

#3 Post by toffel969 » 11 Feb 2018, 12:03

olleman wrote:
11 Feb 2018, 10:59
As I understand it the I2C bus supports up to 121 devices connected to it. I would need 2 or maybe 3 is this supported by ESP Easy?

I'd like to use one INA219 sensor and BME280 and perhaps something more in the future.

,Olle
As long as the devices have different adresses and the overall capacitance is not to high, shouldnt be a problem. I can confirm 4 Devices working on I2C
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

olleman
Normal user
Posts: 39
Joined: 27 Aug 2017, 08:10

Re: Multiple devices I2C bus?

#4 Post by olleman » 11 Feb 2018, 12:59

awesome, thanks!

Shardan
Normal user
Posts: 1112
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: Multiple devices I2C bus?

#5 Post by Shardan » 11 Feb 2018, 13:26

In the ESPEasy Wiki you will find a detailes explanation how I²C works and how to connect components.

Take a look:
https://www.letscontrolit.com/wiki/inde ... he_I²C_Bus
Regards
Shardan

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#6 Post by TD-er » 11 Feb 2018, 13:56

On my testboard, I have been using 3x INA219 and one BME280 and OLED display.
Setting the address on most I2C modules will require some soldering.

olleman
Normal user
Posts: 39
Joined: 27 Aug 2017, 08:10

Re: Multiple devices I2C bus?

#7 Post by olleman » 05 Jun 2018, 21:30

hm...how did you get 3 INA devices working? I have dev12 MEGA and I seem to run into the same bug as this thread reports:
viewtopic.php?f=5&t=3479#p18796

The last configured i2c adress is used to both devices. And yes, I have soldered (bridged) A0 to get 0x41 on one of them.

Edit: Latest version (180524) solved the issue. Now I have another one :) My domoticz installation is now using 5 digit IDX values and EspEasy only allows for 4 digit values. I can't find any way to override this in domoticz, can this be solved from EspEasy instead?

User avatar
grovkillen
Core team member
Posts: 3200
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Multiple devices I2C bus?

#8 Post by grovkillen » 05 Jun 2018, 23:28

You can do it with rules, see this link: https://www.letscontrolit.com/wiki/inde ... th_own_IDX
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#9 Post by TD-er » 06 Jun 2018, 23:01

Hmm 5-digit idx values.
It is stored as an unsigned int and it doesn't look like a very limited variable in Domoticz.
Even if it is a 16-bit value, 5 digits shouldn't be a problem.
It's a simple change here in these lines:
https://github.com/letscontrolit/ESPEas ... 2171-L2174

Could you add an issue on Github about it?
Maybe someone else may have an suggestion on why it's a good idea, or more importantly, why not ;)

olleman
Normal user
Posts: 39
Joined: 27 Aug 2017, 08:10

Re: Multiple devices I2C bus?

#10 Post by olleman » 07 Jun 2018, 21:48

grovkillen wrote:
05 Jun 2018, 23:28
You can do it with rules, see this link: https://www.letscontrolit.com/wiki/inde ... th_own_IDX
Works like a charm, there's always a solution around somewhere but as TD-er mentioned, perhaps ESPEasy should allow 5 digit IDX. I have a lot since I'm picking up huge amounts of my neighbors sensors with my RFXCOM device.

I may be in the wrong thread for this quesion but I'll give it a go since it's connected to the INA219 device.

I'm going to monitor power consumption on my boat and use the ina219 with an external shunt (50A 75mV). In the beginning I will send the data to my server at home via shared internet connection on a dedicated phone and a VPN. But to get a good grasp on power consumption I need to sample the current at least every 5 seconds. Is it possible to store several measurements with the rules function and send the accumulated data each 10 minutes or so to domoticz? The goal is to keep the traffic down.

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#11 Post by TD-er » 08 Jun 2018, 00:01

@Olleman:
Nope it is not yet possible to do so.
I hope to add some support for such a feature. It could even be stored in SPIFF, since adding data is not really a problem, as long as you don't have to erase sectors (or have PUYA chips)

olleman
Normal user
Posts: 39
Joined: 27 Aug 2017, 08:10

Re: Multiple devices I2C bus?

#12 Post by olleman » 10 Jun 2018, 22:16

TD-er wrote:
08 Jun 2018, 00:01
@Olleman:
Nope it is not yet possible to do so.
I hope to add some support for such a feature. It could even be stored in SPIFF, since adding data is not really a problem, as long as you don't have to erase sectors (or have PUYA chips)
It would be a really cool feature! Are you responsible for the INA219 plugin? I'm starting to realize that a RPI Zero would be quite a good choice to have on the boat as well. All this data traffic seems a bit unnecessary and I plan on adding some more sensors as well.

Well, for now I have one wemos mini and two INA219s sending me voltages from my two batteries every minute via a mobile hotspot in the boat. Overkill but fun :)

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#13 Post by TD-er » 14 Jun 2018, 19:00

olleman wrote:
10 Jun 2018, 22:16
[...]
It would be a really cool feature! Are you responsible for the INA219 plugin? [...]
Depends on the definition used ;)
I did not write the initial plugin, I just made it possible to have more than one active at the same time.
Also, I am currently the most active developer on ESPeasy.

boatie
Normal user
Posts: 3
Joined: 08 Sep 2019, 15:24

Re: Multiple devices I2C bus?

#14 Post by boatie » 09 Sep 2019, 14:23

Hi Olleman

re the quote below

Well, for now I have one wemos mini and two INA219s sending me voltages from my two batteries every minute via a mobile hotspot in the boat. Overkill but fun :)

Im learning as a esp newbie, could you post how you run two INA219 on the one WeMos board and / or post the circuit / software as that is what I would like to do as well.

eg in espeasy you can set the SLA/SLD lines to the GPIO's in Hardware but only once ?

I'm also having some trouble getting any reliable voltage / current readings off my ebay IAN219 and suspect they are defective or my setting/ formula (im using %voltage%*300/1024 in espeasy are wrong (eg I get 9.6 volt regardless of what the voltage is of the battery I attach). Any easy test to use ?

I've managed to get my wifi to around 400m using a yagi ant out to my boat and can see/control the Wemos mini devices.

thanks in advance

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#15 Post by TD-er » 09 Sep 2019, 16:14

I2C sensors can all be used on the same SDA/SCL pins, as long as all have their own unique address on the I2C bus.
Most sensor boards have some pads available to set the address. You have to look into the datasheet of the sensor to see what addresses can be used and how to select them.

If you set the new address (other than default) it is advised to only connect that sensor and perform an I2C scan to see if it did accept the new set address and also what the address is.

Some things to keep in mind:

When using multiple I2C sensors on a bus, you may need pull-up resistors for the SDA and SCL lines. Something around 4k7 or 10k.
These must then be placed between the SDA and 3v3 line (the same for SCL and 3v3)
Use them if you experience issues with stable reading of the I2C sensors.

Do not use long cables for I2C. Try to keep them below 20 cm.

Not all plugins support multiple instances of the same plugin to be run on the same ESP node.
INA219 should be fine.

All sensors do consume power. Not all ESP boards have a proper voltage regulator on board.
When in doubt, use your own 3.3 Volt regulator and/or add capacitors.

boatie
Normal user
Posts: 3
Joined: 08 Sep 2019, 15:24

Re: Multiple devices I2C bus?

#16 Post by boatie » 11 Sep 2019, 13:18

Thanks TD-er

I was wondering what the pads on the IDA219 were and read about bridging the pads to set the address. Thanks for suggesting the pull down resistors.

I also worked out that R120 I was using is a old ESPeasy version and the main page does not really mention the new mega versions (I've downloaded it mega-20190903) and will play around as it has a whole heaps of new useful function (once you sort of what all the filenames mean / do and even a 4mb blank file to erase the whole wemos when I "forgot" what I used as the admin password to start again) :)

Any hints on why the voltage is not reading (could all three INA219 boards be duds ?) - Do I need a voltage formula at all or is that optional ? when I leave the formula blank I get a reading of 32.72 volts (on a 9 volt battery) and the reading does not update if i pull the battery off (even at 2 second intervals)

Adding a formula eg %value%*300/1024 makes no difference eh still 32.72 volts

Would you have a page pic of a working INA219 voltage settings to copy :)

Ive attached mine below
ina219 device page.JPG
ina219 device page.JPG (39.57 KiB) Viewed 111 times
ina219 config page.JPG
ina219 config page.JPG (78.87 KiB) Viewed 111 times

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#17 Post by TD-er » 11 Sep 2019, 15:36

boatie wrote:
11 Sep 2019, 13:18
Thanks for suggesting the pull down resistors.
[...]
No they should be pull-UP

32.7 Volt sounds like an overflow value. (32768)

So make sure you have the proper resistors in place to lower the range.
For this you should refer to the datasheet of the chip.

boatie
Normal user
Posts: 3
Joined: 08 Sep 2019, 15:24

Re: Multiple devices I2C bus?

#18 Post by boatie » 11 Sep 2019, 22:45

Thanks

Could you explain the overflow value a bit more ?

All the circuits I have seen do not have any resistors (at least for the V+ input) and I'm only measuring 9 or 12 volts where as the INA219 says it does up to 26 (or 32 volts depending of which specs you read) eg http://www.ti.com/lit/an/sboa194/sboa194.pdf and also https://www.letscontrolit.com/wiki/index.php/INA219

Also, I understood the voltage formula was supposed to allow you to adjust the voltage measurements (when I used R120 it did change them but not update) ?

Any suggested resistor values I should use (I saws 0.1 ohms on YouTube video) ? )

Any suggestions as to why the number does not update if I disconnect or put say 12 volts on the V+ ?

Thanks for the guidance

regards

TD-er
Core team member
Posts: 1461
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Multiple devices I2C bus?

#19 Post by TD-er » 12 Sep 2019, 00:38

Well the value of 32.7 just triggered the association with 32767 with me, which is a typical max.value for a signed 16-bit value.
A quick glance at the datasheet does show the max. value is either 4000 (x 4 mV) or 8000 (x 4mV)
So then any value over 32.0 should not occur.
Maybe it is a fault state?
Perhaps + and - swapped of the battery and set to 32V range (not allowing negative values).
The plugin only updates per set interval (default 60 sec) and most (not all) plugins only update a value if it is a valid value.

Resistor values of less than 1 Ohm are typically used as a shunt, to measure currents. (measure the voltage over that resistor)
It does not seem to be needed to add resistors for measuring voltage.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests