I'm connecting the LiPow charger via UART to a Raspberry Pi 3. When opening a serial console with cu -l /dev/ttyS0 -s 921600
, I can run commands without any problem.
pi@dronebox:~ $ cu -l /dev/ttyS0 -s 921600
Connected.
>help
help:
Lists all the registered commands
stats:
Displays a table showing the system stats
cal:
Calibrates the ADC based on a known input voltage. Expects one argument as a float in milivolts. Connect input voltage to cells 1-4 and the XT60 battery output.
write_otp:
Writes the calibration scalars to OTP flash. Will fail if scalars not set or out of range. Must run cal first with known accurate voltage. Can run up to ~32 times.
task-stats:
Displays a table showing the state of each FreeRTOS task
run-time-stats:
Displays a table showing how much processing time each FreeRTOS task has used
[Press ENTER to execute the previous command again]
>stats
Variable Value
************************************************
Battery Voltage MCU(V) 0.000
Battery Voltage Reg (V) 2.880
Charging Current (A) 0.000
Charging Power (W) 0.000
Cell One Voltage (V) 0.000
Cell Two Voltage (V) 0.000
Cell Three Voltage (V) 0.000
Cell Four Voltage (V) 0.000
2 Series Voltage (V) 0.000
3 Series Voltage (V) 0.000
4 Series Voltage (V) 0.000
MCU Temperature (C) 29
VDDa (V) 3.291
XT60 Connected 0
Balance Connection State 0
Number of Cells 0
Battery Requires Charging 0
Balancing State/Bitmask 0
Regulator Connection State 1
Charging State 0
Max Charge Current 0.000
Vbus Voltage (V) 5.056
Input Current (A) 0.000
Input Power (W) 0.000
Efficiency (OutputW/InputW) nan
Battery Error State 0
[Press ENTER to execute the previous command again]
>
import serial
from time import sleep
ser = serial.Serial("/dev/ttyS0", baudrate=921600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=8, timeout=1)
print("sending...")
ser.write('help\n'.encode())
print('receiving...')
received_data = ser.read()
sleep(0.03)
data_left = ser.inWaiting()
received_data += ser.read(data_left)
print (received_data.decode())
sending...
receiving...
e
Command not recognized. Enter 'help' to view a list of available commands.
[Press ENTER to execute the previous command again]
>
Command not recognized. Enter 'help' to view a list of available commands.
[Press ENTER to execute the previous command again]
>
Command not recognized. Enter 'help' to view a list of available commands.
[Press ENTER to execute the previous command again]
>