EasyManua.ls Logo

Freenove ESP32 User Manual

Default Icon
159 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #87 background imageLoading...
Page #87 background image
Need support? support@freenove.com
85
Chapter 6 Battery
www.freenove.com
The following is the code:
1
2
3
4
5
6
7
8
9
10
#include "BatteryPower.h"
void setup(){
Serial.begin(115200);
setupAdc();
}
void loop(){
float voltage = getBatteryVoltage() / 1000.0;
Serial.printf("The battery voltage is %fV\r\n", voltage);
delay(1000);
}
In the Arduino IDE, the setup() function is usually used as an initialization function, and the code is executed
only once. Serial.begin() is the initialization function of the serial port. The parameter in the bracket indicates
the speed of the serial port communication, and the unit is usually Bit. The baud rate is set to 115200 here,
which means that 115200 bits of data are transmitted within one second. The setupAdc() function is used to
initialize the battery voltage pin of the esp32.
3
4
5
6
void setup(){
Serial.begin(115200);
setupAdc();
}
In the Arduino IDE, the loop() function is usually used as a repeated execution function, and the code in the
function will be executed in an infinite loop. The getBatteryVoltage() function is used to obtain the voltage
value of the battery in millivolts.
The Serial.printf() function can print the content processed by ESP32 to the serial monitor through the serial
port.
delay(x) is a delay function in milliseconds. Every time it is called, it causes the code execution to pause for x
milliseconds,
8
9
10
11
12
void loop(){
float voltage = getBatteryVoltage() / 1000.0;
Serial.printf("The battery voltage is %fV\r\n", voltage);
delay(1000);
}
BatteryPower.h
1
2
3
4
5
6
7
8
9
10
11
#ifndef _BATTERYVOLTAGE_h
#define _BATTERYVOLTAGE_h
#include "Arduino.h"
#define VOLATAGE_RATIO 4 //Resistance partial voltage ratio
#define PIN_ANALOG_IN 32 //ESP32 GPIO number
#define NUM_OF_SAMPLES 64 //ADC sample times
void setupAdc();
uint32_t getBatteryVoltage();
#endif
Question and Answer IconNeed help?

Do you have a question about the Freenove ESP32 and is the answer not in the manual?

Freenove ESP32 Specifications

General IconGeneral
Clock Speed240 MHz
RAM520 KB SRAM
Wi-Fi802.11 b/g/n
UART3
Operating Voltage3.3V
Input Voltage5V
DC Current per I/O Pin40mA
USBMicro USB
MicrocontrollerESP32
ChipESP32
BluetoothBluetooth v4.2 BR/EDR and BLE standard
ADC Channels/Analog Input Pins18
I2CYes
SPIYes
InterfacesI2C, SPI, UART
CPUDual-Core 32-bit LX6 Microprocessor

Summary

Safety and Precautions

General Safety Guidelines

Outlines crucial safety measures for handling and using the robot kit to prevent injury or damage.

Hardware Components

ESP32 Expansion Board and Modules

Details the ESP32 expansion board, ESP32 module, camera, and other electronic components.

Mechanical Parts and Tools

Lists acrylic parts, servos, screws, nuts, standoffs, and necessary tools for assembly.

Software and Firmware Setup

CH340 Driver and Firmware Installation

Guides on installing the CH340 driver and burning firmware for OS.

Freenove App and Arduino IDE Setup

Covers installing the Freenove app and setting up the Arduino IDE environment.

ESP32 Pin Configuration

Details ESP32 pins, their functions, and descriptions for robot connectivity.

Robot Assembly and Calibration

Step-by-Step Assembly Guide

Details the process of assembling the robot's body, legs, head, and wiring.

Servo Wiring and Calibration

Guides on connecting ESP32, batteries, servos, and performing robot calibration.

Robot Functionality and Control

Freenove App Features

Overviews app features like Wi-Fi config, LED control, and interaction.

Ultrasonic Ranging and Motion Control

Explains ultrasonic sensor and provides code for robot movements.

Communication Protocols and Commands

Explains communication commands via Serial, BLE, Wi-Fi, and development aspects.

Related product manuals