Force Sensor Project

12 Apr 2012

I've a basic project i'm working on in school to read some force sensors, and later i'll be using a wifly to send the readings to a database.

Problem is, I can't even get this mBed thing to read then print to terminal for testing. I had it working in about 15 seconds using my arduino, but mbed use is required. Its just different enough, I can't get it working. And this site is lacking in the basics of reading an analog pin and outputting data to terminal. I've spent my requisite 3 hours of head bashing and searching.

For the arduino:

int sensorValue = 0; //variable to store the sensor value in 

void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600); 
}

void loop() 
{
// read the analog in value:
sensorValue = analogRead(5); //reads pin 5 

Serial.print("sensor = " ); 
Serial.println(sensorValue); //print the number to the serial port 

delay(100); 
}

And as far as i could get with the mbed:

#include "mbed.h"
AnalogIn input(p15);
Serial pc (USBTX,USBRX);
DigitalOut myled(LED1);
float sensorvalue=0;

int main() {
   sensorvalue=input.read();
   printf("Sensor Value: ");
    printf(sensorvalue);
   printf("\n");
   wait_ms(100);
}   

Needless to say, it didn't work.

I'm fairly confident this should be easy, there's just a big disconnect. Probably the fact i'm a mechanical engineer. Any help would be greatly appreciated. Thank you for reading.

12 Apr 2012

Try changing your printf's to something like this:

<<code>> pc.printf("\n\rSensor Value: %f",sensorvalue); <</code>

Hope that helps.

Scott

13 Apr 2012

The mbed uses C printf statements, the following links have the formatting codes you need to use. Typicaly its printf( "text goes here, along with formatting %d", Variable);

%d, %f output variables as intergers and floating point numbers. \n is new line.

couple of references for printf;

http://www.cplusplus.com/reference/clibrary/cstdio/printf/

http://www.cppreference.com/wiki/io/c/printf_format