Code: [Local Link Removed for Guests]
Hardware:
8-AA nominal 12V battery pack, several years old and only starting with a little over 10V
48-LED 12V-48V automobile interior light
PZEM-017
50A shunt
RS485 RTU module (as shown in the Annex manual)
ESP32-C3Supermini
Here are the registers the PZEM-017 provides: Volts (16-bit), Amps (16-bit), Watts (32 bits), Watt Hours (32 bits) Here is the code, mostly from the manual. I changed the modbus.requestRTU command to read 6 16-bit words starting from register 0.
Code: [Local Link Removed for Guests]
' RS485RTU.bas ' with PZEM-017, use RS485 to get voltage/current readings
READ_INPUT_REGISTER = 4
SERVER_ID = 1
onWgetAsync modbus_received 'set the event handler function
modbus.setupRTU 4,3,2 ' pins; by default is 9600,N,8,1
do
modbus.requestRTU 1234, SERVER_ID, READ_INPUT_REGISTER, 0, 6 ' 6 bytes from reg 0
pause 3000
loop
end
modbus_received:
r$ = WGETRESULT$
' wlog r$,ramfree(1)
token$ = word$(r$, 1) 'extract the token (first word)
if (token$ ="1234") then ' if the token correspond to the read request
if (word$(r$, 2) <> "Error") then 'if is not an error
'assemble the 2 bytes in one 16 bits word
Volts$ = "&h"+ word$(r$, 5) + word$(r$, 6)
Amps$ = "&h"+ word$(r$, 7) + word$(r$, 8)
Watts$ = "&h"+ word$(r$, 11) + word$(r$, 12)+ word$(r$, 9) + word$(r$, 10)
WattHours$ = "&h"+ word$(r$, 15) + word$(r$, 16)+ word$(r$, 13) + word$(r$, 14)
' volts amps watts Watt hours
wlog val(Volts$)/100,val(Amps$)/100,val(Watts$)/10,val(WattHours$)
else
wlog r$
end if
endif
return
This is just a test to understand the wiring and to get the code working. Next I plan to hook it up to a 12V 50A LiFePO4 battery and run a 300W inverter and 200W 120V heater off of it, running until the battery shuts off. Then, with a bigger shunt, a 48V 100A LiFePO4 battery running a 2K 120V inverter and a 9000BTU mini-split heat pump.
And I plan to add a web page, and also to log readings to my house data accumulator (a Raspberry Pi 5).
Fun to make progress, and thanks ever so much for Annex, which ultimately made easy what I thought would be hard.