Articles Hierarchy

Articles Home » RPI » more hardware for MQTT project

more hardware for MQTT project

we come from end of here
where we created a:

+ PICO_W_CP800b5_Multi_Task_Ains_Temp_DHT22_INA_ADS_USB_MENU_dynamicWebserver_MQTT
+ + PMS1WdotPY ( optional OSCI project included )
on RPI3 fixIP 192.168.1.103
+ mosquitto broker, user p213S31 password p213S31
+ SonOff S31 ( TASMOTA ) Power-meter
+ Node-Red dash-board ( show trend, save local PICO_W mqtt data )
+ python BRIDGE to MQTT cloud broker
+ Node-Red REMOTE dash-board (BRIDGE data send to REMOTE broker : read back from there and show trend )

lets call that combined software project rev 1.0.0 ( published 19.12.2022 )


hardware: sensor INA219 for PS DC output
software: enable INA219 and send to MQTT
oh no CP800b6

connect hardware to LOAD?
** LOAD 3 OHM
** LOAD 12V Battery
** LOAD salt water electrolysis



hardware: sensor INA219 for PS DC output



now here want play with above code ( revisions / improvements expected )
AND using some hardware:

+ + looks like we will try first something with INA219
a small power supply output measurement ( INA limit: max 26 VDC 3.2 ADC )


- - - were i always wonder what would happen when i put a bigger ( smaller OHM ) shunt parallel?
i am not the first one, looks like the Adafruit code for it is tricky ( calibration )
and in Circuit Python we have that adafruit_ina219.mpy file, no idea how to deal with that.
but basically ? just multiply the INA current result with a tuning number ?



but lets start with what i have here:
in the prior BLOGs for this already show
the board:


the board circuit
( here the ADAFRUIT version has STEMMA I2C headers for chaining boards on same I2C "bus", nice feature, but if not needed check for the prize of the simpler versions )


my circuit:


and a running example where i coded a filter for the current signal
( because it was a crazy LOAD aka blinking 12V RGB LED strip / not a INA measuring problem )
and show the filter enable result in Node-Red dash-board



software: enable INA219 and send to MQTT



in PICO_W code project need to enable INA
** as default is just use PICO_W hardware Ains. A0 & A1
like ( for minimal DC Volt Amp measurement )
+ DC_Volt: voltage divider on A0 and
+ DC Amp: shunt milli volt ( shunt in MINUS wire ) A1

BUT
to use INA we need to enable it, and start its multi-tasking JOB
-1- take the PICO_W USB cable from the charger to a PC or RPI USB port
( PICO_W LED on again / PC usb connection info / find like E:/circuitpy/ )
-2- start Mu editor ( in circuit python mode )
open
-2.1- jobs.py
line 11: JOB1en = True # that is for PICO_W analog A0 A1 reads ( and CPU temperature )
line 12: update1 = 30

line 30: JOB3en = True # INA
line 31: update3 = 30

line 46: JOB5en = True # MQTT
line 47:update5 = 60

-2.2- ina.py
line 10: useINA = True

-2.3- mqtt.py

line 24: hereuse_INA = True
line 31: hereuse_PICOW_io = False

info for understanding mqtt code:
MVolt MAmp MWatt are the variables, filled by PICO_W IO OR INA data ( if their jobs enabled )
MVolts MAmps MWatts are the string representation of this data ( 2 decimal / later changed to 3 decimals )
MVoltf MAmpf MWattf are the filtered values ( if useFilter )
( there is now no filter for the raw data, just over the 1 min mqtt data, but can be added in each job )

ok, here i see problems...

- - - error about MTemp in MQTT if JOB1 pico_w IO disabled

? ? ? also how to still get the CPU Temperature if not use A0 A1

- - - that is all very tricky, but yes, you can run any job you want, also use any data from these jobs for MQTT
so in new code mqtt.py line 107:
get the PICO_W RP2040 CPU Temperature even when use INA for Volt Amp Watt, ( if job1 running too )

+ + + now its running
( but i see one time a boot BLIP: INA INIT error even no power hardware connected on the INA board,
ok my hardware is little bit more complicated, as i have INA & ADS connected on same I2C port * parallel aka star connection BAD *)


good boot: ( very informative REPL print enabled )


