Simple 1-hop Sensors Example

The following is an example of how to collect sensor data from the FireFly basic sensor board. For the most basic scenario, we suggest using the nano-RK/projects/demos/bmac_sensors project.

In order to program the FireFly nodes, you will need a FireFly programmer board with the specific version of avrdude that is designed to work with it. Installation instructions for avrdude can be found here. We provide pre-compiled binary images of the two FireFly programs you need on this page, so you are only required to install avrdude and not the entire tool-chain. You can install the entire tool-chain if you wish to modify or recompile the firmware.

In order to configure the nodes, the FireFly EEPROM_mac_set tools is required (nano-RK/tools/EEPRM_mac_set_tool). This tool generates a short sequence of bytes that need to be written to the EEPROM. The tool internally calls avrdude to set these values, so make sure that avrdude is available in the path. To compile, download and untar [attachment:EEPROM_mac_set.tar?format=raw EEPROM_mac_set.tar] and then type "make".

If this is the very first time the FireFly node is to being programmed (it has never been flashed with anything else) you might need to configure the fuses by running the following three commands:

avrdude -b115200 -F -p atmega1281 -P /dev/ttyUSB1  -c avr910 -V -U lfuse:w:0xEC:m -v
avrdude -b115200 -F -p atmega1281 -P /dev/ttyUSB1  -c avr910 -V -U hfuse:w:0xD1:m -v
avrdude -b115200 -F -p atmega1281 -P /dev/ttyUSB1  -c avr910 -V -U efuse:w:0xF7:m -v

1) Gateway Setup
  • Load the [attachment:gateway.hex?format=raw gateway.hex] firmware
    avrdude -b115200 -F -p atmega128 -P /dev/ttyUSB1  -c avr109 -V -U flash:w:gateway.hex
    
  • Set the MAC address to 00000000 and pick a channel (in this case 25)
    ./config-eeprom /dev/ttyUSB1 00000000 25
    
  • Gateway will display (25 will change depending on channel)
    Gateway Starting up...                                                         
    chan = 25
    
2) Client Setup
  • Load [attachment:client.hex?format=raw client.hex] firmware
    avrdude -b115200 -F -p atmega128 -P /dev/ttyUSB1  -c avr109 -V -U flash:w:client.hex
    
  • Set the MAC address, and channel
    ./config-eeprom /dev/ttyUSB1 0000YYYY 25 
    
    • Client nodes must have a unique and non-zero hex value in the "YYYY" field in the address
    • Client should print the following:
      Create done                                                                    
      rx_task PID=2                                                                   
      tx_task PID=3                                                                   
      MAC ADDR: 10                                                                    
      chan = 25                                                                       
      Sending=S MAC: 16 bat: 324 light: 963 temp: 614 audio: 35 adxl: 399 423 551     
      Sending=S MAC: 16 bat: 324 light: 969 temp: 614 audio: 665 adxl: 654 655 766    
      Sending=S MAC: 16 bat: 324 light: 976 temp: 614 audio: 670 adxl: 654 655 766    
      Sending=S MAC: 16 bat: 324 light: 968 temp: 614 audio: 668 adxl: 654 655 764
      

Example Output

Once multiple nodes are running, the gateway should print the following:

Gateway Starting up...                                                         
chan = 25                                                                       
S MAC: 16 bat: 310 light: 980 temp: 614 audio: 35 adxl: 391 425 536             
S MAC: 16 bat: 310 light: 983 temp: 614 audio: 652 adxl: 628 632 739            
S MAC: 16 bat: 310 light: 984 temp: 614 audio: 648 adxl: 628 632 739            
S MAC: 16 bat: 310 light: 985 temp: 614 audio: 647 adxl: 628 632 739            
S MAC: 2 bat: 310 light: 534 temp: 753 audio: 527 adxl: 743 519 756             
S MAC: 16 bat: 310 light: 985 temp: 614 audio: 646 adxl: 627 632 739            
S MAC: 2 bat: 310 light: 444 temp: 751 audio: 454 adxl: 730 407 735             
S MAC: 16 bat: 310 light: 984 temp: 614 audio: 646 adxl: 628 632 739            
S MAC: 2 bat: 310 light: 435 temp: 736 audio: 445 adxl: 728 399 729             
S MAC: 16 bat: 310 light: 979 temp: 614 audio: 647 adxl: 627 632 739 

The following C function will convert the temperature into Celsius:

 1float ff_basic_sensor_cal_get_temp (uint16_t adc_in)
 2{
 3  float t;
 4  float vo;
 5
 6  if (adc_in == 0)
 7    adc_in = 1;
 8  vo = ((float) adc_in / 1023.0) * 2.56;
 9  // 2.56 is fixed due to internal vref on atmega1281
10  t = 2196200.0 + (((1.8639 - vo) * 100000) / (.388));
11  t = -1481.96 + sqrt (t);
12  return t;
13}
14

client.hex - client.hex (85.9 kB) Anthony Rowe, 07/28/2010 09:32 pm

gateway.hex - gateway.hex (79 kB) Anthony Rowe, 07/28/2010 09:32 pm

EEPROM_mac_set.tar - EEPROM_mac_set.tar (10 kB) Anthony Rowe, 07/28/2010 09:38 pm