How to control FSESC(base on VESC) with Arduino ?
Among many VESC users, some are passionate about programming and prefer controlling their VESC with Arduino. In this blog, we’ll step by step introduce three ports controlling by using Arduino: PPM, UART, ADC.
- Preparations
- PPM port Control
- UART port control
- ADC port control
Preparations:
- Make sure the software compilation tool (arduino) has been installed and an arduino board is prepared; make sure you have skills of flashing program, adding a zip file, etc. get an arduino software download: https://www.arduino.cc/en/Main/Software
- Make sure you have skills of soldering or wiring and are able to wire according to the wiring diagram I drew.
- Got basic knowledge of C language.
PPM Control:
- General introduction of PPM signal
- Wiring diagram
- Code to achieve PPM control
- VESC tool operation reminds
First ,we need to know, what is the PPM signal?
I would like to briefly describe it here: a signal with pulse width of 1ms to 2ms in a cycle of 20ms, the standard level of it is 5V.
20ms(50Hz)One Cycle Signal
PPM Signal with Pulse Width of 2.0ms
PPM Signal with Pulse Width of 2.0ms
Want to know more detail information about PPM, here it is by someone else: Https://oscarliang.com/pwm-ppm-difference-conversion/
Reminds: Controlling VESC with PPM signals is the most popular and most conventional one. It’s actually not necessary to completely follow the PPM signal format since the VESC's throttle signal is adjustable. But , the VESC tool PPM mapping default set is standard PPM signal format.
Secondly , make correct wiring:
Wiring diagram is as follows:
UNO |
VESC |
5V |
5V (red wire) |
GND |
GND (black wire) |
D5 |
Signal wire (white wire) |
Following picture is an arduino board with wiring instruction:
The potentiometer indicated in this blog can also be a joystick.
Next Step:
Set the value of the PPM output by the digital port 5 according to the detected change of the potentiometer
Here’s setting value code:
#include <Servo.h>
const uint8_t VescOutputPin = 5;
const uint8_t PotentiometerPin = A0;
Servo esc;
void setup() {
esc.attach(VescOutputPin);
esc.writeMicroseconds(1500);
}
void loop() {
esc.writeMicroseconds(map(analogRead(PotentiometerPin), 0 , 1023, 1000, 2000));
}
Lastly, you need to finish parameter setting in VESC tool, the operation is similar like with a remote control. Refer to our tutorial: https://goo.gl/UMtZnS
UART Control:
- General introduction of UART control mode
- Install a library to arduino
- Wiring diagram
- Input code to achieve UART control mode
- VESC tool operation for UART mode
Controlling VESC with UART is also a common way: writing data to VESC through UART so that the VESC can make corresponding actions according to the given instructions.
So UART-VESC communication can not only control the throttle, but also make reverse , cruise and other functions possible. Some parameters from the VESC can also be read, such as battery voltage, eprm value, motor temperature and so on. For details, please refer to the UART description written by Benjamin: http://vedder.se/2015/10/communicating-with-the-vesc-using-UART/
Fist step: Install a library to arduino.
The library I used in this blog was written by RollingGecko and modified and updated by SolidGeek. Thanks to them for their contributions to the esk8 community! This is the link to the library I am using: https://github.com/SolidGeek/VescUART , you may download it from the link above and add it to the arduino library.
Second step: Wiring
Wiring diagram is as follows:
UNO |
VESC |
5V |
5V |
GND |
GND |
TX |
RX |
RX |
TX |
Third step: Set the value to the UART
Connecting the analog port A0 to the signal cable of the potentiometer for detecting the change of the potentiometer; determining what value to input to the UART according to the detected change of the potentiometer. In this program I just did a simple throttle control, you may add other functions by reading SolidGeek's library: motor reversal, cruising and reading VESC’s data.
Here’s example code.
#include "VescUart.h"
VescUart VESCUART;
const uint8_t PotentiometerPin = A0;
uint32_t LastTime = 0;
void setup() {
Serial.begin(115200);
VESCUART.setSerialPort(&Serial);
}
void loop() {
if((millis() - LastTime) > 10){
VESCUART.nunchuck.valueY = map(analogRead(PotentiometerPin), 0, 1023, 0, 255);
VESCUART.setNunchuckValues();
LastTime = millis();
}
}
Last step: do parameters setting in VESC tool, choose “UART” mode , the baudrate must be 115200 in UART mode.
ADC Control:
It is not common to see the ADC port controlling VESC. Here it will also be briefly introduced. The principle of ADC control is to output the corresponding throttle value by reading the voltage difference. The reading range of the voltage is 0V-3.3V. According to the principle, there’s no need to use the arduino board to control the VESC, ( because filter processing is required to make the ADC value stable, it’s a cost up solution ). So only the potentiometer or thumb throttle is needed.
Wiring diagram is as follows:
potentiometer |
VESC |
1 |
3.3V |
2 |
ADC |
3 |
GND |
All three ports are introduced to control VESC so far. Do you have a general idea of it? want to try it now , click here to get the VESC firstly.
https://flipsky.net/collections/electronic-products
Hey
I want to say what a beautiful site you have made.
I am a regular customer of your store.
I had visited your store last month, and I saw a very nice product i wanne order.
But I have a question! today I wanted to order it, but can not find the product anymore in your webshop.
The product looks like the first picture on this site. http://bit.ly/RemotControlPictureModel4245
I hope you will sell it again soon.
I’ll wait.
Sincerely
Hi, signal you explained is not PPM, it is PWM signal: pulse width modulation. Servo signal as is mentioned in FSESC manual, is always PWM 20ms rate and 1-2ms signal lenght. PPM is a series of inverted PWM signals typically used in some receivers, but the signal you show is definately PWM.
Just read here for further info: https://oscarliang.com/pwm-ppm-difference-conversion/
Another question: For the PPM Control section, where do you insert that code? I don’t see it in the BLDC tool.
Hey Ken,
Thanks for the helpful article! I am trying to figure out how to control my VESC through the Arduino. I will be getting values in a different way than you, but could convert them into the potentiometer range. However, I am confused at the point where the VESC is connected straight to the Arduino. Shouldn’t the VESC be connected right to the batteries?
I really appreciate any feedback or help you can give me.
Thanks
I’ve been controlling VESCs and FSESCs with Arduino’s using CAN for some time now. Depends on what you’re doing, but IMHO it’s the most powerful and safest control method, capable achieving the highest performance. I use it for robotics applications where I want to be sending position or velocity commands at hundreds of Hz. hmu if there’s any interest in the code/collaborating.
Leave a comment