run: ( see 1 min with one MQTT publish and each 2 times [ pico Ain and INA read ] )
( and the PICO_W web-server http://192.168.1.213/data/ page )


PICO_W code v1.0.1
( repair & set PICO_W I/O and job defaults for use INA )


firmware: oh no CP800b6


22.12.2022 try upgrade CP800b5 to CP800b6
?.env? now ?settings.toml?
https://docs.circuitpython.org/en/latest/docs/environment.html
get new version:
circuitpython.org
also check here:
adafruit-circuit-python.s3
adafruit-circuitpython-raspberry_pi_pico_w-en_US-8.0.0-beta.6.uf2
adafruit-circuitpython-bundle-8.x-mpy-20221221.zip

-0- backup your code
-1- boot / usb connect / PICO_W while press [bootsel]
-2- optional copy flash_nuke.uf2
after drive comes back
-3- copy adafruit-circuitpython-raspberry_pi_pico_w-en_US-8.0.0-beta.6.uf2
after drive comes back as E:/circuitpy/
copy files from new bundle to /lib/


copy project code files and check Mu editor / serial console aka REPL /


Traceback (most recent call last):
File "code.py", line 28, in
File "web_wifi.py", line 247, in setup_webserver
TypeError: can't convert 'NoneType' object to str implicitly
Code done running.


that is the first use of a value got via "os.getenv" WIFI_SSID
VERY BAD, there should be a ERROR that there is no "settings.toml" file
anyhow now i change name ".env" to "settings.toml"
and get a error line 8 when i do
WIFI_SSID = os.getenv('WIFI_SSID')
Traceback (most recent call last):
File "code.py", line 27, in
File "web_wifi.py", line 8, in
ValueError: invalid syntax for integer with base 10

ok my bad...
i used in '.env'
WIFI_SSID = 'myssid'
for settings.toml need to change to
WIFI_SSID = "myssid"
and it runs again
PHUUUU

now we work with:
CP800b6 v1.1.1 PICO_W code

-a- so anyhow back up your code first!
-b- sorry, there is no real need to NUKE the board for a Circuit Python revision...
but i like a clean start..
and it does force you to get the new lib files ( build for that revision )

but yes, you can Drag Drop the new CP.uf2 file to the [bootsel] started board, and your code files should survive.



connect hardware to LOAD?



still no big PS available,
but try again with:


AC from S31 ( Power-Meter TASMOTA MQTT) to

SWPS ( 12V 2.1A ) to

DC/DC Buck-Boost CV CC ( 1 .. 30V 4A with display and fan ) to

PICO_W_I2C_INA219 ( 26V 3.2A ) to

? what LOAD i have here ?

** LOAD 3 OHM


+ small power resistor ( 3 Ohm 50W 1% )

12VDC to DC/DC, output adjust to 4V, current in CC mode reduced to 1A aka CC reduced Volt to 3.1V
very nice tool,
BUT after powerup show 12V input NO output, MUST press button [On/Off]
ok need to check if there is a other setting for this?

NOW wire in the INA, obviously
the PLUS wire must be looped through the INA shunt ( 2 screw connectors )
( but with this still not see much ) need to connect MINUS too ( see again my above circuit )
but HOW ( missing a MINUS screw connector on the board )
my circuit show a connection to ANY of the PICO_W board GND pins..
but from a measuring point of view a direct INA board soldered wire would be best.


BRIDGE DATA+++ from PICO W: lastt 2022_12_22_13_59_14 id 3 dev P01 Temp 27.61 Volt 3.09 Amp 1.03 Watt 3.19
+++ from S31:lastt 2022_12_22_13_59_57 Time 2022-12-22T07:59:57 Voltage 234 Current 0.063 Power 8
___+ published mid: 172
___+ 2022_12_22_14_00_00 publish P213
{ "id": 171, "minute": 0, "datetimes": "2022_12_22_13_59_14", "AC_Volt": 234.00 , "AC_Amp": 0.06 , "AC_Watt": 8.00 , "PS_Temp": 27.61 , "DC_Volt": 3.09 , "DC_Amp": 1.03 , "DC_Watt": 3.19 }

( too BIG Watt difference? )

as RPI Bridge was running, startup data are ONLINE:


as the Resistor got too hot to touch i reduced the DC Amp to 0.5A ( via CC mode )
and because of the Filter ( in PICO_W : mqtt.py Va, Ia, Wa = 0.8 ( aka show 20% new value ) )
had too long to wait for response in REMOTE Trend

in v1.1.1b try filter 0.6 ( and data with 3 decimals )

then try 0.4 and then 0.2 ( can see in one picture )


interested in learn more about that filter? get a spreadsheet from 2011


- - - while the S31 data are unfiltered, the AC reacted fast, but IAC low-range has bad resolution..
( 0.06A > 8.00W now 0.05A > 4.00W )
hm.. but the 2 decimals for current is my doing ( making JSON like string from formatted f0.2 float prints )
but no decimals for Watt must be from TASMOTA?

but let's not forget that the 8$ S31 power meter is build for 15 A, at 240V would be 3600W

now this Node-Red dashboard trend ( all default settings ( like 1 h ) ) on the REMOTE data stream
( and no historic database.. ) looks like it need work,
but no, as it is anyhow only a temporary 'show' as until now even the mqtt payload definition ( names )
also temporary ( waiting for a one line example from the future TARGET broker )


** LOAD 12V Battery


i have here a old?bad? sure empty 12V battery from a replacement at Honda PCX 150i
always wanted to use it for a emergency light..

so with keeping the adjustment to CC 0.5A
i can replace the resistor with the battery
- - - no expert in battery loading but expect like
empty 11V
nominal 12V
full 13V
charging max 14 V
** so only using my small SWPS 12V on a battery would mean burn in the first second OR not do anything ? 12,8V min?
but with the new DC/DC buck boost CC CV it might work.
and with changing CV ( from now 4V ) to 14V
should see a nice charging Volt curve to 14 V at const. 0.5A
let's just try it.
oh BAD, old battery show no volt and even connect 14V no current >>> garbage

But today 10.1.2023 got a other battery, that show 12.8V NO LOAD,
but HONDA battery tester say it must be replaced!
again i adjust DC/DC
VC 14V
CC 0.5A
and connect, but in one minutes the current dropped as the Voltage rise up to 14.00V
( ok, but CV and CC worked nicely )



so what might be the correct charging voltage again?
i play 14.4 and 14.7 V but not much current...
that battery is FULL?


now i try it to power a LED STRIP with it?
and for a emergency light need add ?
a relay what goes down on power fail but switch the LED ON
a LDR sensor for LED ON at night only?

** LOAD salt water electrolysis


The last might be the best as it is a adjustable resistor
* a plastic bucket ( might be not usable again ) or glas or steel ( use as cathode too )
* a CATHODE, connect a copper wire to a ( submerged ) building steel rod
( might need to change the water after steel de-rosting phase )
* a ANODE / well, that is a extra topic but here i have
+++ a very tiny "Titanium MMO mesh" anode ( cathodic protection type )
* water
* salt ( add spoon by spoon ) to adjust current ( 35 g/L would be sea-water )
( i think i did that first time 2006 with DMM measurements to excel sheet )
- - but it is a messy stinking thing
!! only use outdoor: H2 gas on cathode ( fire hazard) + Cl2 gas on anode ( poison-as and corrosive gas )


while science is working on anodes ( or water permeable walls ) to do that ( H2 and O2 ),
some web info that seawater electrolysis would create O2 is WRONG
and some JUST LIE





so here come a interesting test 11.1.2023:



a old Ti MMO mesh anode ( like it is used to protect steel in ?submerged? concrete buildings.. )



a steel container ( saw of the head of a insect spray and wash it with hot water )
connect a copper wire



fill it with pure water and dip the anode in

ALL LIVE as volt and current is reduced CV CC

now check:

from 0.5 to 7V NO AMP
up to 12V 0.04A

so pure water is a good isolator,
when i switch OF power for a break i see already something??



capacitive OR electrolytic unloading?
note: mqtt filter was OFF for this test



now i want see some current to check if the setup is worth the time..

? household vinegar
acetic acid 6%
30ml in ?0.7L not show much of a reaction.
? lemo ? baking soda ?



now try to make SALT-WATER
35g salt per Liter water is target,


just for test:
2 tea-spoon about 10g? already give
4V 0.44A
but instead of rising current ( while the salt is expected to dissolve )
i see a decay current to 0.4A
lucky with that test result under the 0.5A CC limit
anyhow my setup ( anode / steel / PS ) is good to go.
| Volt | init A | stable A |
4V 0.44A .. 0.38A
5V 0.73A .. 0.69A
6V 1.07A .. 1.07A
7V 1.47A .. 1.47A
8V 1.87A .. 1.87A
9V 2.24A .. 2.28A LIMIT PS 2.5A



4V 0.4A
3V 0.17A
2.5V 0.1A
2V 0.04A




now while this was a test with unspecified salt water ( 2 spoons on 0.7L water )


for sea-water i want do like 4 steps
0% 25% 50% 75% 100% sea-water
but i not try to play / weight X g of SALT
no good tools for this,

from a shop get ?g pack of salt
and put it in ?L water ( little bit heated ) to create 100% sea-water

now with mixing batches of it with more water dilute it to the step targets



here now i also model the salinity into the current model for this setup & anode



follow me