Go Down

Topic: Brushless Motor malfunction caused by Bluetooth module (Read 604 times) previous topic - next topic

galaxyflo

When my HC-06 module attached to my Arduino Nano  is connected with another Bt device, my Brushless Motor (Samguk Wei) starts to jerk while running (work perfectly if I unplug it or cancel the Bt connection).
I checked the PWM outputs by monitoring them and also excluded the Bt radiation which I though t might has an impact on the wires by holding an Bt headset close to my construction. By having a closer look at it with an oszilluscope i realised that the interference make the impulse written by the ESC to the Motorr (see attachment) longer.

I don't have any more Ideas but I hope someone mor experienced might have on

Florian

Code: [Select]

#include <Servo.h>
#include <SoftwareSerial.h>


SoftwareSerial hc06(2,3);
int inbyte[4];
int incomming;
int outbyte = 0;
int index = 0;
double wanted_pitch = 0;
double wanted_roll = 0;
int throttle = 0;

Servo ESC1;
Servo ESC2;// create servo object to control a servo
// twelve servo objects can be created on most boards

int pos1 = 0;
int state = 0;
int pos2 = 0;// variable to store the servo position

void setup() {
  ESC1.attach(5, 1000 , 2000);
  ESC2.attach(6, 1000 , 2000);  // attaches the servo on pin 9 to the servo object

  hc06.begin(9600);
  Serial.begin(9600);
  ESC1.write(0);
  ESC2.write(0);
  delay(5000);
}

void loop() {
   if(hc06.available()){
    incomming = hc06.read();
    Serial.print("Reciving: ");
    Serial.print(incomming);
    if(incomming == 255){
      index = 0;
     
    /*  Serial.print("roll: ");
        Serial.print(inbyte[0]);
        Serial.print(" | pitch: ");
        Serial.print(inbyte[1]);
        Serial.print(" | throttle: ");
        Serial.print(inbyte[2]);
        Serial.print(" | rotation: ");
        Serial.print(inbyte[3]);
        Serial.print(" | real_throttle: ");
        Serial.print(throttle);
        Serial.print(" | real_roll: ");
        Serial.print(wanted_roll);
        Serial.print(" | real_pitch: ");
        Serial.print(wanted_pitch);
        Serial.println("|||");
     */
      wanted_roll = map(inbyte[0], 0, 120, -60, 60);
      wanted_pitch = map(inbyte[1], 0, 120, 60, -60);
      throttle = map(inbyte[2], 0, 120, 0, 180);
   
    }else {
      inbyte[index] = incomming;
      index ++;
    }
  }
   ESC1.write(throttle);
   ESC2.write(throttle);
 Serial.print("writing: ");
 Serial.println(throttle);
}


galaxyflo

Sorry attachment don't work because I my photo Formate isn't supported

Paul_KD7HB

Hardware problems are ALWAYS caused by software, don't you think?

Paul

jremington

Yes, it is the code. Post it, following the guidelines in "How to use this forum".

galaxyflo

I added the code, but even if I put an int (tested with 20) into the ESC.write() funktion it jerks if Bt is attached and stop jerking if Bt isn't attached.

jremington

#5
Sep 01, 2019, 05:04 pm Last Edit: Sep 01, 2019, 05:06 pm by jremington
This, with no check on array bounds, is guaranteed to trash memory and cause program malfunction.
Code: [Select]

int inbyte[4];
...
      inbyte[index] = incomming;
      index ++;

Go Up