DigitalShoestringSolutions / PowerMonitoring

GNU General Public License v3.0
0 stars 1 forks source link

Support for Grove ADC on Basic Power Monitoring #15

Open tobyaharris opened 2 months ago

tobyaharris commented 2 months ago

Upgrading a demonstrator from PowerMonitoringBasic to PowerMonitoring. Single phase.

PowerMonitoringBasic was working. PowerMonitoring did not.

I'm using the Grove ADC. The traceback was:

2024-04-22T15:10:22.048915+01:00 DemoRailPowerBasic docker-current-sensing[1176]: ERROR:core.sensing_stack:Error during sampling: Traceback (most recent call>
2024-04-22T15:10:22.049002+01:00 DemoRailPowerBasic docker-current-sensing[1176]:   File "/app/core/sensing_stack.py", line 25, in execute
2024-04-22T15:10:22.049088+01:00 DemoRailPowerBasic docker-current-sensing[1176]:     sample_resp = self.device.sample()
2024-04-22T15:10:22.049169+01:00 DemoRailPowerBasic docker-current-sensing[1176]:   File "/app/core/device_modules/adc_grove.py", line 41, in sample
2024-04-22T15:10:22.049248+01:00 DemoRailPowerBasic docker-current-sensing[1176]:     raise e
2024-04-22T15:10:22.049356+01:00 DemoRailPowerBasic docker-current-sensing[1176]:   File "/app/core/device_modules/adc_grove.py", line 34, in sample
2024-04-22T15:10:22.049446+01:00 DemoRailPowerBasic docker-current-sensing[1176]:     readings = self.i2c.read_register(register_addr, 2,stop=True)
2024-04-22T15:10:22.049505+01:00 DemoRailPowerBasic docker-current-sensing[1176]:   File "/app/core/interface_modules/i2c.py", line 25, in read_register
2024-04-22T15:10:22.049570+01:00 DemoRailPowerBasic docker-current-sensing[1176]:     self.i2c.i2c_rdwr(write_reg_addr)
2024-04-22T15:10:22.049635+01:00 DemoRailPowerBasic docker-current-sensing[1176]:   File "/usr/local/lib/python3.9/site-packages/smbus2/smbus2.py", line 658,>
2024-04-22T15:10:22.049700+01:00 DemoRailPowerBasic docker-current-sensing[1176]:     ioctl(self.fd, I2C_RDWR, ioctl_data)
2024-04-22T15:10:22.049763+01:00 DemoRailPowerBasic docker-current-sensing[1176]: OSError: [Errno 5] Input/output error

Which looks similar to hardware disconnected, but i2cdetect -y 1 reports the adc at 0x08 as expected. Switched back to PowerMonitoringBasic (master) and it's fine again. What broke?

I am suspicious of the hardcoded address in the config file: https://github.com/DigitalShoestringSolutions/PowerMonitoring/blob/4b6625a0f690af022bf046d64f5f9e161e9ff84a/current_sensing/config/pm_b_1p.toml#L7

But shouldn't what address to poll be taken care of by the adc board selected: https://github.com/DigitalShoestringSolutions/PowerMonitoring/blob/4b6625a0f690af022bf046d64f5f9e161e9ff84a/current_sensing/config/pm_b_1p.toml#L20

So why is any address hardcoded?

tobyaharris commented 1 month ago

Changing https://github.com/DigitalShoestringSolutions/PowerMonitoring/blob/4b6625a0f690af022bf046d64f5f9e161e9ff84a/current_sensing/config/pm_b_1p.toml#L7

to addr=0x08 works, but why should that be necessary?