I have a remote with a RF transmitter, connected to an Arduino with a receiver, using the code below, and when the Arduino is connected to the ESC, the ESC doesn’t understand the signal it is receiving. The ESC does work since I can use my quadcopter controller with it, but it doesn’t work with the code I am using. I have attached the code below:
/* Analog Signal Receiver Receiving an Analog Signal over VirtualWire Developed by Michael Delaney */
#include <VirtualWire.h> #include <Servo.h>
const int transmit_pin = 12; const int receive_pin = 2; const int transmit_en_pin = 3; int ledPin = 13;
int potData;
Servo esc;
// RF Transmission container char potMsg[4];
void setup() { Serial.begin(9600);
// sets the digital pin as output
pinMode(ledPin, OUTPUT);
esc.attach(9);
//ESC.setMinimumPulse(800);
//ESC.setMaximumPulse(2000);
// VirtualWire
// Initialise the IO and ISR
// Required for DR3100
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true);
// Bits per sec
vw_setup(2000);
// Start the receiver PLL running
vw_rx_start();
} // END void setup
void loop(){ uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Non-blocking
if (vw_get_message(buf, &buflen))
{
int i;
// Turn on a light to show received good message
digitalWrite(13, true);
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
// Fill Sensor1CharMsg Char array with corresponding
// chars from buffer.
potMsg[i] = char(buf[i]);
}
// Null terminate the char array
// This needs to be done otherwise problems will occur
// when the incoming messages has less digits than the
// one before.
potMsg[buflen] = '\0';
// Convert Sensor1CharMsg Char array to integer
potData = atoi(potMsg);
potData=map(potData,0,1023,0,179);
esc.write(potData);
// DEBUG
Serial.print("Sensor 1: ");
Serial.println(potData);
// END DEBUG
// Turn off light to and await next message
digitalWrite(13, false);
}
}