Gravity: I2C Digital Wattmeter (SEN0291)

This is a placeholder topic for “Gravity: I2C Digital Wattmeter” comments.

Gravity: I2C Digital Wattmeter is a high-resolution, high-precision, large-scale measurement module that can measure the voltage, current and power of various electronic…

Read more

This looks like a nifty device, and DFRobot’s product wiki suggests that there is support for it with Raspberry Pi … except that their instructions are wrong … and there is no response to product queries on their forum.

The points I was going to make were raised over 2 years ago in Gravity: I2C Digital Wattmeter- DFRobot Forum, and received no response. I have also got their demo working, but not in my own program.

Is there any support for this product with Raspberry Pi ? Is this typical of DFRobot ?

I realise that my current problem is that I am not familiar with how python libraries work. So far I’ve been able to follow instructions to install libraries and use them. Just one more learning curve :wink:

Hi @Donald23173,

Can definitely look into issues with getting it working on Pi.

Could you let us know what part of their instructions have been causing issues?

There are a number of errors in DFRobot’s wiki page (not my current problem, because I have determined the correct values). I found that going down the 5 levels of directory structure to the example program’s folder and running the example program worked as indicated.

But in my project folder the same program gives error “ImportError: cannot import name ‘INA219’ from ‘DFRobot_INA219’ (unknown location)”. It would seem that the library has not been installed somewhere it is accessible.

OK, I worked it out. I found the file DFRobot_INA219.py somewhere in the files from github, and moved it to my application folder. Working now.


On Core’s product page https://core-electronics.com.au/gravity-i2c-digital-wattmeter.html under Documents / Product Wiki there is a link to DFRobot’s website.

This DFRobot page contains (what I assume are) accurate and complete instructions for Auduino … and erroneous instructions for Raspberry Pi.

Under Requirements / Software is “Download and install the DFRobot_INA219 RaspberryPi library” which links to a different product DFRobot_AS3935.

The “Installation” section points to the correct Github repository https://github.com/DFRobot/DFRobot_INA219.git, but under " Run Sample Code" the folder path which the code was installed into is badly mixed up - it is actually DFRobot_INA219/Python/RespberryPi/examples/get_voltage_current_power. And finally the given program name is wrong, with the actual program name following the all lower case with underscores naming convention.

All-in-all I am left with the impression that the documentation was dashed off quickly from memory only, and with no quality control.

Hi Donald,

Glad to hear that you have it figured out. It’s likely that the library has been revised without the product’s wiki being updated. Having a typo in the directory name go unchanged for a couple years is a bit of a blunder but fortunately, there is enough available to get you the info that you need to get ti working.

Hopefully from here your project goes a bit smoother.

TL;DR … I think my battery is borked ?

Back to this sub-project now that I (finally) have DFRobot Solar Power Manager 5V, Solar panel and Li-PO battery (not to scale) and assembled it with a Adafruit MAX17043 and two DFRobot Digital Wattmeters (INA219) … like so:

The voltage meter is showing almost exactly the same voltage as the MAX17043 :heavy_check_mark:

The solar panel doesn’t seem to be generating any noticable current :x:, so I have also connected a USB phone charger via a INA219 - and the amount reported on that is also suspiciously low :x:.

Connecting the INA219-45 with USB power to my Raspberry Pi and using the DFRobot code mentioned above in November, I get:

(env) pi@raspberrypi:~/python $ python greenhouse3.py
INA219-45:   Shunt Voltage=38.0mV,  Bus Voltage=4.945V,  Current=41.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=36.0mV,  Bus Voltage=4.953V,  Current=35.0mA,  Power=160.0mW 

INA219-45:   Shunt Voltage=41.0mV,  Bus Voltage=4.949V,  Current=37.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=36.0mV,  Bus Voltage=4.949V,  Current=37.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=38.0mV,  Bus Voltage=4.949V,  Current=40.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=38.0mV,  Bus Voltage=4.957V,  Current=37.0mA,  Power=160.0mW 

INA219-45:   Shunt Voltage=37.0mV,  Bus Voltage=4.953V,  Current=38.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=37.0mV,  Bus Voltage=4.949V,  Current=34.0mA,  Power=160.0mW 

