Using Analogread

ravinrabbid edited this page May 16, 2012 · 2 revisions
Clone this wiki locally

With Analogread you can measure the voltage on one of the port A pins on the Hexabus-Socket. (e.g. for reading out potentiometers, light sensors or similar devices)

1. Connect your device

Simply connect the output of your device to one of the pins on port A. Mind that the output voltage should be at most the supply voltage of the Atmega.

2. Configure Analogread

Set ANALOGREAD_ENABLE in firmware/contiki-2.x/platform/Hexabus-Socket/hexabus_config.h to 1.

Set ANALOGREAD_PIN to the pin you connect your device.

Set ANALOGREAD_MULT to a multiplicator you want to apply to the measured value. The ADC measures a value between 0 and 1023, where 0 is 0V and 1023 is the supply voltage. Which means if you want to have the value in volts and your supply voltage is 2.5V, set the multiplicator to 2.5/1024 = 0024414062.

3. Use it.

The value can now be accessed directly via EID 22 or broadcast periodically using the auto broadcast feature of value_broadcast.