member-projects:m0jqq_-_bpq_for_beginners
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| member-projects:m0jqq_-_bpq_for_beginners [2024/12/15 12:13] – [Monitoring a Remote Battery Voltage] m0jqq | member-projects:m0jqq_-_bpq_for_beginners [2025/08/01 18:33] (current) – m0jqq | ||
|---|---|---|---|
| Line 424: | Line 424: | ||
| == Arduino code == | == Arduino code == | ||
| + | |||
| + | < | ||
| + | //To measure up to 15V dc | ||
| + | |||
| + | #define inputPin A0 | ||
| + | // mvpc is a measurement of actual millivolsts per count (5v ref/1064) | ||
| + | const float mvpc = 4.55; | ||
| + | //counts are the ouput of the adc | ||
| + | float counts = 0; | ||
| + | float mv = 0; | ||
| + | float multi = 3; | ||
| + | //multi depends on voltage divider setup (3 x 5k in series) | ||
| + | float output = 0; | ||
| + | |||
| + | void setup() { | ||
| + | // put your setup code here, to run once: | ||
| + | Serial.begin (115200); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | // put your main code here, to run repeatedly: | ||
| + | counts = analogRead (inputPin); | ||
| + | mv = counts * mvpc; | ||
| + | output = (mv * multi) / 1000; | ||
| + | Serial.println(" | ||
| + | |||
| + | delay (5000); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | == Create python3 script – battMonitor.py== | ||
| + | Depending on RPI OS version, you may need to install Python and/or Python libraries | ||
| + | |||
| + | < | ||
| + | cd ~/ | ||
| + | nano battMonitor.py | ||
| + | #!/usr/bin python3 | ||
| + | import serial | ||
| + | import time | ||
| + | sdata = serial.Serial('/ | ||
| + | time.sleep(2) | ||
| + | sdata.reset_input_buffer() | ||
| + | print(" | ||
| + | try: | ||
| + | while True: | ||
| + | time.sleep(0.01) | ||
| + | if sdata.in_waiting >0: | ||
| + | file = open("/ | ||
| + | battState = sdata.readline().decode(' | ||
| + | file.write(f" | ||
| + | file.close() | ||
| + | print (battState) | ||
| + | except KeyboardInterrupt: | ||
| + | print(" | ||
| + | sdata.close() | ||
| + | file.close() | ||
| + | |||
| + | </ | ||
| + | Make it executable < | ||
| + | |||
| + | == Create bash startup script – getBattMonitor.sh == | ||
| + | < | ||
| + | nano getBattMonitor.sh | ||
| + | |||
| + | #!/bin/bash | ||
| + | sudo python3 / | ||
| + | sleep 1 | ||
| + | </ | ||
| + | |||
| + | Make it executable < | ||
| + | |||
| + | |||
| + | Now is the time to test your work. Connect a variable power supply set to less than 5 volts to the batt+ and Gnd connections of your Arduino and measure the voltage between GND & A0 It should be about one third of your variable power supply voltage. | ||
| + | Start the script with < | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | a < | ||
| + | |||
| + | |||
| + | |||
| + | |||
member-projects/m0jqq_-_bpq_for_beginners.1734264835.txt.gz · Last modified: by m0jqq