INA219-45:   Shunt Voltage=37.0mV,  Bus Voltage=4.909V,  Current=39.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=36.0mV,  Bus Voltage=4.949V,  Current=37.0mA,  Power=200.0mW 

INA219-45:   Shunt Voltage=36.0mV,  Bus Voltage=4.953V,  Current=37.0mA,  Power=200.0mW 

The Bus Voltage seems right, but only 35-40 mA of current ?

Back to all 3 power monitors connected to a ESP32 via i2c, and all devices are installed in ESPHome and appear to be returning data to Home Assistant - except that data except voltage is recorded as 0.0.

Maybe it’s because Home Assistant is showing the reading in Amps but the values are too small to register ? Going to the ESPHome log from the ESP32

[19:19:43][D][pulse_counter:181]: 'rain gauge': Retrieved counter: 0.00 pulses/min
[19:19:43][D][sensor:094]: 'rain gauge': Sending state 0.00000 pulses/min with 2 decimals of accuracy
[19:19:44][D][dht:048]: Got Temperature=27.9°C Humidity=64.0%
[19:19:44][D][sensor:094]: 'DHT22 Temperature': Sending state 27.90000 °C with 1 decimals of accuracy
[19:19:44][D][sensor:094]: 'DHT22 Humidity': Sending state 64.00000 % with 0 decimals of accuracy
[19:20:12][D][sensor:094]: 'greenhouse Wifi signal': Sending state -54.00000 dBm with 0 decimals of accuracy
[19:20:19][D][sensor:094]: 'Solar Bus Voltage': Sending state 4.85600 V with 2 decimals of accuracy
[19:20:19][D][sensor:094]: 'Solar Shunt Voltage': Sending state 0.00012 V with 2 decimals of accuracy
[19:20:19][D][sensor:094]: 'Solar Current': Sending state 0.00118 A with 3 decimals of accuracy
[19:20:19][D][sensor:094]: 'Solar Power': Sending state 0.00588 W with 2 decimals of accuracy
[19:20:21][D][text_sensor:064]: 'greenhouse Uptime Human Readable': Sending state '3m 34s'
[19:20:21][D][sensor:094]: 'greenhouse Uptime': Sending state 214.25101 s with 0 decimals of accuracy
[19:20:21][D][bh1750.sensor:159]: 'BH1750 Illuminance': Got illuminance=603.3lx
[19:20:21][D][sensor:094]: 'BH1750 Illuminance': Sending state 603.29718 lx with 1 decimals of accuracy
[19:20:28][D][sensor:094]: 'MAX17043 Battery Voltage': Sending state 3.60500 V with 3 decimals of accuracy
[19:20:28][D][sensor:094]: 'Max17043 Battery level': Sending state 2.68355 % with 3 decimals of accuracy
[19:20:32][D][sensor:094]: 'INA219-45 Bus Voltage': Sending state 4.77600 V with 2 decimals of accuracy
[19:20:32][D][sensor:094]: 'INA219-45 Shunt Voltage': Sending state 0.00147 V with 2 decimals of accuracy
[19:20:32][D][sensor:094]: 'INA219-45 Current': Sending state 0.01470 A with 3 decimals of accuracy
[19:20:32][D][sensor:094]: 'INA219-45 Power': Sending state 0.07056 W with 2 decimals of accuracy
[19:20:34][D][ads1115.sensor:017]: 'ADS1115 Channel A0-GND': Got Voltage=3.156000V
[19:20:34][D][sensor:094]: 'ADS1115 Channel A0-GND': Sending state 3.15600 V with 3 decimals of accuracy
[19:20:38][D][ads1115.sensor:017]: 'ADS1115 Channel A3-GND': Got Voltage=0.015000V
[19:20:38][D][sensor:094]: 'ADS1115 Channel A3-GND': Sending state 0.01500 V with 3 decimals of accuracy
[19:20:43][D][pulse_counter:181]: 'rain gauge': Retrieved counter: 0.00 pulses/min
[19:20:43][D][sensor:094]: 'rain gauge': Sending state 0.00000 pulses/min with 2 decimals of accuracy
[19:20:44][D][dht:048]: Got Temperature=27.9°C Humidity=64.2%
[19:20:44][D][sensor:094]: 'DHT22 Temperature': Sending state 27.90000 °C with 1 decimals of accuracy
[19:20:44][D][sensor:094]: 'DHT22 Humidity': Sending state 64.20000 % with 0 decimals of accuracy
[19:21:19][D][sensor:094]: 'Solar Bus Voltage': Sending state 4.85600 V with 2 decimals of accuracy
[19:21:19][D][sensor:094]: 'Solar Shunt Voltage': Sending state 0.00011 V with 2 decimals of accuracy
[19:21:19][D][sensor:094]: 'Solar Current': Sending state 0.00108 A with 3 decimals of accuracy
[19:21:19][D][sensor:094]: 'Solar Power': Sending state 0.00588 W with 2 decimals of accuracy
[19:21:21][D][bh1750.sensor:159]: 'BH1750 Illuminance': Got illuminance=589.4lx
[19:21:21][D][sensor:094]: 'BH1750 Illuminance': Sending state 589.37494 lx with 1 decimals of accuracy
[19:21:28][D][sensor:094]: 'MAX17043 Battery Voltage': Sending state 3.61750 V with 3 decimals of accuracy
[19:21:28][D][sensor:094]: 'Max17043 Battery level': Sending state 2.68355 % with 3 decimals of accuracy
[19:21:32][D][sensor:094]: 'INA219-45 Bus Voltage': Sending state 4.78000 V with 2 decimals of accuracy
[19:21:32][D][sensor:094]: 'INA219-45 Shunt Voltage': Sending state 0.00146 V with 2 decimals of accuracy
[19:21:32][D][sensor:094]: 'INA219-45 Current': Sending state 0.01460 A with 3 decimals of accuracy
[19:21:32][D][sensor:094]: 'INA219-45 Power': Sending state 0.07056 W with 2 decimals of accuracy
[19:21:34][D][ads1115.sensor:017]: 'ADS1115 Channel A0-GND': Got Voltage=3.150000V
[19:21:34][D][sensor:094]: 'ADS1115 Channel A0-GND': Sending state 3.15000 V with 3 decimals of accuracy
[19:21:38][D][ads1115.sensor:017]: 'ADS1115 Channel A3-GND': Got Voltage=0.015000V
[19:21:38][D][sensor:094]: 'ADS1115 Channel A3-GND': Sending state 0.01500 V with 3 decimals of accuracy
[19:21:43][D][pulse_counter:181]: 'rain gauge': Retrieved counter: 0.00 pulses/min
[19:21:43][D][sensor:094]: 'rain gauge': Sending state 0.00000 pulses/min with 2 decimals of accuracy
[19:21:44][D][dht:048]: Got Temperature=27.8°C Humidity=64.0%
[19:21:44][D][sensor:094]: 'DHT22 Temperature': Sending state 27.80000 °C with 1 decimals of accuracy
[19:21:44][D][sensor:094]: 'DHT22 Humidity': Sending state 64.00000 % with 0 decimals of accuracy
[19:22:12][D][sensor:094]: 'greenhouse Wifi signal': Sending state -54.00000 dBm with 0 decimals of accuracy
[19:22:19][D][sensor:094]: 'Solar Bus Voltage': Sending state 4.85600 V with 2 decimals of accuracy
[19:22:19][D][sensor:094]: 'Solar Shunt Voltage': Sending state 0.00012 V with 2 decimals of accuracy
[19:22:19][D][sensor:094]: 'Solar Current': Sending state 0.00118 A with 3 decimals of accuracy
[19:22:19][D][sensor:094]: 'Solar Power': Sending state 0.00588 W with 2 decimals of accuracy
[19:22:21][D][text_sensor:064]: 'greenhouse Uptime Human Readable': Sending state '5m 34s'
[19:22:21][D][sensor:094]: 'greenhouse Uptime': Sending state 334.24799 s with 0 decimals of accuracy
[19:22:21][D][bh1750.sensor:159]: 'BH1750 Illuminance': Got illuminance=574.9lx
[19:22:21][D][sensor:094]: 'BH1750 Illuminance': Sending state 574.88678 lx with 1 decimals of accuracy
[19:22:28][D][sensor:094]: 'MAX17043 Battery Voltage': Sending state 3.61750 V with 3 decimals of accuracy
[19:22:28][D][sensor:094]: 'Max17043 Battery level': Sending state 2.68355 % with 3 decimals of accuracy
[19:22:32][D][sensor:094]: 'INA219-45 Bus Voltage': Sending state 4.78400 V with 2 decimals of accuracy
[19:22:32][D][sensor:094]: 'INA219-45 Shunt Voltage': Sending state 0.00144 V with 2 decimals of accuracy
[19:22:32][D][sensor:094]: 'INA219-45 Current': Sending state 0.01441 A with 3 decimals of accuracy
[19:22:32][D][sensor:094]: 'INA219-45 Power': Sending state 0.06664 W with 2 decimals of accuracy

