Skip to content

Analog Values

Dario Di Maio edited this page May 24, 2015 · 3 revisions

Introduction

Analog values are always represented as floating points, in order to save RAM half-precision floating point (2 bytes) is used to store and send the value over the network.

The GCC math libs doesn't support half-precision floating point, so all math operation need single-precision (4 bytes) floating point.

Read a value from an analog pin

Read a value from an analog pin and store it directly into the node can be done through AnalogIn method, this read the analog input, convert and store it directly. The scaling and bias allow to convert the value as storedvalue = (readvalue * scaling) + bias.

void AnalogIn(U8 pin, U8 slot, float scaling, float bias)

Once you have stored this value, you need to process it using a relevant analog Typicals, like T51.

Import a single precision floating point

If you need to perform maths, read the analog value using analogRead() from Processing/Arduino and then import the value using

void ImportAnalog(U8 slot, float* analogvalue)

This applies also in case of data acquired via external libraries, like DHT and DA1820 sensors.

...
#define TEMPERATURE 0    // Analog values use two slot, in this case 0 and 1

...                      // Include DHT related code

float read_temperature = dht.readTemperature();
void ImportAnalog(TEMPERATURE, &read_temperature);

...

Send a analog value between nodes

Analog values shall be transferred as half-precision floating point, use RemoteInputs() to send the two output bytes directly into a T5n Typicals of a destination node.

Use

RemoteInputs(U16 addr, U8 firstslot, U8 *commands, U8 numberof)

An example

The following line of code send the analog value every time that is executed,

RemoteInputs(dst_addr, dst_slot, mOutput[src_slot], 2);
Clone this wiki locally