Can't read analog values from radio receiver channels

06 Jun 2014

Hey friends, this is Metin.

I'm trying to write a code that reads analog values from a receiver and directly writes them to the servos of the aircraft but I couldn't even read analog values. All I read(I'm debugging with Teraterm) is 0.000000.

Receiver output is between 2.3V and 4.6V. I'm using Seeduino Arch Pro. Receiver and board works properly. My code is down below. Please take a look.

Regards

#include "mbed.h"

int main()
{
    while(true)
    {
        Serial pc(USBTX, USBRX);
        AnalogIn aileron(P0_23);
        PwmOut aServo(P2_2);
        float temporary = 0.0;
        
        temporary = aileron.read();
        aServo.write(temporary);
        
        pc.printf("Aileron: ");
        pc.printf("%f\r\n", &temporary);
       
        wait(1);
    }
}
06 Jun 2014

You don't need both a question and a forum topic, and you closed your question (at least I can't answer there).

To your code. First there is a problem which doesn't prevent it from working, but also isn't supposed to be done. pc, aileron and aServo are created in the while loop. Since their scope is that loop, every iteration they are destroyed and recreated. At least put them one level higher, so at the beginning of main. But there is also little reason not to put them directly after the include mbed.h.

Isn't your code now giving a warning? You are not printing 'temporary', but you are printing the address of 'temporary', interpreted as float. (Btw you can do that printf also on one line).

Finally, the maximum allowed voltage on an AnalogIn pin is 3.3V.

10 Jun 2014

Hey Mr. Olieman,

Pardon my naiveness.

Thanks for your help.