FireFly Basic Sensor Driver


This document describes use of the FireFly Basic Sensor Driver that works with the FireFly Sensor Basic v1 add-on board shown above. For a running example please refer to the basic_sensor project. The FireFly Sensor Basic board senses the following properties:
  • Light
  • Temperature
  • Audio
  • Acceleration (3 axis)
  • Battery Level

Adding the Driver to a Project

When adding the sensor driver to a project make sure to do the following:
  • Update NRK_MAX_DRIVER_CNT in nrk_cfg.h
  • If the radio and voltage monitoring will be used, #define RADIO_PRIORITY_CEILING
    • This is required because checking the voltage of the battery requires communication with the cc2420 radio chip. This needs to be set to the max priority of a radio task which is usually 20
  • Add the driver source to the local makefile
    • SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/ff_basic_sensor.c
  • Register the driver before nrk_start() is called

    • 1  // Register the Basic [[FireFly]] Sensor device driver
      2  val=nrk_register_driver( &dev_manager_ff_sensors,FIREFLY_SENSOR_BASIC);
      3  if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to load my ADC driver\r\n") );
  • Make sure FIREFLY_SENSOR_BASIC is uniquely defined in /src/drivers/include/nrk_driver_list.h
  • Make sure to add the following includes to your source
    • #include <nrk_driver_list.h>
    • #include <nrk_driver.h>
    • #include <ff_basic_sensor.h>

Opening the Device

The following sample of code will open an instance of the driver. This will apply power to the sensors and wait for a few milli-seconds until they are ready.

1int8_t fd;
4      if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n"));

Selecting a Sensor

Using nrk_set_status( device, value, key) allows the application to configure which sensor value will be read by the nrk_read() command. device is the descriptor returned by nrk_open(). value is the command parameter you wish to set, in this case SENSOR_SELECT. key is the value of the sensor you wish to select and can take the following values:
  • TEMP
  • ACC_X
  • ACC_Y
  • ACC_Z
  • BAT

Upon error, nrk_set_status() returns NRK_ERROR with errno set to the following:

  • 0 Invalid Device
  • 1 Sensor Value out of range

Reading the Sensor Value

After a sensor has been selected, the value can be read using the nrk_read(device,uint8_t *buf, uint8_t size) function. device is the device file descriptor returned by nrk_open(). buf is a pointer to the memory where the driver will write the value. size is the max size of the buffer (in this case 1 byte). Below is an example of reading a sensor value:

1uint8_t buf;
4printf( "sensor value=%d",buf);

Closing the Device

Closing the device is important for saving on power. When the device is closed, the sensor powers down. Below is a sample of closing the sensor driver:


ff_2_2_sensor_sm.jpg - FireFly 2_2 with Sensor Board (68.4 kB) Anthony Rowe, 06/13/2007 04:08 pm