Yes, the raw values are reading thousandths of an amp, so the meters seem to be correct.

Did i mention that I can’t check the readings because my Digitech multimeter no longer reads current ? Another expense on my list to replace that :frowning:


Thinks … a device pulls as much current as it wants (up to the max provided by the power supply) … so is the problem with my battery rather than the power monitors ?

As for the battery … I bought a 6600mAh 3.7V battery pack about 8 years ago for a project to build a mobile robot … but then financial circumstances changed and it got shelved. Battery has been unused for much of that time.
When I started bench testing this greenhouse project (but before I got the power meters) I connected a simple LED display volt meter and battery to the Solar power Manager 5V and on to the ESP32, wondering roughly how long the battery would continue to run the ESP32 (i.e. will I need to buy a bigger battery to allow for 3 days operation during winter). I recorded a max of 4.24V, and it ran down to 2.91V. Charged back up to 4.23V, so thought it was OK … but now it seems to max at 3.7V.

At 9:30am the USB charger has been on overnight and the battery has maxed out at 3.64V (3.7V on the LED display). Charge from USB is only 16mA. Solar panel is facing out my window to the wast, so won’t be in sun till the afternoon, though you can see that it is starting to generate a little charge.

Turned USB charger off, and battery voltage immediately starts dropping. Wait till the afternoon, both to see how far the battery voltage drops, and to see how effective the solar panel is …

