Cool stuff for Raspberry Pi, Arduino and all electronics hobby projects
Notifications
Clear all

Monitoring output current using a Witty Pi 4 on a Rapsberry Pi 4

5 Posts
2 Users
0 Likes
98 Views
JeromeBriot
(@jeromebriot)
Posts: 13
Active Member
Topic starter
 

Hello,

I try to monitor the output current trough the Witty Pi 4 on a Raspberry Pi 4.

The system is 12V powered using a bench power supply. Power is applied on the VIN connector (XH2.54).

The bench power supply gives me 12V and 0.240A when the Raspberry Pi is idle.

Here are some results monitoring the current at 10Hz:

0.170 0.380 0.170 0.210 0.170 0.360 0.340 0.120 0.320 0.340 0.100 0.080 0.060 0.100 0.320 0.120 0.340 0.080 0.080 0.380 0.250 0.360 0.020 0.080 0.080 0.150 0.100 0.120 0.100 0.040 0.120 0.230 0.150 0.170 0.320 0.100 0.230 0.100 0.380 0.230 0.100 0.340 0.150 0.100 0.250 0.190 0.100 0.100 0.320 0.300 

Is it normal that the values fluctuate so greatly?

Can the output current monitoring be improved?

Here is the Python script I use:

import smbus
from time import sleep

WITTY_PI_I2C_ADDRESS = 0x08

class WittyPi():

    def __init__(self):

        self.i2c_bus = smbus.SMBus(1)

        self.firmware_id = 0
        self.input_voltage = 0.0
        self.output_voltage = 0.0
        self.power_mode = 0
        self.firmware_revision = 0

        self.get_firmware_id()
        self.get_input_voltage()
        self.get_output_voltage()
        self.get_output_current()
        self.get_power_mode()
        self.get_firmware_revision()

    def get_firmware_id(self):

        self.firmware_id = self.read_register(0x00)

    def get_input_voltage(self):

        self.input_voltage = self.read_register(0x01) + self.read_register(0x02) / 100

    def get_output_voltage(self):

        self.output_voltage = self.read_register(0x03) + self.read_register(0x04) / 100

    def get_output_current(self):

        self.output_current = self.read_register(0x05) + self.read_register(0x06) / 100

    def get_power_mode(self):

        self.power_mode = self.read_register(0x07)

    def get_firmware_revision(self):

        self.firmware_revision = self.read_register(0x12)

    def read_register(self, register):

        try:

            data = self.i2c_bus.read_byte_data(WITTY_PI_I2C_ADDRESS, register)

        except OSError as e:

            data = None

        return data

    def __str__(self):

        s = 'Witty Pi\n'

        s+= f'  Firmware ID: {self.firmware_id:02X}\n'
        s+= f'  Firmware revision: {self.firmware_revision}\n'
        s+= f'  Input voltage: {self.input_voltage:.3f}V\n'
        s+= f'  Output voltage: {self.output_voltage:.3f}V\n'
        s+= f'  Output current: {self.output_current:.3f}A\n'
        s+= '  Power mode: ' + ('LDO regulator' if self.power_mode == 1 else '5V USB') + '\n'

        return s

def main():

    witty_pi = WittyPi()

    for i in range(0,50):
        witty_pi.get_output_current()
        print(f'{witty_pi.output_current:.3f} ', end='')
        sleep(0.1)

if __name__ == '__main__':

    main()

Thank you

 

 
Posted : 29/01/2025 2:44 pm
Topic Tags
(@admin)
Posts: 535
Member Admin
 

Posted by: @jeromebriot

Is it normal that the values fluctuate so greatly?

It is not normal. However I do think 10Hz is too frequenlty for gethering this value. Do you really need to get this value 10 times per second? I am not sure if this would overload the MCU and whether it relates to the fluctuating though.

Do you still see such fluctuating, if you get this value only 1 time a second?

 
Posted : 30/01/2025 6:18 pm
JeromeBriot
(@jeromebriot)
Posts: 13
Active Member
Topic starter
 

Actually I just need to record the value of Iout every 5 minutes.

But here is an example of data collected yesterday (using crontab to run a Python script every 5 minutes) with Iout on the last column:

Time(UTC);ExternalTemperature(C);ExternalHumidity(%);CpuTemperature(C);Vin(V);Vout(V);Iout(A)
05:15;19.6;51.6;46.7;11.960;5.030;0.100
05:20;19.4;51.7;45.8;11.960;5.090;0.040
05:25;19.2;52.0;45.8;11.960;5.080;0.020
05:30;19.5;51.8;47.7;11.960;5.030;0.150
05:35;19.6;51.2;49.7;11.960;5.030;0.170
05:40;19.5;51.8;47.2;11.960;5.030;0.380
05:45;19.5;51.8;46.7;12.020;4.980;0.080
05:50;19.5;52.0;46.3;11.960;4.970;0.060
05:55;19.6;52.0;45.8;11.960;5.080;0.320
06:00;19.7;52.0;46.3;12.020;5.030;0.000
06:05;19.8;52.0;45.8;11.960;4.970;0.270
06:10;19.9;51.9;45.8;11.960;5.030;0.060
06:15;20.1;51.9;44.8;12.020;4.970;0.080
06:20;20.2;51.8;45.8;11.960;5.030;0.380
06:25;20.5;52.1;46.7;11.960;5.090;0.040
06:30;20.7;51.6;46.7;11.960;5.080;0.360
06:35;20.8;51.1;47.2;11.960;5.020;0.300
06:40;21.1;50.6;49.7;11.960;5.010;0.100
06:45;21.4;49.9;51.6;11.960;5.020;0.100
06:50;21.6;49.2;52.1;11.960;5.090;0.120
06:55;21.8;49.8;54.0;11.960;5.090;0.300
07:00;22.0;48.4;54.0;11.960;5.030;0.080
07:00;22.0;48.3;53.6;11.960;5.030;0.210
07:05;22.2;47.6;53.6;11.960;5.030;0.340
07:10;22.4;47.2;54.0;11.960;5.090;0.170
07:15;22.4;47.3;57.0;11.900;4.970;0.020
 
Posted : 31/01/2025 9:11 am
JeromeBriot
(@jeromebriot)
Posts: 13
Active Member
Topic starter
 

@admin Do you need more information?

 
Posted : 05/02/2025 11:04 am
(@admin)
Posts: 535
Member Admin
 

@jeromebriot Your data shows the fluctuating of current reading, however I can not tell if it is really an issue: it is possible that the current are really changing this fast, or there is source of interference that interferes the ADC reading.

We do not pursue a very accurate current reading in Witty Pi: the current value only gives some idea about wheather the device is under heavy load. The ADC in ATtiny841 is not very accurate too. If it is important to you, you may consider using an algorism to smooth the values so the output value makes more sense.

 
Posted : 05/02/2025 11:39 am
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.