Reading voltage values from the battery

From youBot wiki
Jump to: navigation, search

Reading the voltage level is only possible with the internal PC which connected via USB to the power board. An example Python app to read the voltages as shown in the following has to be executed on the internal PC. You can also implement a C-based version of the software:

 import serial

 import time

 ser = serial.Serial('/dev/ttyACM0')

 #print ser

 on the display board line 2 and 3

 #trailing \CR== 0x0d needed for next readline not to hang up.

 ser.write('\x02Put L1 text here\x0d\x03Put L2 text here\x0d')

 ser.flush()

while 1:

 try:

 print 'Battery1Voltage[mV]\tBattery2Voltage[mV]\tPowerSupplyVoltage[mV]'

 for i in range(20) :

 ser.write('\x04') #read voltage of battery 1

 vBatt1 = ser.readline()[:-2] #read from serial / delete last two character{ [:-2] == (\CR + \LF) }

 ser.write('\x05') #read voltage of battery 2

 vBatt2 = ser.readline()[:-2] #read from serial / delete last two character{ [:-2] == (\CR + \LF) }

 ser.write('\x0c') #read voltage of power supply

 vPowSup = ser.readline()[:-2] #read from serial / delete last two character{ [:-2] == (\CR + \LF) }

 print '\t'+vBatt1+'\t\t\t'+vBatt2+'\t\t\t'+vPowSup

 ser.write('\x02Batt1[mV]: '+vBatt1+' \x0d\x03Batt2[mV]: '+vBatt2+' \x0d')

 time.sleep(0.5)

 except:

 break

print 'Ending program and closing serial port'

 ser.close()



Go back to Technical Support Software

Corrections, suggestions, and new documentation should be posted to the Forum.