Hi Donald

Open it up and check the fuses. There are probably 2, one small one (low current) and one large high rupture current type. The large one should be OK but if you are using mA ranges the small one could be gone.

By the way if you do happen to be using mA ranges are you aware of the problem of “voltage burden” where there can be a considerable voltage drop across the meter itself due to its internal current measuring resistance. This drop could cause the device under test (DUT) to behave in an abnormal manner or even start working in a fashion with the lower voltage.

Always a good idea to measure current on the 10A or higher (if available, my particular meter has the high range of 20A) range where this could be a problem. You should still get mA resolution and this voltage burden will be very low.

I have a very useful small AC/DC clamp meter which gets down to mAs with surprising accuracy (as long as you don’t forget to “zero” the meter for DC). Current limit is 100A but it is a clamp meter so is non invasive.
Type is UNI-T model UT210E and it was not very expensive.
Cheers Bob

The interior of multimeter is incredibly tight - had to find a lever to get battery and fuses out. Two fuses are intact, and the 9V battery seems to still have plenty of voltage left in it.

And now I can hear the thunder and see clouds rolling in from the west, so no solar power today either :frowning:

Hi Donald
That seems to be all the simple things checked. It is not unknown for one or both the leads to be dodgy although you would think this would show up at other times. Even the socket (A, mA, µA) you plug into might be faulty.

I don’t have time at the moment to look at your set up in detail but you seem to be concerned with lower than expected current. Is this current being measured with the multimeter connected? If so on the mA ranges the voltage burden I spoke of earlier could cause this. It would be the same as inserting a resistor in circuit. The current measured would be the correct value AT THAT TIME WITH THE DMM CONNECTED. and would not be the true state of affairs existing without the DMM in circuit.

