Hi everyone , I'm currently working on a nano-based brushed motor drone project, but I have encountered a problem . In the vdieo below, I was trying to control my motors' rpm with my joystick . At the begining it seemed to be fine , but after a few second , all motors started acting on their own . the symptom is that they'll spin for a few sec , then stop for another while , then spin again......All three(there is one I haven't soldered onto circuit) motors were synchronous.
video : drone_test
Originally , I thought the cause is probably due to EMI , so I wrapped up my nrf24l01 and motor wires with aluminium foil . It does help , but very little . The followings are what I've done so far in order to reduce EMI:
1 . adding 0.01µF to each motor.
2 . wrapping nrf24l01 and motor wires with aluminium foil.
3 . placing positive and negitive motor wires as close as possible.
Some informations about the drone:
1 . MCU : nano
2 . Tx , Rx : nrf24l01(PA+LNA)
3 . motor : 180 motor
Is there any other factor that could cause the problem ? If it's really due to EMI , what should I do to further reduce the noise ?
Edit :
1 . Code I use:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int led_1 = 7;
int led_2 = 2;
struct Signal {
byte throttle;
byte pitch;
byte roll;
byte yaw;
};
Signal data;
const uint64_t pipeIn = 0xE9E8F0F0E1LL;
RF24 radio(8, 10); //(CE,CSN)
void ResetData(){
// Define the inicial value of each data input.
// The middle position for Potenciometers. (254/2=127)
data.throttle = 80; // Motor Stop
data.pitch = 127; // Center
data.roll = 127; // Center
data.yaw = 127; // Center
}
void setup(){
//Configure the NRF24 module
ResetData();
radio.begin();
radio.openReadingPipe(1,pipeIn);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_HIGH); //vary between RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, and RF24_PA_MAX.
radio.startListening(); //start the radio comunication for receiver
pinMode(led_1,OUTPUT); //pin 7
pinMode(led_2,OUTPUT); //pin 2 or pin 4
pinMode(3,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(led_1,HIGH);
while(!radio.available()){
delay(50);
}
while(radio.available()){
radio.read(&data, sizeof(Signal));
if(data.throttle>230)
break;
else
delay(50);
}
digitalWrite(led_2,HIGH);
}
unsigned long lastRecvTime = 0;
//declare date receiving function
void recvData(){
while (radio.available()) {
radio.read(&data, sizeof(Signal));
lastRecvTime = millis(); // receive the data
}
}
void loop(){
recvData();
unsigned long now = millis(); //millis() : return the millisec since arduino starts.
if ( now - lastRecvTime > 1000 ){ //Have not receive data for 1 sec.
ResetData(); // Signal lost.. Reset data
}
analogWrite(3,data.throttle);
analogWrite(5,data.throttle);
analogWrite(6,data.throttle);
analogWrite(9,data.throttle);
}
2 . Schematic:
(Sorry about the ugly wiring, I am a newbie)