PulseIn() not detecting pulse and timing out.

I am working on a quadcopter project for school and have run into an issue that seems to be a problem with the Arduino DUE and/or IDE because the code runs fine on an Arduino Uno and an Arduino Mega. I switched from these baords the the DUE so I can improve performance, taking advantage of the 32-bit processor and faster clock speed.

For my design, I am using the Flysky FS-T6 controller, which uses radio frequency to transmit a microsecond pulse between 1000 and 2000 to the receiver module which the Arduino board uses the pulseIn() function to read. I am powering the radio receiver using the boards 5v pin. Previously, I was using A0-A5 to connect to the 6 channel pins on the receiver, but I have also tried using pins 16-21 and have found the same results.

I have troubleshot the problem to the furthest of my abilities making sure the wiring is correct and that everything is functioning correctly and even had a second pair of eyes check my work. Using a multi-meter, I can confirm that the receiver is receiving 5v.

When I try to run my program, the serial monitor shows that the code is getting hung up whenever it tries to execute the pulseIn() function meaning the pulseIn() function is timing out like there is not a signal. I am providing just an example of code to show what the program is doing below. What this does is just stream a constant flow of zeros to the serial monitor, but still gets hung up every cycle during the timeout whereas if the program wasn't timing out, the serial monitor would be printing zeros much faster. The code belows shows A0 as thats the pin I have been using on all three boards, but I have tried other pins on the Arduino DUE as well.

int CH1;

void setup() {
  // put your setup code here, to run once:
Serial.begin(250000);
}

void loop() {
  // put your main code here, to run repeatedly:

CH1 = pulseIn(A0,HIGH);
Serial.println(CH1);

}

I don't have access to an oscilloscope so I decided to be intuitive and found that by maxing the serial monitor baud rate, and connecting the channel pins on the receiver to A0-A5, I was able to simulate a oscilloscope using the analogRead() function and returning the value straight to the serial monitor using the code shown below.

int CH1;

void setup() {
  // put your setup code here, to run once:
Serial.begin(250000);
}

void loop() {
  // put your main code here, to run repeatedly:

CH1 = AnalogRead(A0);
Serial.println(CH1);

}

What this did is return multiple instances of zero and then periodic bursts of six or seven instances of 1023 meaning the signal is at zero, then spikes to 3.3v, then returns to zero, cycling continuously. This response confirms that both the Arduino pins and the receiver modules are working correctly. The only thing I can think of is that there is some sort of problem with the Arduino DUE and the pulseIn() function.

I am continuing to research the issue, but I wanted to see if the community had any other ideas as to what is happening.

Look again at the documentation for pulseln() and see what data type it returns. Hint: not an int.

Paul

Sorry, didn't realize that would be an issue. In my actual program file I am using Float variables, and just used Int variables to describe my problem.

However, I just tried switching the variable to a float and then as a unsigned long, but the problem still persists. The serial monitor when using pulseIn() is printing zeros, while the serial monitor when using analogRead() still shows that the pulse is coming in just fine. I am also still seeing that the serial monitor is delaying before each print meaning the pulseIn() is timing out and not seeing a signal even though a 3.3v pulse of 1500us is reaching the pin. I looked into the logic threshold for the 3.3v boards and the Arduino website says the threshold is 2v meaning 3.3v should be more than enough to trigger the pulseIn() function.

Paul_KD7HB:
Look again at the documentation for pulseln() and see what data type it returns. Hint: not an int.

Paul

Sorry to hijack (sort of) but I have PulsIn working with INT. What is wrong with it? It does exactly what I want it to do. I used part of this tuto:

Read receiver with Arduino

int steerInputValue=pulseIn(SteerpinNumber, HIGH, 30000);

Please don't cross-post.

Sareno:
Sorry to hijack (sort of) but I have PulsIn working with INT. What is wrong with it? It does exactly what I want it to do. I used part of this tuto:

Read receiver with Arduino

int steerInputValue=pulseIn(SteerpinNumber, HIGH, 30000);

You are right, I was looking at the time-out time.

Paul

If anyone can try to replicate the issue using the Arduino DUE, please let me know. Still have not found any useful information about the problem I am having.

Try another digital! pin and set it to input (pinMode)

CH1 = pulseIn(YOURPIN,HIGH,30000);
Serial.println(CH1);

Note the 30000