I have created a basic receiver with an Nano board, a HC-05 module and a level shifter. For the 3.3 volts source, I am using the Nano board output, instead of a voltage regulator. The Nano is powered directly through the 5v pin from the ESC (stable voltage) I am using the PWM pins 5 and 6 for the controll of an ESC and a servomotor.
The main problem is that the motor have some kind of impulses when the there is no acceleration ( value set at the middle ( 0 - 180 range, the value sent to the esc is 90, continuosly). Bellow you can see the code.
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(3, 2); // RX | TX
int input_bluetooth[4];
int stare = 0;
int escValue;
Servo ESC;
Servo dirServo;
unsigned long escSetTime = 0;
void setup(){
Serial.begin(9600);
MyBlue.begin(9600);
Serial.println("Ready to connectnDefualt password is 1234 or 000");
escSetTime = millis();
ESC.attach(5);
dirServo.attach(6);
dirServo.write(90);
}
void loop(){
while (millis() - escSetTime <= 3500){
Serial.println("in set mode");
//do something
}
switch (stare){
case 0:
if (MyBlue.available() >= 4){
input_bluetooth[0] = MyBlue.read();
input_bluetooth[1] = MyBlue.read();
input_bluetooth[2] = MyBlue.read();
input_bluetooth[3] = MyBlue.read();
Serial.println("4 bits sent");
/*
Serial.print(input_bluetooth[0]);
Serial.print(" : ");
Serial.print(input_bluetooth[1]);
Serial.print(" : ");
Serial.print(input_bluetooth[2]);
Serial.print(" : ");
Serial.println(input_bluetooth[3]);
*/
stare = 0;
}
break;
case 1:
ESC.write(input_bluetooth[1]);
dirServo.write(input_bluetooth[2]);
Serial.print("ESC = ");
Serial.print(input_bluetooth[1]);
Serial.print(" dirServo= ");
Serial.println(input_bluetooth[2]);
stare = 0;
break;
}
}
As you can see I have a lot of "debugging code", trying to see if I have any weird data received, or the bits are received on other order. But not once this happened.
At the end I stopped sending any values, just receiving from the buffer, and discarding them. And that's when the magic happened. The motor behaved the same, even though the Nano was not sending any pulses through pins 5 or 6. And after I removed the data pin for the ESC, it stopped.
Now, am I missing something? Should I add some capacitors? I don't understant if there are some parasites signals or if it's something else.