Example Code for Jetson Nano-Battery Voltage and Percentage Reading
Read the battery power percentage and battery voltage information of the Jetson Nano UPS module using Python software.
Hardware Preparation
- Jetson Nano Developer Kit: 1
- DFR0865 Jetson Nano UPS Module: 1
- 18650 lithium-ion batteries: 6
Software Preparation
- First, install the pip of Python3 on the Ubuntu system. Please run the following command as the root user or sudo user in the terminal:
sudo apt-get update
sudo apt-get install python-pip
- Install Jetson GPIO library:
sudo pip install Jetson.GPIO
- Install the I2C development library:
sudo apt-get install libi2c-dev i2c-tools
pip install smbus
- Install Nano editor on Ubuntu:
sudo apt-get install nano
Wiring Diagram
Correctly install six 18650 batteries to the Jetson Nano UPS power board, and connect to Jetson Nano through the 10 Pin GPIO board. The connection diagram is as follows:

Other Preparation Work
- Create a new file named
Bat.pyusing the Nano editor or any text editor. - Copy the sample code provided into the
Bat.pyfile.
Sample Code
#!/usr/bin/env python
import struct
import smbus
import sys
import time
def readVoltage(bus):
address = 0x36
read = bus.read_word_data(address, 2)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
voltage = swapped * 1.25 /1000/16
return voltage
def readCapacity(bus):
address = 0x36
read = bus.read_word_data(address, 4)
swapped = struct.unpack("<H", struct.pack(">H", read))[0]
capacity = swapped/256
return capacity
bus = smbus.SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
while True:
print "******************"
print "Voltage:%5.2fV" % readVoltage(bus)
print "Battery:%5i%%" % readCapacity(bus)
if readCapacity(bus) == 100:
print "Battery FULL"
if readCapacity(bus) < 20:
print "Battery LOW"
print "******************"
time.sleep(2)
Run the command in the terminal to execute the code:
sudo python Bat.py
Result
Now you get the battery power percentage and battery voltage information.
Additional Information
Was this article helpful?
