A howto to build an Avr node from the internal template

RF24Hub startpage: wilmsn.github.io/rf24hub

A minimalistic Node without attached Sensor

Node Schematic

Layout minimalistic node

Node configuration

Here are the configurations behind TESTNODE (file Node_settings.h)

#if defined(TESTNODE)
#define RF24NODE                      100
#define SLEEPTIME                     60
#define EMPTYLOOPS                    0
#define SENSOR_DUMMY
#define DUMMY_TEMP                    33.3
#endif

So we get a Node with id=100 that will send every 60 seconds a dummy value of "33.3" on channel "1"

Board settings

I use "Mini Core" as the board template. To install it look at "https://github.com/MCUdude/MiniCore" for details. Once the Mini Core is installed use this settings:

Arduino Settings

Important:

Compiling and uploading

If all the settings are done you can compile the sketch.

For transfering the compiled code onto the AVR microcontroler i use the USBASP Programmer. But there are lots of alternatives (eg. to use Arduino Uno as a programmer - google for it).

Build a node to your needs

If you want to build your own node there are two posibilities to do it:

  1. If all of the sensors you used are already implemented you can configure it easily.

  2. If you used a new, unimplemented sensor you have to implement it first.

Node configuration

~~~c++ //*************** // Individual settings //-----------------------------------------------------

if defined(MYFIRSTNODE)

define RF24NODE 200

endif

//----------------------------------------------------- ~~~

In this case we will add a temerature sensor 18b20

Here is the definition from Node_settings.ino:

~~~c++ // Dallas 18B20 Sensor

ifdef SENSOR_18B20

// Resolution for DS18B20 sensor

ifndef SENSOR18B20RESOLUTION

define SENSOR18B20RESOLUTION 9

endif

// Delaytime for 18B20 measurement

ifndef SENSOR18B20DELAYTIME

define SENSOR18B20DELAYTIME 100

endif

// Channel for temperature

ifndef TEMP18B20CHANNEL

define TEMP18B20CHANNEL 1

endif

endif

~~~

So the only thing we have to add to the node definition is:

~~~c++

define SENSOR_18B20

~~~

Now we have configured the 18b20 sensor which will send the temperature on channel 1,has a resolution of 9 (see datasheet) and has a conversation delay of 100ms (see datasheet)

The resulting node configuration is:

~~~c++ //*************** // Individual settings //-----------------------------------------------------

if defined(MYFIRSTNODE)

define RF24NODE 200

define SENSOR_18B20

endif

//----------------------------------------------------- ~~~

If you want to change the resulution or the delaytime just add the corespondending line from the configuratuin (#define ...) to your node configuration. This will overwrite the defaults!

Implementing a new sensor

In this step you should be able to programm in c++.

You will need a library that can handle your sensor!

Usually there are some steps that have to be programmed.

In the following lines i show the steps for the 18b20 sensor.

  1. Define a name for your sensor and get it running on Arduino board

The name will be SENSOR_18B20

  1. Goto Node.ino and include the library

~~~c++

if defined(SENSOR_18B20)

include

include

endif

~~~

  1. Define Initial treatment of the sensor at startup

Define variables and objects:

~~~c++

if defined(SENSOR_18B20)

OneWire oneWire(SENSOR18B20); DallasTemperature s18b20(&oneWire); DeviceAddress sensorAddress; float temp_18b20;

endif

~~~

~~~c++ void setup(void) {

if defined(SENSOR_18B20)

s18b20.begin(); s18b20.setWaitForConversion(false); for(byte i=0; i18b20.getDeviceCount(); i++) { if(s18b20.getAddress(sensorAddress, i)) { s18b20.setResolution(sensorAddress, SENSOR18B20_RESOLUTION); } }

endif

} ~~~

  1. Define cyclic actions

~~~c++ void get_sensordata(void) {

// Sensor Dallas 18B20

if defined(SENSOR_18B20)

s18b20.requestTemperatures(); // Send the command to get temperatures sleep4ms(SENSOR18B20DELAYTIME); delay(2); temp18b20=s_18b20.getTempCByIndex(0);

define DISPLAYTEMP temp18b20

if defined(DEBUGSERIALSENSOR)

Serial.print("Temp: ");
Serial.print(temp_18b20);

endif

endif

// ENDE: Sensor Dallas 18B20

} ~~~