JeeNode setup

JeeNodes

As sensor node we are using the JeeNode SMD, developed at JeeLabs. This preassembled kit working on the ATmega328 chip and comes with a rfm12b wireless module. Upload of code to the chip is done with the USB BUB II, through micro-usb. Power is delivered by 3  1,5 v AA-batteries and through the USB BUB for the other node.

To measure temperatures we are using maxim integrated: DS18B20 (datasheet), which utilizes 1-Wire technology, allowing us to measuring multiple sensors through one port.

Setting up the JeeNodes

  1. First of, we are using the Arduino IDE for programming the ATmega328 chip, which uses a programming language similar too C++.
  2. To use the USB BUB II this VCP-driver has to be installed
  3. Adding Libraries: JeeLib – library for the JeeNode. OneWire – library and DallasTemperature – library for the temperature sensors.

Setup

For our first test setup, we used both our JeeNodes; the one with batteries as a transmitting node and the one without as the receiving end. We connected 4 temperature sensors at port 2 on the sending JeeNode and connected the other to the computer using USB BUB II.

setup1

The strength of the DS18B20 sensor is shown here, we are able to connect multiple sensors in a series connection and still be able to read independent values from each sensor, whether it is 1 or 10 sensors. In this setup we used the digital pin 5 for DQ and analog pin 1 for Vdd, we used a pin for power so that it would be possible to turn the sensors on and off, limiting the power consumption.

Code

The code used for this setup is heavily  inspired by this setup for the funky sensor project.

Receiver

#include <JeeLib.h>

#define myNodeID 28      // RF12 node ID in the range 1-30
#define network 210      // RF12 Network group
#define freq RF12_868MHZ // Frequency of RFM12B module

//########################################################################################################################
//Data Structure to be received
//########################################################################################################################

 typedef struct {
    int supplyV;	// Supply voltage
	int temp;	// Temperature reading
  	int temp2;	// Temperature 2 reading
  	int temp3;	// Temperature 3 reading
  	int temp4;	// Temperature 4 reading
 } Payload;

 Payload temptx;

 void setup(){
   Serial.begin(57600);
   Serial.print("Start");
   rf12_initialize(myNodeID,freq,network);
 }

 void loop(){
   if (rf12_recvDone() && rf12_crc == 0){
     int numSensors = rf12_len/2 - 1;
     const Payload* p = (const Payload*) rf12_data;
     Serial.println();
     Serial.print("Voltage: ");
     Serial.print(p->supplyV / 100.);
     if (numSensors>0) Serial.print(" Sensor1: ");
     if (numSensors>0) Serial.print(p->temp / 100.);
     if (numSensors>1) Serial.print(" Sensor2: ");
     if (numSensors>1) Serial.print(p->temp2 / 100.);
     if (numSensors>2) Serial.print(" Sensor3: ");
     if (numSensors>2) Serial.print(p->temp3 / 100.);
     if (numSensors>3) Serial.print(" Sensor4: ");
     if (numSensors>3) Serial.print(p->temp4 / 100.);
   }
 }

Sender

#include <JeeLib.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define TEMPERATURE_PRECISION 9
#define ONE_WIRE_BUS 5  // pad 5 of the Funky
#define tempPower A1    // Power pin is connected pad 4 on the Funky
#define minutes 5       // Duration of sleep between measurements, in minutes

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

ISR(WDT_vect) { Sleepy::watchdogEvent(); } // interrupt handler for JeeLabs Sleepy power saving

#define myNodeID 29      // RF12 node ID in the range 1-30
#define network 210      // RF12 Network group
#define freq RF12_868MHZ // Frequency of RFM12B module

//########################################################################################################################
//Data Structure to be sent, it is variable in size and we only send 2+n*2 bytes where n is the number of DS18B20 sensors attached
//########################################################################################################################

 typedef struct {
    int supplyV;	// Supply voltage
	int temp;	// Temperature reading
  	int temp2;	// Temperature 2 reading
  	int temp3;	// Temperature 3 reading
  	int temp4;	// Temperature 4 reading
 } Payload;

 Payload temptx;

 int numSensors;

//########################################################################################################################

void setup() {
  rf12_initialize(myNodeID,freq,network); // Initialize RFM12 with settings defined above
  rf12_control(0xC000);			  // Adjust low battery voltage to 2.2V
  rf12_sleep(0);                          // Put the RFM12 to sleep

  PRR = bit(PRTIM1); // only keep timer 0 going
  ADCSRA &= ~ bit(ADEN); // Disable the ADC
  bitSet (PRR, PRADC);   // Power down ADC
  bitClear (ACSR, ACIE); // Disable comparitor interrupts
  bitClear (ACSR, ACD);  // Power down analogue comparitor

  pinMode(tempPower, OUTPUT);     // set power pin for DS18B20 to output
  digitalWrite(tempPower, HIGH);  // turn sensor power on
  Sleepy::loseSomeTime(50);       // Allow 50ms for the sensor to be ready

  sensors.begin();
  numSensors=sensors.getDeviceCount();
}