There is something else that does not add up.
Your table quotes the Shunt Voltage at say 37mV. I assume this is the voltage across the sensor shunt resistor which is quoted as being 10mΩ.
Now to get 37mV across 10mΩ requires a current of 3.7A. Quite a bit different from the 38 mA tabled.
I think you should look into this discrepancy as there could be something fundamentally wrong here. In effect the shunt voltage and current don’t agree by a factor of about 100.
Cheers Bob

Hi Donald
Add on to above

I just had a closer look at the numbers in the yellow table directly under that statement and found the following.
I noted the shunt voltage and the current as above and find these numbers are low by a factor of 10. Ohms law says that the current is the voltage divided by the resistance.If I look at a sample in the bus numbers the shunt voltage is 0.00147V so if we divide this by 0.01Ω (10mΩ) we get 0.147A. The figure in this table says 0.0147A

This applies to all the entries in the log. An error of 10X or 1/10.

There is something very basically wrong here and I think you are going to have to do some sleuthing to find out what.
Cheers Bob

You are right Robert, that the Shunt Voltage (in Volts) appears to consistently be 1/10th of the Current (in Amps), which is further confused by Home Assistant’s display rounding the numbers.

  • Both INA219’s show the same ratio, suggesting it’s not simply a faulty unit.
  • The INA219 unit named INA219-45 is connected to a USB power adaptor; which should be supplying a steady 500mA. It is shown supplying 0.003-0000.4A, which is barely enough to keep the ESP32 running.
  • The battery is charging very slowly, which suggests that the current actually passing through is the low amount (as opposed to the reading being incorrect).
  • if it wasn’t borked before, I expect my Li-PO battery is now, after being run flat (2.85V) several times now.

Conclusion: Somewhere, something is limiting the amount of current which can flow.

I have just replaced my USB Adaptor: USB A cable -- INA219-45 -- micro USB cable :Solar Manager 5V board with a single USB cable, and wow, the battery voltage is shooting up without the INA219.

Core, what am I missing ? How can I prove that the DFRobot Digital Wattmeter (SEN0291) is actually working correctly ?

Hi Donald
One explanation for the factor of 10 error is that maybe the shunt resistor is actually 100mΩ and not 10mΩ. This would be difficult for the home hobbyist to measure as it would require a 4 wire resistance measuring system which probably would not be accessible.

To check all this you are going to have to be able to measure the voltage across the shunt resistor and the actual current through it. These measurements need to be as accurate as possible. The resistance of the current measuring device won’t matter here as the same current will be passing through the current measuring device and the shunt resistor and you are interested in that relationship. The current would be better if it were up in the Amps region as otherwise the shunt voltage will be very low and difficult to measure. If using a DMM for current use the 10A or above range and measure the shunt resistor voltage WITH THE CURRENT MEASURING DEVICE CONNECTED.
Have a look at the info on the sensor in regards to calibration and you might get an idea of what you need.

If all this checks out OK I would look at the libraries and see how they calculate the results or try an Arduino in case there is something funny with the RPi system.
Cheers Bob

Robert I have noticed that the ratio of Shunt Voltage to Current differs between the RasPi python code block, and the ESP32 ESPHome log. Looking once more at the ESPHome configuration I see that the INA219 section includes “shunt_resistance: 0.1 ohm” … which matches with your previous assertion that the shunt resistor should be 100m. I will give it a go with 0.01 ohm, and see what difference that makes. Probably wouldn’t hurt to multiple the values by 1000 to make the units mA and reduce the rounding error.

Can you confirm that you have gone through the calibration procedure so that the correct calibration values are being written to the device? If so, can you provide the numbers you used for the procedure. Note that you do not need to measure your calibration current if you have a known voltage and a known resistance, both of which can be measured with the multimeter. You calibration data is measured source voltage, resistance used, calculated current, measured current and calculated calibration value?

Hi Donald

Leave it at Volts and Amps for the time being. Multiplying by 1000 will do nothing for the rounding error as it has already happened (I think). Also leaving it V and A reduces the likelihood of an error with misplacing the decimal point. Ohms law is about V and A and fiddling with mA and mV can lead to large errors.

