Troubleshooting

Error with current sensor error

userHead Asier.Iglesias 2023-07-17 21:38:23 226 Views11 Replies

I have the following code, where I have 2 equal sensors and a multiplexer, the thing is that each sensor independently together with the multiplexer work correctly. But when I put the 2 sensors at the same time 1 stops working (always the first one). I do not understand why, the sensors have different I2C addresses.

 

 

 

#include <Wire.h>

#include <DFRobot_I2C_Multiplexer.h>

#include <DFRobot_INA219.h>


 

DFRobot_I2C_Multiplexer I2CMultiplexer(&Wire, 0x70);

DFRobot_INA219_IIC sensb(&Wire, INA219_I2C_ADDRESS4);  

DFRobot_INA219_IIC sensc(&Wire, INA219_I2C_ADDRESS3);

float ina219Reading_mA = 1000;

float extMeterReading_mA = 1000;

void setup() {

  Serial.begin(9600);


 

  I2CMultiplexer.begin();

    sensb.begin();

  sensc.begin();

  delay(1000);

  Serial.println("Scan ready!");

    sensc.linearCalibrate(ina219Reading_mA, extMeterReading_mA);

    sensb.linearCalibrate(ina219Reading_mA, extMeterReading_mA);


 

  for (uint8_t port = 0; port < 8; port++) {

    I2CMultiplexer.selectPort(port);

    Serial.print("Port: ");

    Serial.print(port);

    uint8_t *dev = I2CMultiplexer.scan(port);

    while (*dev) {

      Serial.print("  I2C addr ");

      Serial.print(*dev);

      dev++;

    }

    Serial.println();

  }

}


 

void loop() {

  I2CMultiplexer.selectPort(1);


 

   Serial.print("Corriente (B):   ");

  Serial.print(sensb.getCurrent_mA(), 1);

  Serial.println("mA");

  Serial.println("");

  delay(1000);

  I2CMultiplexer.selectPort(0);

  Serial.print("Corriente (C):   ");

  Serial.print(sensc.getCurrent_mA(), 1);

  Serial.println("mA");

 

  Serial.println("");

  delay(3000);

}


 

2023-07-18 14:08:12

Hi!

 

pls refer to this example.

 

DFRobot_I2C_Multiplexer/examples/multiSsd1306/multiSsd1306.ino at main · DFRobot/DFRobot_I2C_Multiplexer (github.com)

 

  * @param port - Select channel, range: 0 - 8  * @n 0-7 for enabling the corresponding channel separately, 8 for disabling all channels   * @note When“multiple multiplexer modules” are used on one I2C bus to connect “sensors with same I2C address”, to avoid conflicts,    * @n it is necessary to ensure that “the currently used channel” is the only enabled one among “all channels in all multiplexers”   * @n For instance, when one of the channels in the first multiplexer is enabled, in order to use any channel in the second multiplexer,    * @n please make sure that the channels in the first multiplexer are all disabled.

userHeadPic jenna
Asier.Iglesias wrote:

Hey, I have seen your message, in my case I have a single multiplexer and 3 sensors (Wattmeter) with 3 different I2C addresses (x45, x44 and x41). Separately they work without problem, the thing is that when I put the 3 together they go crazy, the voltage gives me well but the current does not. The wiring and the equipment I want to measure is correct, the problem is in my code but I do not see the error.  What can I do?I also tried the advice you gave me to select port 8 before switching to another port.

2023-07-18 20:08:48
Asier.Iglesias wrote:

Here is an image of what I get in the terminal. The voltage is correct but the current is not.Sorry for the inconvenience 

2023-07-18 20:12:53
jenna wrote:

Hi!

 

1. Maybe you can try not adding the I2C multiplexer and set the addresses of the three sensors to 40,41and 44. Then connect the sensor directly to the board.

code:

https://drive.google.com/file/d/10XDd_mp6kUwi_7d8uu5U2Ik_kMOb4CFH/view?usp=drive_link

 

 

2.pls try this code.

 

https://drive.google.com/file/d/1ORFV4IaS7v8Unpndc3u6UfududXAd_LZ/view?usp=sharing

2023-07-19 11:24:04
Asier.Iglesias wrote:

with a portoboard if the 3 sensors work at the same time, then the failure is the multiplexer thank you very much, I hope they put an update or something to the library for q go headache that has given me hahaha. Thank you very much.

2023-07-19 18:46:46
jenna wrote:

Hi!

The second code uses three sensors and a multiplexer, I recommend you try both. Looking forward to your feedback. If it's still not resolved, I'll try it.

 

 

2023-07-20 09:34:09
Asier.Iglesias wrote:

Hi again Jenna, I really don't know what I would do without your help hahaha. It seems that my fault is that in the void Setup I only initialized one port. Thanks to your code I have been able to see that it is necessary to do it with each and every one of them. Thank you very much for the help, now I can measure everything correctly, now I just have to calibrate and that's it :) thank you

2023-07-20 19:21:08
6 Replies
2023-07-17 22:55:06

Some other people faced the same issue with multiple INA219 current sensors. Some found solutions too. I am posting some links that may help you:

 

https://github.com/easybotics/node-red-contrib-easybotics-ina219/issues/13

 

https://www.pcbway.com/project/shareproject/RaspberryPI_Power_Monitor_HAT_130c366a.html

userHeadPic bidrohini.bidrohini
Asier.Iglesias wrote:

Hey, thanks for the link, I have been reading and something similar happens to me, since the sensors (with different addresses x45, x44 and x41) separately work fine. But when I put them all in the multiplexer they go crazy. I don't see what I'm doing wrong. Here I leave an example of the answers, (the voltage reads well but the current does not).

2023-07-18 20:11:49
Asier.Iglesias wrote:

with a portoboard if the 3 sensors work at the same time, then the failure is the multiplexer thank you very much, I hope they put an update or something to the library for q go headache that has given me hahaha. Thank you very much.

2023-07-19 18:46:18
bidrohini.bidrohini wrote:

I think DG408 solves the same purpose. But could not find an Arduino library for this: 

 

https://www.theengineeringprojects.com/2018/04/introduction-to-dg408dy.html

2023-07-20 01:44:13
3 Replies