Simple analog sample

02 Jun 2016

Hi,

First I would like to say that I am french so sorry if my english is not perfect. I am writing here because I have a problem with a simple analog sensor which is an accelerometer. I made a first test with Tera Term : if the p20 is free I read 0.0 and if I put 3V3 on p20 I read 1.0 so it is OK

Now I connect the Vin to the Mbed 3V3, the GND to Mbed ground and the Xout to Mbed p20. The zero-g tension on Xout is 1.65V and after calculation I have to read 0.5 thanks to AnalogIn function. I read data like 0.50 - 0.51 so I think it is OK ! :)

My goal is to see a shock on my accelerometer So my reasoning is : if I put an 'if' in my program, I will have a data if I have more than zero-g (I thought about an InteruptIn but it is only for digital data and my sensor is an analog one). That mean that if I give an acceleration to my sensor, the tension will be something like 1.75V and I will see on Tera Term a data like 0.53 - 0.54 !!

BUT : it doesn't work ! When I give an acceleration nothing happens on Tera term :(

I give you my program.

Thank you all, Drax75.

include the mbed library with this snippet

#include "mbed.h"
Serial pc(USBTX, USBRX);//On ouvre une liaison série

AnalogIn accelero(p20);//On affecte le nom "accelero" à l'entrée analogique p20

int main()
{
    pc.baud(9600);//La vitesse de communication avec Tera Term sera de 9600 bauds
    while(1) 
    {
        float valeurLue=accelero.read();
        /*On lit la tension d'entrée sur p20 qui est traduit ici par un chiffre entre 0.0 et 1.0
        sachant de 0.0 correspond à une tension d'entrée de 0V et 1.0 correspond à 3V3*/
        if (valeurLue>0.53) 
        {
            pc.printf("value is: %f  \n",valeurLue);//On affiche f qui est un float (d'où le %f)
        } 
    }
}