hello I want to realize the openRC-F1 project and I use an arduino nano and an HC-06 bluetooth module to control the motor with the ESC.
I manage to run the motor by putting fixed values in the code but I can't control it remotely with my phone and a slider. here is the code I am using:
#include <Servo.h>
#include<SoftwareSerial.h>
Servo esc;
SoftwareSerial mySerial(2, 3); // RX, TX
char Throttle;
void setup() {
esc.attach(9); //ESC Pin
delay(100);
esc.writeMicroseconds(1500);
Serial.begin(9600);
mySerial.begin(9600);
delay(2000);
}
void loop() {
if(mySerial.available()){
Throttle = mySerial.read();
Throttle = map(Throttle, 1000, 2000, 2000, 1000);
esc.writeMicroseconds(Throttle);
}
delay(100);
}
voici l'application qui doit faire varier la vitesse du moteur :
A single byte can only send values from 0 to 255. You then go on to treat "Throttle" as a number from 1000 to 2000.
Does the Bluetooth app send a value from "1000" to "2000"? To read that you can use:
Throttle = mySerial.parseInt();
Thank you very much for your help, yes the app send a value between 1000 and 2000 but i can change to 0 -> 255 if its necessary.
how do I match 0 to 1000 and 255 to 2000? 1000 is the maximum reverse speed value and 2000 the maximum forward speed value. I tried to integrate your command line but without success
[image]
I would start by checking the bluetooth data:
#include<SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup() {
Serial.begin(9600);
delay(200);
Serial.println("Sketch started");
mySerial.begin(9600);
}
void loop() {
if(mySerial.available())
Serial.write(mySerial.read());
}
Upload this sketch and see what shows up on Serial Monitor when you end Bluetooth data.
I started checking that the arduino was indeed receiving the data and it is. here the arduino receives the correct value that I sent. The motor is then supposed to run at the speed corresponding to 1399 as if I simply did: esc.writeMicroseconds(1399);
The engine control is random and partially works with bluetooth. I think my code design is wrong.
What throttle values are you seeing if you print the throttle values to Serial?