1. Introduction to battery power inquiry driver
The battery power query driver is also customized by Yahboom officially for Jetbot. We provide the matching Battery_Vol_Lib.py driver. Put the driver file in the same folder as the program we need to use it.
The hardware that implements this feature is designed on the hardware of the RGB programming light strip.
Path of package : [Jetbot-AI Car] --> [Annex] --> [Driver file]---> [Battery_Vol_Lib.py]
The initialization of the driver is done when we first create the RGB instance.
The driver is as follows:
We can get the current battery status by simply calling the example method shown above.
2. Battery power drive
In this course, we refreshed the displayed battery level in real time in the lower right corner of the OLED screen.
Before this, in order to avoid Jetbot's real-time refresh display, the stats.py program running by jetbot_stats.service and the program we are testing now use an I2C peripheral OLED screen at the same time and generate an exception conflict.
We need to stop refresh the operation of the OLED service at the Jetbot command console.
sudo systemctl stop jetbot_start
After executing the above command, we can observe that there is no value refresh display on the screen.
Next, run the code we want to test:
First, import the modules we need to use：
Next, we create the SSD1306 object instance that we need to use and create the variables we need to use. When creating an OLED object instance, the driver initialization function is automatically called to initialize the OLED.
Create the BatteryLevel object instance we need to use and create the variables we need to use. When we create the object instance, we will automatically call the driver initialization function to initialize the battery query driver.
The specific code is shown below:
After running the above code, we can see that the display on the OLED screen is cleared, which means that our code is initialized for both the OLED screen and the battery query driver.
Next, we run the following code to start collecting Jetbot usage data in real time every second and refresh the display to the onboard OLED display.
After running the above code, the current usage information of Jetbot robot car will be displayed on the OLED display, and the battery power information will be displayed in the lower right corner of the screen, as shown below.
The corresponding complete source code is located at:
/home/jetbot/Notebook/7.Battery power inquiry/Battery power inquiry.ipynb
- Yahboom JetBot AI Robot Car Tutorial
- Last Tutorial>> 4.5 Using of Onboard OLED
- Next Tutorial>> 4.7 Use of PTZ servos