9 years, 4 months ago.

Passing analog values accross several kl25z boards.

Hi all

I'm having a problem (probably with my understanding) of using AnalogIn and AnalogOut on the KL25Z board - say I have two boards.

The first will write a single float value (range 0-1) from a sensor using

AnalogOut signal(PTE30); Only AnalogOut pin

main() Stuff signal = value; Set signal to be the found value

Then I'm trying to read this value into the second board using AnalogIn AnalogIn readvalue(PTB0); main()

led = readvalue; (basically to dim with change)

I'm using a wire straight from PTE30 on board A going to PTB0 on board B. I feel this should work as the reference voltages are the same?

It does not need to be exact but I cannot seem to get any information across the board. Also I am assuming that AnalogOut is a float between 0 and 1.

3 Answers

9 years, 4 months ago.

Are you using PWM out to drive the led?

AnalogOut pin will give you a value somewhere between 0 and 3.3v with a digital float value of 0 to 1 (digital float value of 0.5 should give you approximately 1.5v on the pin) you can measure this with a meter if you have one.

To drive the led on the other board you will need to use PWMout, that way it will go from no light to maximum brightness.

9 years, 4 months ago.

Did you connect the grounds between the boards? Did you verify you are writing the correct value to the AnalogOut?

Hi Erik/Paul thanks for the swift response.

I am using PWM to drive the led and no I haven't connected the grounds between the boards. They are both plugged into my desktop via USB so assumed they would share a common ground that way?

The code I am using to check what is being sent is

AnalogOut signal(PTE30);

//get value from sensor
if(value < 0.2)
        {
            send = 0.2f;
        }
        else if(value < 0.4)
        {
            send = 0.4f;
        }
        else if(value < 0.6)
        {
            send = 0.6f;
        }
        else if(value < 0.8)
        {
            send = 0.8f;
        }
        else //value between 0.8 & 1
        {
            send = 1;
        }
        signal = send;
        pc.printf("\n%f\n", send); 
        wait(0.3);

I'm printing send as printing 'value' doesn't work as it's not a float?

On the receiving end

AnalogIn    sentvalue(PTB0);

PwmOut led(LED_RED);
    float i = sentvalue;
        printf("\n%f\n", i);
        led = 1 - sentvalue; 

I've cut out a load of the fluff code around it, hopefully my problem is more with understanding AnalogIn/Out

posted by Lee Kent 07 Jan 2015

Regarding ground: Probably yes, but it can't hurt to connect them also directly.

Directly printing value can be done using value.read(), printf is the only situation where it doesn't work to just use 'value' (dunno exactly why, it is C++ related). At least I assume 'value' is an AnalogIn?

I see you sent the value to your PC, so the obvious question: What is it sending? Is that correct? And how about the other board? You also send the data their to your PC, which values do you get?

posted by Erik - 07 Jan 2015
9 years, 4 months ago.

Dear Lee-san,

Although I hope that previous answers have solved the problem, just in case let me add a couple of lines.

(1) I'm using GND from J2 for GND between boards. (refer to the last picture of my project below)

(2) If you have time/chance would you try "funcgen", which I have published recently for the signal generator to test? (since no one has downloaded it, yet (; ;) )

http://developer.mbed.org/users/Rhyme/code/funcgen/

Best Regards, 8-Jan-2015 moto