OSO Level

WiFi Refrigerator Scale

Drop Pressure Sensor Config

Posted by Justin Bernard on January 6, 2014

convert/create method of:

"sensor is rated 0-25lbs

voltage input is 0-5v

Analog input reads 0-5V as 0-1023

so we need to do 0 is 0oz, 1023 is 400oz"

Comments

Justin Bernard on January 6, 2014:

only question i have on this is you mention:
0-5V as 0-1023

so that mean syou always receive the value returned as 0-1023 instead of 0-5, right?

Taylor Bernard on January 6, 2014:

" 0 is 0oz, 1023 is 400oz"
yep

Justin Bernard on January 7, 2014:

all that needs to happen is something like this:

// CONVERT VOLT TO OZ

float instantVolt;
float instantOunce;
float instantPound;
float instantPercent;

int maxVolt = 1023;
int maxOunce = 400;

void convertVoltToOz() {
     instantVolt = ###_VALUE_FROM_SENSOR###;
     instantPercent = instantVolt / maxVolt;
     instantOunce = round( maxOunce * instantPercent );

      if ( instantOunce > 16 )
           return floor( instantOunce / 16 ) + 'lbs, ' + instantOunce % 16 + 'oz';
      } else {
           return instantOunce;
     }

}

Taylor Bernard on January 7, 2014:

ok, have you figured out how they are getting a data string to the agent? i think its either

agent.send

or

data.push


here's the most logical code ive seen so far:
but this is the one thats throwing an error on that data = [] line for some reason

//------------

//Setup hardware
sensor1 <- hardware.pin1;


sensor1.configure(ANALOG_IN);


function getValuesAndSendToXively() {
// read values from pins
local s1 = sensor1.read();


// make array of {key/value} objects to send to agent
data = [];
data.push( { key = "sensor1", value = s1 } );


// send to agent
agent.send("sendToXively", data);

// wakeup in 15 minutes, and do it again
imp.wakeup(120, getValuesAndSendToXively);
}

getValuesAndSendToXively();

Taylor Bernard on January 7, 2014:

look at this code:
http://forums.electricimp.com/discussion/comment/9566

why is his agent code so much more involved? looks like both do the same thing in theory, just send 1 ch of data back to the API?

Justin Bernard on January 7, 2014:

dont know.  im in elecimp interface right now so dont move anything, testing

Taylor Bernard on January 7, 2014:

Justin Bernard on January 7, 2014:

Taylor Bernard on January 7, 2014:

are you using this code of tempBug? this guy updated the code YESTERDAY due to a possible bug throwing an error:

https://github.com/electricimp/examples/tree/master/tempBug

http://www.instructables.com/id/TempBug-internet-connected-thermometer/step5/Setting-your-imp-firmware/

Justin Bernard on January 7, 2014:

thx testing with this now.

Taylor Bernard on January 7, 2014:

looks like i may need to use pin9 for analog voltage readings. he's using pin8 to toggle power.

Justin Bernard on January 7, 2014:

ok back working again lol.

moving forward i'll base stuff off that code base.  looking now into stripping stuff out so we can add our functionality into it...

Taylor Bernard on January 7, 2014:

the temp238xxxxxxxxxxxxx channel is from the serial number of the device. so its 'temp' channel + SN thus that weird string. just figured that out.