For my project, I have a Turnigy Reveiver connected to the analog in pins on my arduino mega. The receiver is paired with this transmitter. But the Arduino does not read any conprehensible data, staying at 0.00 for the mots time, but jumping up to, about 6.4 a few times a second. IS there something I am missing here?
Here is my code.
float pin0;
float pin1;
float pin2;
float pin3;
float pin4;
float pin5;
float pin6;
void setup() {
Serial.begin(9600);
}
void loop() {
pin0=digitalRead(0);
pin1=analogRead(1);
pin2=analogRead(2);
pin3=analogRead(3);
pin4=analogRead(4);
pin5=analogRead(5);
pin6=analogRead(6);
Serial.print("pin0: "); Serial.print(", "); Serial.println(pin0/100,3);
Serial.print("pin1: "); Serial.print(", "); Serial.print(pin1/100,3);
Serial.print("pin2: "); Serial.print(", "); Serial.print(pin2/100,3);
Serial.print("pin3: "); Serial.print(", "); Serial.print(pin3/100,3);
Serial.print("pin4: "); Serial.print(", "); Serial.print(pin4/100,3);
Serial.print("pin5: "); Serial.print(", "); Serial.print(pin5/100,3);
Serial.print("pin6: "); Serial.print(", "); Serial.println(pin6/100,3);
delay(100);
}
Thanks in advance!
pin0=digitalRead(0);
Do you want digitalRead or analogRead here?
Change to:
analogRead(A0);
analogRead(A1);
Etc.
Doesn't the output of that RC receiver usually go to servos? If so the signal is PPM, not analog. A servo expects a pulse every 20mS. The pulse will be between 1000uS (0 degrees) and 2000mS (180 degrees). Use the pulseIn() to read the pulse width. The 1000 and 2000 are nominal values, they acutally vary served to servo.
ok, I am using the PulseIn command. The function returns a value occelating between 2.7 and 2.8
show your new code.
Returns
the length of the pulse (in microseconds) or 0 if no pulse started before the timeout (unsigned long)
If you search for "arduino read servo pulse", there is a lot of info and libraries for reading multiple servos signals from RC receivers. Thank to the quad and RC drone guys, I guess.
wait no sorry thats not correct. The pulseIn command is changing from 14(neutral) to 19(positive) to 9(negative). Is there any way to read this data nicely, Or do I just have to make do with this?
Oh, alright! Thanks for the help, I will do that!
Which Arduino do you have??
Do you have a servo? If you do, connect one servo to the receiver. Get it so that you can control the servo from the transmitter. Disconnect the servo and connect the servo signal pin of the receiver, that was connected to the servo, to pin 5 of your Arduino (I have to assume a Uno without knowing for sure). Connect the ground from the receiver (any of the ground, black wire, pins)to Arduino ground.
The following code will read a servo signal from pin 5 (UNO) and output to the serial monitor the pulse width in microseconds. Warning, untested (the batteries are dead in my TX), but should work.
unsigned long chan1PW; // ch1 pulse width (microseconds)
unsigned long timer; // time acquisitions and prints
const byte chan1Pin = 5; // innput pin
void setup()
{
Serial.begin(9600);
Serial.println("measure swervo pulse width on ch1");
timer = millis();
}
void loop()
{
if(millis() - timer >= 500) // get and print every 500 mS)
{
timer = millis();
// read channel 1, HIGH pulse, if no pulse in 25mS abort return 0 else return UL width uS
chan1PW = pulseIn(chan1Pin, HIGH, 25000);
Serial.println(chan1PW);
}
}
If the servo worked you should get values between around 600 to around 2200 when you power up the receiver and transmitter and actuate the channel the servo was connected to. PulseIn() will return 0 if no pulse detected before timeout.