Hi all. I'm trying to get an R/C car working using two Arduino Pro-Minies + NRF24L01. I have done a bunch of tutorials on the NRF unit. I have a pair set up and have established communication between them with simple hello world and ping pong commands.
I have even got a limited version of Servo+ motor control going, but the code I was working with didn't include trim pots for the throttle and steering.
So I found an example for an R/C airplane but it used an XBee. I'm trying to change the code to work with the NRF module and am running into a problem. Can somebody please help me understand where I went wrong with this? Here is the TX code it is stalling with:
I tried to add comments to show where I made changes. The code I started out with can be found at the github link.
I know the code is for a model airplane. That's ok. I will keep it that way but only use the channels I need for the car. Throttle will be just that for car and Rudder will be steering.
no matching function for call to 'RF24::write(String&)'
// ArduinoRC-Tx.ino
// (c) Will Streuli 2015
// github.com/Streuli273
// modified for NRF24l01 by Jonathan jonawadl
//- WHAT IT DOES: Reads Analog values and transmits
//them over a nRF24L01 Radio Link to another transceiver.
//- SEE the comments after "//" on each line below - CONNECTIONS: nRF24L01 Modules See:
//http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
//1 - GND
//2 - VCC 3.3V !!! NOT 5V
//3 - CE to Arduino pin 9
//4 - CSN to Arduino pin 10
//5 - SCK to Arduino pin 13
//6 - MOSI to Arduino pin 11
//7 - MISO to Arduino pin 12
//8 - UNUSED
//-
//Analog inputs (Joysticks + Buttons)
//GND to Arduino GND
//VCC to Arduino +5V
//Throttle Pot to Arduino pin A0
//Rudder to Arduino pin A1
//Elevator pot to Arduino pin A2
//Ailron pot to Arduino pin A3
//Throttle trim Pot to Arduino pin A4
//Rudder trim pot to Arduino pin A5
//Elevator trim pot to Arduino pin A6
//Ailron trim pot to Arduino pin A7
//Rudder pot to Arduino
//elevdualrate switch to Arduino pin 2
//-----( Import needed libraries )-----/ Added for NRF24l01
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
//-----( Declare Constants and Pin Numbers )---/ Added for NRF24l01
// Radio Pins
#define CE_PIN 9
#define CSN_PIN 10
//TX pot pins
//#define throttleval A0; // I defined a bunch of pins, but it appears the way this code is written it has them defined in a way I'm not used to further down. I commented them out.
//#define throttletrimval A4;
//#define elevval A2;
//#define elevtrimval A6;
//#define aileronval A3;
//#define ailerontrimval A7;
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
// read values from analog sticks
int throttleval;
int elevval;
int rudderval;
int aileronval;
// read values from pots for trim
int throttletrimval;
int elevtrimval;
int ruddertrimval;
int ailerontrimval;
// values to send to plane, via NRF24l01
String sendthrottleval;
String sendelevval;
String sendrudderval;
String sendaileronval;
// dual rate values from pots
float elevdualrate;
float ailerondualrate;
boolean simulator = false;
//---( Declare objects )---/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
void setup() {
{
radio.begin(); //Starts NRF radio
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipe); } // Do I need more than one radio pipe for the different channels?
pinMode(13, OUTPUT);
pinMode(12, INPUT_PULLUP);
//digitalWrite(12, HIGH);
pinMode(11, INPUT_PULLUP);
//digitalWrite(11, HIGH);
pinMode(10, INPUT_PULLUP);
//digitalWrite(10, HIGH);
// check plugged into computer for simulator
if(digitalRead(12) == HIGH) {
simulator = false;
} else {
simulator = true;
digitalWrite(13, HIGH);
}
}
void loop() {
aileronDualRead();
//elevDualRead();
throttleRead();
elevRead();
aileronRead();
rudderRead();
sendData();
}
void throttleRead() {
throttleval = analogRead(A0);
throttleval = map(throttleval, 0, 1023, 0, 179);
throttletrimval = analogRead(A4);
throttletrimval = map(throttletrimval, 0, 1023, -25, 25);
throttleval += throttletrimval;
constrain(throttleval, 0, 179);
sendthrottleval = String(throttleval);
sendthrottleval += "a";
}
void elevRead() {
elevval = analogRead(A2);
elevval = map(elevval, 0, 1023, 0, 179);
elevtrimval = analogRead(A6);
elevtrimval = map(elevtrimval, 0, 1023, -25, 25);
elevval += elevtrimval;
//elevval *= elevdualrate;
constrain(elevval, 0, 179);
sendelevval = String(elevval);
sendelevval += "b";
}
void aileronRead() {
aileronval = analogRead(A3);
aileronval = map(aileronval, 0, 1023, 0, 179);
ailerontrimval = analogRead(A7);
ailerontrimval = map(ailerontrimval, 0, 1023, -25, 25);
aileronval += ailerontrimval;
aileronval *= ailerondualrate;
aileronval /= 100;
constrain(aileronval, 0, 179);
sendaileronval = String(aileronval);
sendaileronval += "d";
}
void rudderRead() {
rudderval = analogRead(A1);
rudderval = map(rudderval, 0, 1023, 0, 179);
ruddertrimval = analogRead(A5);
ruddertrimval = map(ruddertrimval, 0, 1023, -25, 25);
rudderval += ruddertrimval;
constrain(rudderval, 0, 179);
sendrudderval = String(rudderval);
sendrudderval += "c";
}
// for dual rates (factor of control surface movement)
void elevDualRead() {
if(digitalRead(12) == HIGH) {
elevdualrate = analogRead(3);
elevdualrate = map(elevdualrate, 0, 1023, 1, 100);
} else {
elevdualrate = 1;
}
}
// for dual rates (factor of control surface movement)
void aileronDualRead() {
if(digitalRead(11) == HIGH) {
ailerondualrate = analogRead(4);
ailerondualrate = map(ailerondualrate, 0, 1023, 1, 100);
} else {
ailerondualrate = 1;
}
}
// send data via Radio
void sendData() {
if(simulator == false){
radio.write(sendthrottleval);
radio.write(",");
radio.write(sendelevval);
radio.write(",");
radio.write(sendrudderval);
radio.write(",");
radio.write(sendaileronval);
radio.write(",");
delay(10);
}
}
void simulatorControl() {
// TODO Simulator control
}