Author Topic: AnalogInput units  (Read 724 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: AnalogInput units
« on: March 21, 2017, 04:28:02 pm »
Maria,

I think you are mixing float and integer types, plus the voltage reference is 3600 not 3.3.

What I think you are looking for is:

Code: [Select]
value = (sensorReading\3600)*16384

or for 0-1024
Code: [Select]
value = (1023 * reading) \ 3600

where "value" is an integer type. Due to some odd math in McThings, division (/) always returns a float, so unless "value" was a float, you would get strange results. To do integer division, you use \ as shown above.

This will give you a reading from 0 to 16384 (0 to 3.6V), or 0-1024 if you use the second version. 3.6V is the maximum you can read. Note: this is not 3.3V or battery voltage, but is based on the internal 0.6V reference - so you can't change it, or use another number!

You also need to keep your units and data types consistent, sensorReading is in mV, and is a Short, 3.3 is in Volts and is a float. This combination is probably causing all the headaches.

Good luck with the project!
« Last Edit: March 21, 2017, 04:37:06 pm by Nick_W »