I don’t or didn’t know about configuration options in ESPHome and nor do I want to. I think the first thing to do is establish the value if the shunt resistor by doing what I said above. Once you know this you can write a sketch to check the whole operation of the sensor. If you are insisting on connecting up a whole monitoring set up first you are going to be running in circles for a very long time.

If you are looking for a power source you might have a 12V 3A or 4A plug pack or other supply, Use something like a 21W incandescent auto globe in series to limit current to between 1.5 and 2A will do the job. Values are not critical as you are not “calibrating” but measurement needs to be as accurate as possible. Calculating the resistance from this should put you in the ball park as we are looking to confirm a value of 10mΩ, 100mΩ or 1Ω.

I think really it will turn out to be 10mΩ as I don’t think a mistake of this magnitude while possible is probable as the number 10mΩ appears far too often to be incorrect. But you never know???
Cheers Bob

Hi Jeff

I think the system has to be working somewhere near properly first. I believe the “calibration” is to trim up any slight variations in shunt resistor value.
What Donald is looking at here is errors of 100X and 10X wh I think would be way out of range for any sort of “calibration” error. Could be wrong as I don’t have one of these devices to play with.

A lot here depends on the multimeter. You would be lucky to find 2 that read EXACTLY the same. While good and convenient they are not necessarily the Holy Grail. Specs are usually written as +/- X% + X (or XX) digits which usually means you can pretty much ignore at least the last digit. Which is all OK as long as one is aware of this and does not go looking for the last vestige of resolution and accuracy. Calibration status should also be considered. A new device could probably be expected to be very close but in the commercial world this is checked every year, I don’t think the home user worries too much about this. Meter quality can and does affect this situation greatly I think.

In reality as long as the user is aware the actual Value of a measurement may not be deadly accurate as long as the same meter is used any comparison or diagnostic type measurements would be quite valid. In most practical instances round up a reading to 1or 2 decimal places will be OK, just don’t go looking for and expecting something like 4 decimal places to be gospel.
Cheers Bob

1 Like

The system is working somewhere near properly - it is providing current readings. The results of running the calibration procedure will inform the process of determining where the error is. If the unit can be calibrated against an approximate standard derived from a measured resistance and voltage (and any typical multimeter will do to that adequately) then OP will know whether the calculation is being done correctly, or not. Accuracy is not critical in trying to prove that the error is simply a misplaced decimal point.

1 Like

Hi Jeff
I did say

where

would be the term I used.

The aim of this exercise is to determine the resistance of the shunt resistor 0.01Ω, 0.1Ω 0r 1.0Ω so granted super accuracy is not mandatory but it is nice to do the best possible with the material at hand.
Cheers Bob
PS. I do think that it will be 0.01Ω but nice to be sure so you are not chasing goblins.

1 Like

Sorry guys, been at work today and I haven’t yet digested all your posts - but wondering if you are focussed on “current measuring” instead of the “current limiting” issue.

Yesterday afternoon I got fed up and replaced the USB cable with SEN0291 with a single USB cable from the USB charger to the Solar Power Monitor, and the battery voltage (measured by MAX17048) shot up quickly, as shown below. After several days of the battery charge not even reaching 3.6V I had given up on my battery, so was relieved to see the new high voltage.


At 3:15am there was a power cut for 2 hours and my PC which logs the measurements was not rebooted until about 7:30am (hence the horizontal line which just assumed the latest reading).

This morning I swapped back to the USB cable with SEN0291 and you can see from the reducing battery level that the charge coming from the USB charger is not sufficient to power the ESP32-S3 (which all the sensors are connected to). It may be that the small current values being reported are correct - but why is so little current getting through the SEN0291 ?? Surely this isn’t normal ?

If you do what I have been suggesting you might find out.
Even if something (like an unwanted resistance somewhere) was limiting the current it should be reflected in the voltage across the shunt resistor. That is the bit that does not make sense. That and the fact the error is 10X or 100X which in itself is suspicious.
Cheers Bob
Cheers Bob