void loop() {
  pinMode(tempPower, OUTPUT); // set power pin for DS18B20 to output
  digitalWrite(tempPower, HIGH); // turn DS18B20 sensor on
  Sleepy::loseSomeTime(10); // Allow 10ms for the sensor to be ready
  sensors.requestTemperatures(); // Send the command to get temperatures
  temptx.temp=(sensors.getTempCByIndex(0)*100); // read sensor 1
  if (numSensors>1) temptx.temp2=(sensors.getTempCByIndex(1)*100); // read second sensor.. you may have multiple and count them upon startup but I only need two
  if (numSensors>2) temptx.temp3=(sensors.getTempCByIndex(2)*100);
  if (numSensors>3) temptx.temp4=(sensors.getTempCByIndex(3)*100);
  digitalWrite(tempPower, LOW); // turn DS18B20 sensor off
  pinMode(tempPower, INPUT); // set power pin for DS18B20 to input before sleeping, saves power

  vccRead();

  rfwrite(); // Send data via RF

  for(byte j = 0; j < minutes; j++) {    // Sleep for 5 minutes
    Sleepy::loseSomeTime(60000); //JeeLabs power save function: enter low power mode for 60 seconds (valid range 16-65000 ms)
  }

}

//--------------------------------------------------------------------------------------------------
// Send payload data via RF
//--------------------------------------------------------------------------------------------------
 static void rfwrite(){
   rf12_sleep(-1);     //wake up RF module
   while (!rf12_canSend())
   rf12_recvDone();
   rf12_sendStart(0, &temptx, numSensors*2 + 2); // two bytes for the battery reading, then 2*numSensors for the number of DS18B20s attached to Funky
   rf12_sendWait(2);    //wait for RF to finish sending while in standby mode
   rf12_sleep(0);    //put RF module to sleep
}

//--------------------------------------------------------------------------------------------------
// Reads current voltage
//--------------------------------------------------------------------------------------------------
void vccRead(){
  bitClear(PRR, PRADC); // power up the ADC
  ADCSRA |= bit(ADEN); // enable the ADC
  Sleepy::loseSomeTime(10);
  temptx.supplyV = map(analogRead(6), 0, 1023, 0, 660);
  ADCSRA &= ~ bit(ADEN); // disable the ADC
  bitSet(PRR, PRADC); // power down the ADC
}

Test results

.
Voltage: 3.52 Sensor1: 21.62 Sensor2: 22.37 Sensor3: 21.62 Sensor4: 21.56
Voltage: 2.34 Sensor1: 21.18 Sensor2: 21.31 Sensor3: 21.31 Sensor4: 21.31
Voltage: 2.27 Sensor1: 21.00 Sensor2: 21.06 Sensor3: 21.12 Sensor4: 21.12
Voltage: 2.27 Sensor1: 20.87 Sensor2: 20.93 Sensor3: 21.00 Sensor4: 21.00
Voltage: 2.27 Sensor1: 20.75 Sensor2: 20.87 Sensor3: 20.87 Sensor4: 20.87
Voltage: 2.27 Sensor1: 20.68 Sensor2: 20.87 Sensor3: 20.81 Sensor4: 20.81
Voltage: 2.27 Sensor1: 20.62 Sensor2: 20.75 Sensor3: 20.75 Sensor4: 20.75
Voltage: 2.27 Sensor1: 20.50 Sensor2: 20.56 Sensor3: 20.68 Sensor4: 20.62
Voltage: 2.27 Sensor1: 20.43 Sensor2: 20.50 Sensor3: 20.56 Sensor4: 20.56
Voltage: 2.27 Sensor1: 20.37 Sensor2: 20.43 Sensor3: 20.50 Sensor4: 20.50
Voltage: 2.27 Sensor1: 20.31 Sensor2: 20.37 Sensor3: 20.37 Sensor4: 20.43
Voltage: 2.27 Sensor1: 20.18 Sensor2: 20.25 Sensor3: 20.37 Sensor4: 20.31
Voltage: 2.27 Sensor1: 20.18 Sensor2: 20.31 Sensor3: 20.31 Sensor4: 20.25
Voltage: 2.27 Sensor1: 20.18 Sensor2: 20.37 Sensor3: 20.31 Sensor4: 20.31
.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s