Hi All,
I am using the pulseIn() command to try and measure the length of a pulse from an RC receiver. These pulses are used to control servo motors on model helicopters and planes ect. I want to use my receiver to control the motions of a tracked robot with one joystick and a pan/tilt mechanism on board with the other.
I have an interesting problem here though. I am using a Spektrum DX6 transmitter and a AR6000 and BR6000 receivers. Now this kit does work with every servo that I have connected which is a fair few. This tells me that the pulses output are of correct length and voltage to control a servo motor. When I use the pulseIn() command however I get a zero reading every time.
I have tested the pulses as a switch alone using the digitalRead() command, which works, so the hardware is able to distinguish between the high and low states of the input pin (i.e. voltage is not apparently an issue).
To give a quick overview of teh physical arranegemnt, the recieveer is getting power from it's own 6VDC supply and the Arduino via the USB. The grounds of the two supplies are common, and the servo pulse is going to pin 12.
If I write my own pulse measuring command I obtain the times that are expected (see code).
int input = 12;
unsigned long x = 0;
unsigned long y = 0;
unsigned long delta;
void setup()
{
pinMode(input,INPUT);
Serial.begin(9600);
}
void loop()
{
while(digitalRead(input) == LOW)
{
if (digitalRead(input) == HIGH)
{
x = micros();
while (digitalRead(input) == HIGH)
{
digitalWrite(13,HIGH);
}
y = micros();
delta = y - x;
Serial.print("delta = ");
Serial.println(delta);
digitalWrite(13,LOW);
}
}
}
Now this is probaly not the most graceful method of doing this, but it provides an interesting result as it does work. So we wait until the pin is LOW, then wait for a change in state, grab the current time, wait for another state change, grab a second time, get the difference and display it.
The question that raises from this is why does this work, and not the pulseIn() command? Is it a voltage issue within the pulseIn() command?
I have some solutions in mind such as using a pull-up or down resistor to help define the pulse state or using a transistor to achieve the same (so pulse goes to base). I do not know the output voltage of the receiver which may well affect a transistor arrangement.
I would love to know why this command doesn't work at the moment, as solving it requires a bit of a "long way round" approach and isn't really necessary.
Thanks for your help in advance.
Cheers