Bluetooth receiver behaves verry odd

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.

There is a timer conflict between SoftwareSerial and the Servo library. Most people solve that using ServoTimer2, or a different Arduino with two or more hardware serial ports.

Unfortunately, the ServoTimer2 did not solved the issue. Still, the servo and the ESC jitters random except when I remove the data pins.

Hi,
Do you have a DMM?

Can you please post a circuit diagram?
Just an image of a hand drawn schematic would be fine, please include component names, pin labels and power supplies.

Can you please post some images of your project, so we can see your component layout.

Tom.. :smiley: :+1: :coffee: :australia:

Yes, I do have a basic DMM, the circuit diagram bellow is powered throug a 3s li-Ion battery pack - ESC and the BEC outputs a stable 5V for the circuit.


So I've discovered that when disconecting the app from sending data to the receiver, the jitter stops, and when reconecting it, it starts again. That makes me believe the problem is in data receiving. But I've wrote a check to show me in the serial monitor only when values change from previous, and the jitter appears even if there is no different data received. So I'm out of ideas.
This is the new code.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.