I have been trying to home build a drone with an arduino based flight controller system and radio controller, i have calibrated my maker fire 20a escs and they work fine with a program that uses Serial.parseInt() to get an integer value and set throttle. Upon adding in lines of code that accommodate serial communication at 433mhz with 2 hc-12 modules the motors will speed up as i increase the throttle signal, but the motors will twitch and cause vibration especially at lower speeds. I also have the arduino controlling the motors printing what it receives over radio software serial and there seems to be no noise or incorrect values being transmitted/received.I have tried providing a separate 5v source for the hc-12 module with no change in result. The escs receive a separate 11.7 lipo voltage, and the flight controller runs on a 9v battery.
Probably in the code you didn't show.
Paul
See attached images for code, but heres the code anyway
Controller/Remote
#include <Adafruit_ST7735.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#define TFT_CS 10
#define TFT_RST 6
#define TFT_DC 5
#define TFT_SCLK 13
#define TFT_MOSI 11
Adafruit_ST7735 display = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
SoftwareSerial HC12(9, 8); // HC-12 TX Pin, HC-12 RX Pin
byte throttle=0;
int a2,a2old;
void setup() {
display.initR(INITR_BLACKTAB); //setting up more display stuff
display.fillRect(0,0,display.width(),display.height(),ST7735_RED);
display.setRotation(3);
display.setTextSize(2);
display.setTextColor(ST7735_BLACK);
display.setCursor(0,10);
display.print("SPEED:");
Serial.begin(9600); // Serial port to computer
HC12.begin(9600);
// Serial port to HC12
}
void loop() {
if(a2old+1<analogRead(2)||a2old-1<analogRead(2) && millis()%20==0)
{
display.setCursor(0,10);
display.fillRect(0,10,display.width(),50,ST7735_RED);
display.print("THROTTLE:"+String(throttle));
}
a2=analogRead(2);
if(a2<516)
{a2=516;}
throttle=((byte)((a2-516)/15));
HC12.write('&');
HC12.write(throttle);
Serial.println(throttle);
a2old=analogRead(2);
}
Flight controller
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial HC12(9, 8); // HC-12 TX Pin, HC-12 RX Pin
Servo e1;
Servo e2;
Servo e3;
Servo e4;
int throttle=0;
byte received;
void setup() {
Serial.begin(9600);
HC12.begin(9600);
HC12.setTimeout(10);
e1.attach(3);
e2.attach(4);
e3.attach(5);
e4.attach(6);
e1.write(90);
e2.write(90);
e3.write(90);
e4.write(90);
}
void loop() {
e1.write(90+(throttle*2));
e2.write(90+(throttle*2));
e3.write(90+(throttle*2));
e4.write(90+(throttle*2));
if(HC12.available()>2) {
received=HC12.read();
if(received=='&')
{
throttle =HC12.read();
Serial.println((2*throttle)+90);
}
}
}
#include <SoftwareSerial.h>
#include <Servo.h>
I recall much discussion about a conflict between these two.
Edit: try googling 'softwareserial and servo'. There is a fair bit of information out there.
SoftwareSerial is not friendly to other timing critical stuff as it disables interrupts for long times I believe.
That was it only hardware serial can be used if you want to use servos, at least on the Pro Mini.