Sunday, November 24, 2013

Stellaris Launchpad with nRF24L01+ communicating with Arduino UNO

Firstly I would like to thanks Premier Farnell (Element14) for sending me a sample Texas Instruments's Stellaris Launchpad. This development board platform from Texas Instruments is running on ARM Cortex-M4F based microcontrollers. The diagram below is directly taken from the datasheet showing all the pins, functions and other connectors.

Stellaris Launchpad
As I have lots and lots of female-female jumper cables, I kinda like the male headers on the Stellaris Launchpad. As this is not a review on the Stellaris Launchpad, I shall skip most of the features of the board and jump straight into the software needed to run this board.

Energia


Similar to Arduino, Stellaris have Energia, an open source multiple platform software development environment. You can refer to Stellaris LaunchPad Guide for all the pins and functions.

After installing the Energia development environment, it looks very similar like Arduino except it is red in colour like the Stellaris board.

So the first thing to do is to blink those three built-in RGB LED on the board itself and it looks very nice and useful to have RGB LED on the board itself. The second project that came into my mind is to get the Nordic nRF24L01+ radios working with this launchpad.

With some googling, I found the spirilis had written an Energia nRF24L01 library on the MSP430 (43oh.com) forum. There is also a github repo from spirilis that I downloaded and install the Enrf24 library similar to installing Arduino libraries. This is great, no steep learning curve.

nRF24L01 Stellaris Launchpad


While loading the Enrf24 Tx example, I notice it was written for MSP430 launchad pins instead of Stellaris launchpad pins, so the pin name needed to be changed to matched the Stellaris pin names.

The changes made as follows :-

// PE_1 = CE, PE_2 = CSN, PE_3 = IRQ
// SPI pins : SCK = PB_4 , MOSI = PB_7, MISO = PB_6
Enrf24 radio(PE_1, PE_2, PE_3); 

Refer to the StellaPad https://github.com/energia/Energia/wiki/Hardware#stellarpad-ek-lm4f120xl

Just blindly hook up the nRF24L01 to the Stellaris Launchpad according to the pinout above and you are all set.


While hooking up the 3.3V power to the nRF24L01+ radio ( that requires 3.3V ) I accidentally hook up the jumper cables to the VBUS pins as they are just next to each other. The VBUS is the USB power measured at 4.4V on my multimeter and the left pins besides it is the actual regulated 3.3V power pins. Luckily, the higher voltage did not blew up the nRF radio.

After this minor incident, I got the nRF24L01 working and transmitting a ON/OFF payload to whichever devices that is listening on those configured address.

As I have experience is getting different nRF libraries working with each other, the few possible places to look are the addressing schemes ( either 3 or 5 bytes ), CRC is either off / on (8bit/16bit), does it implement dynamic or static payload and matching all the speed and channels.

After much tweaking on the Arduino UNO side, I still could not get Arduino UNO side to receive the payload so I did what everyone else would do, read the codes and ask the author of this library.

Within less than a few hours, the author spirilis replied me and after changing the CRC settings, the Arduino UNO running the RF24 library is talking to the Stellaris Launchpad. The Tx demo is working and I tried the Rx demo and both works flawlessly. Below are the settings needed to get them working together...


Stellaris Launchpad transmitter side :-
const uint8_t txaddr[] = { 0xDE, 0xDE, 0xDE, 0xDE, 0xE3 };

void setup() {
....
  radio.begin(1000000);  // 1Mbps, max TX power
  radio.setChannel(88); // Channel 88
  radio.setCRC(1,1);    // Enable CRC, 16-bit
....
}

Arduino UNO receiver side :-

const uint64_t pipes[6] = { 0xDEDEDEDEE7LL, 0xDEDEDEDEE9LL, 0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL, 0xF0F0F0F0E4LL, 0xF0F0F0F0E5LL };

void setup() {
....
  radio.setDataRate(RF24_1MBPS);
  radio.setPALevel(RF24_PA_MAX);
  radio.setChannel(88);
  radio.enableDynamicPayloads();
  radio.setCRCLength(RF24_CRC_16);
....
}


Summary Links :-

Premier Farnell (Element14)
Stellaris Launchpad
Energia Development Environment
- Spirilis Energia nRF24L01 library
Forum link


Wednesday, August 14, 2013

Getting nRF24L01 working with attiny84

attiny84


After getting the attiny85 (8 pins) working with nRF24L01, I find that while this chip is nice and small, the lack of extra pins is a real hassle when I need to add any sensors/actuators to the MCU.

When I received my attiny84 ICs from Element14, now the fun begins...

attiny84 pinout

As usual, I hook up the attiny84 and test a blink sketch to ensure the attiny84 is working correctly. The first thing I encounter is that the blink is very slow, about 8 to 10 secs slower and I was wondering why. By the way, I'm using this Arduino tiny-core https://code.google.com/p/arduino-tiny/ as there are other tiny-cores available on the net with different settings.

After posting my problems on Arduino forum, I found out I need to do a Tools->Burn Bootloader to set the correct speed and fuses on the attiny84. After the "Burn Bootloader", the attiny84 was operating correctly at 8Mhz without an external crystal.

attiny84 
The above pictures are my test setup of the attiny84 on a breadboard with breadboard power supply running on 3.3V, nRF24L01 on an UNO adapter, USBtinyISP and logic analyzer and mini hooks.

The "fun" starts when trying to get the SPI pinout for attiny84 for running the nRF24L01. Since it uses the same tiny core was the attiny85 and I got the attiny85 working, it should not be too difficult, I guess.

After hooking up the attiny84 according to the above image and flashed the hex into the attiny84, I did not get correct settings on the four register I was monitoring on the serial/debug monitor. For troubleshooting, I have enabled "TinyDebugSerial" to read the four register, namely RF_CH, RF_SETUP, TX_ADDR and RX_ADDR.

I always needed to verify these settings and proper communications to the nRF24L01 as I used many different data rate, channel/frequencies and TX/RX address on all these nRF24L01 radios all the time.

  Mirf.readRegister(RF_CH, &rf_ch,sizeof(rf_ch));
  Mirf.readRegister(RF_SETUP, &rf_setup, sizeof(rf_setup));
  Mirf.readRegister(TX_ADDR, tx_addr, sizeof(tx_addr));
  Mirf.readRegister(RX_ADDR_P1, rx_addr, sizeof(rx_addr));

I also hook up a Logic Analyzer to the SPI pins to "see" what is going on during those SPI transfers. A proper SPI transfer would look something like below, with Enable/Slave Select (SS) pin held low during active SPI with Clock (SCK) supplying the clockrate for the MOSI/MISO.

SPI transfers

The issue seems to be SPI related as I do not get SPI patterns similar to the above, I immediately looked at SPI85 library that was downloaded from Arduino forum and it was working fine on the attiny85 on my earlier blog entry.

A bit about the SPI for the attiny, as the attiny does not have dedicated pins for SPI, it uses Universal Serial Interface (USI) for both SPI or I2C. See http://playground.arduino.cc/Code/USI-SPI for details on the USI-SPI on Arduino playground.

By viewing this link on Arduino Playground, it gives *hint* NOT to use the MOSI/MISO pins for attiny as they are ONLY used for In-Circuit Serial Programming (ICSP) only.

By looking at the SPI85.cpp codes, there are two lines that seems to differentiate between attiny85 and attiny84.

#if defined( __AVR_ATtiny85__ )
const static uint8_t SS   = PB4;
const static uint8_t MOSI = PB1;
const static uint8_t MISO = PB0;
const static uint8_t SCK  = PB2;
#endif

#if defined( __AVR_ATtiny84__ )
const static uint8_t SS   = PA7;
const static uint8_t MOSI = PA6;
const static uint8_t MISO = PA5;
const static uint8_t SCK  = PA4;
#endif


Here are some snapshot from the datasheets as like most of you, I only 
will read through the datasheet as a last resort as they are not written for 
normal people like myself. I always wonder if the author even understand what 
he himself wrote if he reads it a few years later.



attiny x4 pinout


attiny x4 pin alternate functions
From the above info/snapshots from the datasheet, I will have to assume that whoever 
wrote the SPI85 library was just following putting support for attiny84 without actually 
tested an attiny84 before as clearly it shows the pins was incorrect.

The pin PA5, while listed as MISO (for ICSP), was also USI-DO (data out) and PA6 while 
listed as MOSI (for ICSP), was also USI-DI (data in). As stated above in Arduino 
playground, for attiny, the MISO/MOSI is used only for ICSP and not for USI-SPI.

That was easy to solve, just swapped PA5 and PA6 and everything will work fine, 
right.. but it turns out that the PA5 and PA6 is logically mapped to value of 5 and 6 
and when the codes does an Arduino code of pinMode and digitalWrite, it execute 
the wrong pins for the attiny. A Digital pin5 mapped to PA5 and Digital pin6 mapped 
to PA4 (the pin used for the SCK/USCK).. no wonder the SPI display on the 
logic analyzer goes haywire..

Once, I traced the issue and figure out the problems, I just had to hard code the Arduino digital pins
to the AVR_ATtiny84 defines as below and changed the MOSI/MISO source of confusing to 
USI_DO and USI_DI :-

#if defined( __AVR_ATtiny84__ )
const static uint8_t SS   = 3;
const static uint8_t USI_DO = 5; 
const static uint8_t USI_DI = 4;
const static uint8_t SCK  = 6;
#endif

After that, I was able to see the correct settings on the Serial Debug or the SPI patterns on the 
logic analyzer. I do not know enough about how the tiny cores was written to put the 
proper attiny84 pin names but it was finally working.

If you figure out on how to fix the attiny84 pins, please let me know. The nRF24L01 library
was located at the summary links below.

There is an example of attiny84 codes in the Mirf library at github repo.

Summary Links :-

Mirf (nRF24L01) libs for UNO/attiny84/attiny85 :- https://github.com/stanleyseow/arduino-nrf24l01
Arduino tiny-cores :- https://code.google.com/p/arduino-tiny/







Friday, June 21, 2013

Electric Imp + Arduino + nRF24L01 = Fully Internet Wireless Solution

When we discovered the Electric Imp recently, we almost immediately ordered them directly from US to do research and coding on them. You can read more about the electric imp on their websites or view their videos on Makerfaire, in short, it is a awesome product. 

electric imp



What it does is to simplify the Internet connectivity of electronic projects and the ability to program your device or "things" over the Internet on a web based IDE is a really powerful concept made into reality.

Before the Imp, a few other options existed to have your device "Internet Enabled" and they are either too expensive or requires a lot of other stuff like router / firewall configuration, having a linux box in between like the Raspberry Pi version of Raspbian or plug in an Ethernet Shield on top of an Arduino. I've tried  them all out and could not find any other solution as simple as this.

Firstly, do not be confused by it SD card looking form factor, it is NOT a memory card but a powerful microcontroller plus wifi enabled radio all stuff into a tiny SD card otter shell. When it comes to connecting endpoints like smartphones and laptops to wifi, we are all aware of the trouble of choosing the correct access point and keying in the wifi password to gain access. 

How do you key in the access point name and wifi password to this small little SD card microcontroller ? The answer is light or blinking lights to transmit these wifi authentication information directly to the card itself. They have mobile apps for both iOS and Android platform. View this video demo on how it works.

With the Internet connectivity issue easily solved using an Electric Imp, my next questions is what if I want to connect more than one device ? Should I buy another electric imp and the Imp development board to house it or should I find an alternative (or more cost effective ) method to link up all my other devices/things in the house.

With my other projects all using nRF24L01 radio, the choice is quite obvious for a wireless solution, find a nRF24L01 driver for the electric imp platform. After a few google searches, I manage to find an initial driver for the electric imp on the forum  BUT it was totally not working and unfinished. This is what usually happens to open source and community projects, someone will write the codes when time and interests permits and abandon it when it is either not working or find something else more interesting project to do...

Since I have a little bit of experience forking the nRF24L01's RF24 library and making the RF24 drivers work for Arduino, Raspberry Pi and Atmel attiny85, I took up the challenge of writing the nRF24L01 driver for the electric imp at the same time learning a C like new object oriented programming language called Squirrel that was used on the Imp.

The nRF24L01 I wrote was a combination of RF24 codes with the Mirf codes as the Mirf codes was easier to understand and was originally written in C instead of C++ for the RF24. There were some issues on the SPI but with a help of a Logic Analyzer and Logic software, I was able to fix most of the SPI related issues   

The github repo for the Electric Imp nRf24L01 driver is at https://github.com/stanleyseow/electricimp-nRF24L01. You can comment out all the debug output when everything the radio is running ok.

block diagram

My next task is to find a useful application for my wireless solution, since I had a RGB LED strip and always like to make an Internet enabled RGB lighting, I hook up everything like the block diagram above. The web portion is a jquery colour picker from farbtastic with some touchscreen add-ons for touchscreen smartphone/tablets. Do viewsource to see the javacript codes at http://stanleyseow.asuscomm.com/color/.

colour picker

The Arduino portion is a simple code to read the three RGB codes from the colour picker webpage via nRF24L01 in #RRGGBB in hex and convert them to decimal ( 0 - 255 ) for analogWrite to the PWM pins. I'm driving the 12V RGB LED strip using a ULN2803 IC similar to this page on ambient lighting.

Arduino + nRF24L01 + RGB
The electric Imp part of the hardware is an April development board with the Impee SD card with SPI pins connected to the nRF24L01 radio. Since both the Imp and nRF24L01 runs on 3.3V, I do not need power regulator for this.

Impee + nRF24L01
Those red mini hooks are connected to my logic analyzer when I was troubleshooting the SPI issues I faced earlier. 

In summary, this seems like a complex setup but in actual fact after removing all the nRF24L01 library/drivers, the lines of codes is only the below :-

Imp Server Side :-
  1. ===============================================================================================
  2. Electric Imp agent side ( cloud / server side ) :-
  3. ===============================================================================================
  4.  
  5. http.onrequest(function(req, resp){
  6.     server.log("Got a HTTP request");
  7.     if (req.method == "POST"){
  8.         local body = http.urldecode(req.body)
  9.         server.log(body.data);
  10.         device.send("agentBuffers",body.data);
  11.         //device.on(recvfromImp,impBuffer);
  12.     }
  13.     resp.send(200"<head><meta http-equiv=\"refresh\" content=\"1;url=http://stanleyseow.asuscomm.com/color/\"><html>OK</html></head>");
  14. });


Imp device to send to nRF24L01 ( radio.send() ) :-
  1. ===============================================================================================
  2. Electric Imp device ( the white wifi SDcard in yr home ) :-
  3. ===============================================================================================
  4.   function watchdog2() {
  5.         agent.on("agentBuffers",function(value) {
  6.         server.log("Got a buffer from agent/http");
  7.            if ( value.len() < 33 ) {            // Make sure nRF24L01 payload is only 32bytes or less
  8.            radio.send(value,value.len());          // Send the payload to the radio
  9.            }
  10.         } );
  11.         radio.powerRX();
  12.         imp.wakeup(1, watchdog2 );    
  13.     }

Arduino portion after getting the #rrggbb from nRF24L01 :-

  1.         HEXtoRGB(); 
  2.         analogWrite(RED_PIN,r);
  3.         analogWrite(GREEN_PIN,g);
  4.         analogWrite(BLUE_PIN,b);


Summary Links :-
- Arduino RGB code http://pastebin.com/ZvtE1p9T



Sunday, June 9, 2013

Arduino Serial over nRF24L01

While browsing for nRF24L01 solutions, I came across this UART interface to nRF24L01 that work similar to Xbee, serial data into the module RX/TX and serial data out of the module at the other end.  Since those modules uses Atmel ATmega8 as the MCU, I had an idea to write the code for it from an Arduino IDE and make a few PCBs for it. Making it work like Xbee serial would be fantastic as the cost is only a fraction compared to Xbee. I always joked that the X in Xbee stands for eXpensive.

UART to nRF24L01

For me, the drive to spring into action is usually to solve a problem in hand and during the myduino.com 50% mega sale, I purchase a Skylab GPS module to mess around with GPS stuff. I've been messing with GPS since 2005 with my purchase of the handheld color Garmin GPSmap60C but these days, GPS is no big deal since any smartphone is usually equipped with one.

Skylab GPS module

After soldering jumper cables to the Skylab Vcc,Gnd, RX & TX pins as they were not the standard breadboard size of 0.1" (2.54mm), I loaded TinyGPS library from Arduiniana and was surprise on the sensitivity of this GPS module. Inside my room, I can receive very strong signals compared to my trusty Garmin GPSmap60C or my Holux M-241 (for geotagging) where I have to stand outside my balcony for 5-10 mins just to get a GPS lock.

I just hook up a 16x2 LCD to the Arduino UNO to display the location and the number of satellite and hdop value for accuracy of the location.

Since the GPS module runs on serial and spit out data continuously, I can use this as my "content" or raw data to feed to my UART to nRF24L01 module and another module just reverse it back to Serial into an Arduino or output to Serial Monitor for a GPS software to interpret them instead of using Arduino GPS library.

Another really important piece that got me started was this blog by JHaskell on Serial communications fundamentals on Arduino that explain about using start and stop delimiters to capture serial input into an array.

With this two pieces of info, I just need to figure out on how to split up the payload to fit the nRF24L01 max payload size and reassemble it back together at the receiving end. 

I initially started with using a $ for the start delimiter and a few other symbols at the end delimiters to denote 1st fragment, 2nd fragment and last fragments on the receiving side. Greg suggested that I use a one byte header to denote fragmentation, and rest of the bits as fragment sequences and the rest as payload. I finally decide to use 2 bytes headers with the 2nd byte reverse for future use and the first byte as follows :-

8 bit    - 1 - fragment, 0 - no fragment
5-7 bit - number of fragments  
4 bit    - unused
1-3 bit - fragment number

I've been reading TCP/IP headers packets for a long time and this is the first time I wrote my own simple protocol to fragment and assembly a wireless packet and even reverse 8 bits for future use...

Here are some pictures before I continue with the rest of the story..

Arduino UNO nRF24L01 GPS module

The first thing you might be wondering is why is there a FTDI USB-Serial breakout board  when the Arduino already have a built-in USB-Serial on pin 0 & 1. This issue started when I was receiving GPS data using Arduino SoftwareSerial library and while this library works with the TinyGPS mentioned above, it was starting to drop bytes ( serial overflow ) and some of the GPS data was lost before I can even sent them over the radio frequency.

Someone at Arduino forum suggested that I use the hardware serial to receive the GPS data and plug in the FTDI USB Serial for debugging purpose/serial monitor. I tried out his suggestions and all the dropped bytes went away immediately. Since the final product do not really need to connect to Serial Monitor, I might as well use the hardware serial instead of the slow SoftwareSerial library.

Arduino UNO nRF24L01
Above is a picture of the receiver, nothing special, just an nRF24L01 with an adapter that plug directly to the Arduino pins or to a breadboard with jumper wires flying all over the place... ( ignore the 16x2 LCD, it was permanently there for other projects )

I will not go though the programming codes on this post as they are still not fully optimize but I will post the links to them on pastebin.com. Below are the output from mini GPS software displaying all the satellite signals and my location had been masked to protect my identity.

Mini GPS
Someone on Google+ asked me about using this setup ( nRF24L01+ and GPS module) on a remote control boat and I just discovered that you can use this setup to measure the range of the radio, just mark the initial GPS coordinates and the furthest distance the radio + GPS module can reached and calculate the distance using both the GPS coordinates.

*** Special thanks to Greg for helping me out on ideas, suggestions and coding the serial and nRF24L01 stuff.


Summary Links :-
- My Serial to nRF24L01 code V4 http://pastebin.com/mmMxgdCx
- JHaskell's Arduino Serial communications fundamentals
- Arduiniana TinyGPS library

Monday, April 22, 2013

Added TinyDebugSerial to attiny85

One of the challenges of 8-pins attiny85 is that we do not have Serial Monitor debugging after flashing the hex into the IC. As per my previous blog, without debugging output, we cannot be sure what is happening when the attiny is up and running.

While browsing the arduino forum, I came across this site that wrote about several methods to have serial communications to the attiny. Since I only have CSN & CE pins free when the nRF24L01 is not transmitting, I decide to go with the TinyDebugSerial method of serial output. This method will use the attiny85 PB3 pin and transmit to the Serial-TTL receiver or an Arduino.

You can use a USB-Serial TTL module or an Arduino to receive the serial transmitted by the attiny and only use one pin on the attiny. Since I have an extra USB FTDI to Serial TTL breakout board, I will use this board and also power up the attiny and nRF24L01 using the on-board selectable 5V/3.3V regulator. Choose 3.3V jumper as the nRF24L01 can only take up to 3.8V only.

attiny/nRF24L01 with FTDI BoB
The above image is my prototype with 6-pin ICSP header on top of the attiny85 with connections to the nRF24L01 and TX to the RX of the FTDI. When I am programming the attiny85, I had to remove the nRF24L01 transceiver and Vcc jumper cable from the FTDI as my USBtinyISP is providing power to the attiny85 and prevent the nRF24L01 transceiver from interfering the attiny85 during flashing/programming the chip. Once the USBtinyISP programming is done, I can immediately "see" the output from the USB-FTDI on my console/serial monitor. 

attiny to USB-Serial TTL


The first step is to install the new tiny cores from https://code.google.com/p/arduino-tiny/ and compile the codes with the new cores to make it everything is working without the extra codes. Once everything is working fine, I added the following lines to my codes :-


#include <TinyDebugSerial.h>
TinyDebugSerial mySerial = TinyDebugSerial();

// Put this in setup()
  mySerial.begin( 9600 );

// Put this in loop()

  mySerial.print("Sent :");
  mySerial.println(buffer);


The rest of the code is at the github repo under libraries/mirf85/examples at the link below.

When I tried to compiled it, I got the following compilation errors due to using an older version of WinAVR on Windows or older avr-gcc on Mac OSX software on the Arduino IDE 1.0.1.

"R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in" 

Here are the links to the fixes and I will not rewrite it here... it have to do with an updated ld file for the avr.

Windows fixes :- Arduino Forum
Max OSX fixes :-  Arduino Forum

Once the above fixes is applied, I was able to see serial output on my USB-Serial on the serial monitor or any terminal program.

Summary Links :-
- Updated github repo
Serial Comms with attiny
Atmel AVR TinyISP
- Attiny cores https://code.google.com/p/arduino-tiny/ with TinyDebugSerial
Window fixes for R_AVR_13_PCREL
Mac OSX fixes for R_AVR_13_PCREL

Saturday, April 13, 2013

Process of getting attiny85 to work with nRF24L01 on RF24 libraries

While getting Arduino or Raspberry Pi to talk to nRF24L01 was fun and challenging, trying to make it work for a 8-pin attiny85 is a whole different experience... without serial monitor or printf debugging to the display, after the firmware was flash into the attiny85, you could only guess what is happenning or not happening when nothing was received on the nRF24L01 receiver side...

Initially, I just assume that since the Atmel attiny85 does not have hardware SPI, getting nRF24L01 talking to the attiny was not so possible... but after a few searches and reading up some blogs and forums, things seems to look brighter...

attiny85 pinout

The second challenge was the usable pins on the attiny85, with 8 pins and two used by power and ground, only six pins are available... and the nRF24L01 radios uses the usual SPI - MOSI, MISO, CLK plus another two pins for SS/CSN and CE leaving only the reset pin unused.

The third challenge was size of the firmware, unlike Arduino UNO using atmega328 with 32Kb of flash, the attiny85 only have 8Kb of flash, so optimizing the code was really important, and this is the largest flash size of the attiny x5 series. See this link for the attiny comparison chart.

With the help of Alex from Insidegadgets.com, I start from a scaled down mirf codes ( mirf was the initial libraries for nRF24L01 written in C for the AVR ) using notepad, WinAVR and avrdude to compile and flash the firmware into the attiny85. Then I was using a ported version to Arduino IDE that makes things much more easier as Arduino IDE can still support USBtinyISP, the programmer I was using to flash firmware into the attiny85.

After a few unsuccessful retries, I decide to use a different approach and found on Arduino forum that someone had modified the Arduino SPI and mirf into ther attiny85 version called SPI85 and mirf85. After matching all the channels, data rate and CRC, I manage to get some packets on Serial Monitor with a mirf library on the Arduino UNO.

Since all my libraries are using RF24 for both the Arduino & Raspberry Pi, having a mirf library isn't too much useful for me. I went through all the codes and default settings and managed to configure the mirf to be compatible with RF24 library.

attiny85 nRF24L01 USBtinyISP


Here are a summary of differences between both the mirf and RF24 library :-

Data rate :
mirf : 2Mbps as it uses the default registry setting of the nRF24L01
RF24 : configurable via setDataRate()

CRC length :
mirf : 8bit CRC length
To make it work for the RF24, change the following header files directly :-
mirf85.h
#define mirf_CONFIG ((1<<EN_CRC) | (1<<CRCO) )

RF24 : configurable via setCRCLength()

Node addressing :
mirf : serv1 or clie1 ( 5 bytes in ascii format )
To talk to RF24 receiver, use the following format,  :-

    byte RADDR[] = {0xe2, 0xf0, 0xf0, 0xf0, 0xf0};
    byte TADDR[] = {0xe3, 0xf0, 0xf0, 0xf0, 0xf0};


RF24: f0f0f0f0e2 format ( 5 bytes in hex format )

Optional settings :-

Enable Dynamic Payload :
I had my RF24 receiver with dynamic payload enabled so that I only need to set the payload size on transmitter only and can use different payload length instead of the max length.. set the below to mirf codes to enable dynamic payload.

mirf :
Mirf.configRegister( FEATURE, 1<<EN_DPL );
Mirf.configRegister( DYNPD, 1<<DPL_P0 | 1<<DPL_P1 | 1<<DPL_P2 | 1<<DPL_P3 | 1<<DPL_P4 | 1<<DPL_P5 );

I've compiled all the SPI85 and mirf85 files at github repo at the summary links below.

Summary Links :-

https://github.com/stanleyseow/arduino-nrf24l01
Insidegadgets.com
- Arduino forum




Saturday, April 6, 2013

Finally got all RPi & UNO combinations working for nRF24L01

I have finally setup my second Raspberry Pi with 512M memory, clone the github RF24 ( https://github.com/stanleyseow/RF24 ) and can finally test all the combinations :-

rpi-hub.cpp


sendto_hub.cpp
Possible combo :-

- Raspberry Pi as hub
- Arduino as node

- Raspberry Pi as hub
- Raspberry Pi as node

- Arduino as hub
- Arduino as node

- Aduino as hub
- Raspberry Pi as node




If anyone got the above codes tested on other platform like  Arduino Mega2560, Due or other platforms, please let me know the details and links so that I can update my summary links for others..

My latest github repo have combined forked from https://github.com/gcopeland/RF24/ and I've added some of the changes into the Raspberry Pi codes.

Do read an articl from Greg on RF24 performance enchantments at http://maniacalbits.blogspot.com/2013/04/rf24-avoiding-rx-pipe-0-for-enhanced.html



As usual, I've all summary links below :-

- Raspberry Pi as hub ( rpi-hub.cpp )
- Raspberry Pi as node ( sendto_hub.cpp )

- Arduino as hub nRF24_Arduino_as_hub
- Arduino as node nRF24_sendto_hub





Wednesday, March 6, 2013

Migrated RF24 codes to github

I've migrated my previous static codes to github's RF24 libs at https://github.com/stanleyseow/RF24
This is a fork from gnulnulf codes that uses dynamic rf24 RPi libraries...

This will be using the Arduino maniacbug's RF24 libraries in additional to the Raspberry Pi codes under a different folder...

Changes to take note from my initial instructions  :-

- CE is now using GPIO25
- CSN is now using GPIO8 (CE0)

Thanks to gnulnulf, you can specify the devices inside of the codes as below :-


RF24 radio("/dev/spidev0.0",8000000 , 25);

The files are located at RF24/librf24-rpi

Instructions on using github version for RPi :-

Using git, issue the following instructions :-

git clone https://github.com/gnulnulf/RF24.git
$ cd RF24
$ cd librf24-rpi/librf24
$ make                                <--- Compile the files
$ sudo make install             <--- This will install the librf24.so.1.0 into the shared libraries
$ sudo ldconfig -v | grep librf

     librf24.so.1 -> librf24.so.1.0

$ cd examples
$ make

To run the programs, type sudo ./rpi-hub or sudo ./scanner

*** You need sudo to access the spidev0.0 device
Instruction on Arduino :-

Got examples/RF24/rpi_hub_arduino

Compile and upload to the Arduino

Connect a small buzzer to digital Pin2

If everything is working, you should hear a short beep ...


Summary Links :-

https://github.com/stanleyseow/RF24 ( Arduino RF24 and RaspberryPi libs codes all in one )












Wednesday, February 27, 2013

Made a slot for NRF module directly onto Arduino digital pins


Once I ran out of jumper cables, I've made a slot to hold the nRF module that sits directly onto Arduino UNO digital pins.

I've change the CSN pin from pin7 to pin9 and swap the LCD pin9 to pin7. This is reflected in my latest codes below.


// Set up nRF24L01 radio on SPI pin for CE, CSN ( *** older codes uses Pin 7 instead )
RF24 radio(8,9);


LiquidCrystal lcd(10, 7, 3, 4, 5, 6);
// Make way for the SPI pins
// 10 -> LCD 4
// 7  -> LCD 6
// 3  -> LCD 11
// 4  -> LCD 12
// 5  -> LCD 13
// 6  -> LCD 14



Arduino with nRF slot directly to digital pins


I've re-wrote both the program on the Raspberry Pi and Arduino to make it more practical use. I've made the Raspberry Pi as the central hub to receive sensor data from Arduino nodes and returned back the same data to the sender for calculating the round-trip time (rtt).

You can download the updated codes at the summary links below.

I'm using all the pipes for each of the nodes, so if you want to use this codes, uncomment the pipes for different nodes to send payload to the Raspberry Pi using different node address.


// Radio pipe addresses for the 2 nodes to communicate. Uncomment for the active node
 const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
// const uint64_t pipes[2] = { 0xF0F0F0F0E2LL, 0xF0F0F0F0D2LL };
// const uint64_t pipes[2] = { 0xF0F0F0F0E3LL, 0xF0F0F0F0D2LL };
// const uint64_t pipes[2] = { 0xF0F0F0F0F1LL, 0xF0F0F0F0D2LL };
// const uint64_t pipes[2] = { 0xF0F0F0F0F2LL, 0xF0F0F0F0D2LL };
// Pipe0 is F0F0F0F0D2 ( same as reading pipe )


*** You can either connect a small buzzer or LED to pin2 for audio/visual acknowledgement the payload once it is returned and matched the outBuffer payload sent to the RPi.


Summary Links :-

- RF24 libs/codes on github:-  https://github.com/stanleyseow/RF24 ( all Arduino & Raspberry Pi codes are on github )




Tuesday, February 19, 2013

Setup Nordic nRF24L01 RF modules to both Arduino UNO and Raspberry Pi


In my process of building a Wireless Sensor Network, I obtained  a few low cost RF module from Inhaos that are compatible with Nordic Semiconductor nRF24L01. My plans are to have these low cost RF modules replaces the wires for my sensor network on Arduino and connect them to Raspberry Pi as the IP gateway to the rest of the Internet.

Raspberry Pi with nRF24L01-PA-LNA with BT module and USB Wifi


This entry will show you on how to setup both Arduino UNO & Raspberry Pi to connect to these nRF24L01 modules.

Some basic information on these low cost RF modules, they communicate using SPI to the microcontroller and works on raw speed of 250Kbps, 1Mbps and 2Mbps.

I'm using the following hardware & software:-


Raspberry Pi Model B running Adafruit's Occidentalis V0.2 ( http://learn.adafruit.com/adafruit-raspberry-pi-educational-linux-distro/occidentalis-v0-dot-2 ) that support SPI.

Nordic Semiconductor Datasheet / Product Info ( http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P )

RF modules used here :-
------------------

nRF24L01+ PA+LNA+2dBi ant

nRF24L01+ with PA & LNA and 2 dBi antenna ( http://www.elecfreaks.com/wiki/index.php?title=2.4G_Wireless_nRF24L01p_with_PA_and_LNA ), these are long range RF modules acting as hub on the Raspberry Pi.

Inhaos RF2400P


Inhaos RF2400P (with 5dBm RF power output) on BEKEN Chipset ( http://www.inhaos.com/product_info.php?products_id=35 ). They are compatible with the nRF24L01 but with higher output power of 5dBm.

nRF24L01+


Too many to choose from, just google for the above keyword on eBay or choose the cheapest as they sells in bulk of 10 pieces for a very low cost...

*** The main differences between the regular nRF24L01+ modules and the Inhaos RF2400P modules are that the RF2400P have a higher output power of 5dBm but could not do 250Kbps speed.

I'm running my setup using 1Mbps speed.

Setting up Arduino 

Connect using jumper wires from the above pin to the nRF24L01+ modules
Upload the sketches/program to the Arduino, download it here from Dropbox. 


Arduino UNO with nRF24L01+/PA/LNA/2dBi ant


Arduino connections to the nRF24L01 modules :-

Arduino Pin 11 to RF Module Pin 6 ( MOSI)
Arduino Pin 12 to RF Module Pin 7 ( MISO )
Arduino Pin 13 to RF Module Pin 5 ( SCK )
Arduino Pin 7 to RF Module Pin 4 ( CSN )
Arduino Pin 8 to RF Module Pin 3 ( CE )
Arduino 3.3V to RF Module Pin 2 ( VCC / 3.3V ) *** RF Module can only take 3.3V 
Arduino GND to RF Module Pin 1 ( GND )
RF Module Pin 8 (IRQ) is not connected

*** All the other pins are 5V tolerant

Optional LCD Module to display the received payload & payload length :-

I'm using Arduino Pin 7 & 8 for the SPI because my LCD module is using the following pins :-

Arduino Pin 9 - LCD Pin 4
Arduino Pin 10 - LCD Pin 6
Arduino Pin 3 - LCD Pin 11
Arduino Pin 4 - LCD Pin 12
Arduino Pin 5 - LCD Pin 13
Arduino Pin 6 - LCD Pin 14

Arduino Pin 2 - connect to buzzer ( for sound feedback when it received a valid packet )


Setting up Raspberry Pi

Upgrade your Raspberry Pi firmware to Adafruit Occidentalis V0.2 that support hardware SPI.

Download the above firmware and flash your SD card according to the instruction on Adafruit/Raspberry Pi website.

Refer to the two Raspberry Pi GPIO pinout and the physical pinout.

Raspberry Pi GPIO
GPIO with pin functions


RPi GPIO9    (Pin 21)  to RF Module Pin 7 ( MISO )
RPi GPIO10  (Pin 19)  to RF Module Pin 6 ( MOSI )
RPi GPIO 11 (Pin 23)  to RF Module Pin 5 ( SCK )
RPi GPIO8    (Pin 24)  to RF Module Pin 3 ( CE )
RPi GPIO 25 (Pin 22)  to RF Module Pin 4 ( CSN )
RPI 3.3V       (Pin 17)  to RF Module Pin 2 ( VCC/3.3V )
RPi Gnd        (Pin 25)  to RF Module Pin 1 (GND)



Instructions on using github version for RPi :-

Using git, issue the following instructions on Raspberry Pi command prompt :-

$ git clone https://github.com/stanleyseow/RF24.git
$ cd RF24
$ cd librf24-rpi/librf24
$ make                                <--- Compile the files
$ sudo make install              <--- This will install the librf24.so.1.0 into the shared libraries
$ sudo ldconfig -v | grep librf
     librf24.so.1 -> librf24.so.1.0

$ cd ../examples/
$ make

To run the programs, type 

$ sudo ./rpi-hub 
or 
$ sudo ./scanner

*** You need sudo/root to access the spidev0.0 device

Instruction on Arduino :-

Got examples/RF24/rpi_hub_arduino ( make sure the pins matches the above Arduino pinout )

Compile and upload to the Arduino

Optional :- Connect a small buzzer to digital Pin2 to hear a beep when the packet is returned to sender


If everything is working, you should see a screenshot below :-

rpi-hub screenshot


Summary Links :-

- Raspberry Pi firmware :- Adafruit Occidentalis-v0.2

- RF24 library (Arduino & RPi libs) on Github https://github.com/stanleyseow/RF24

Datasheets :-
- Nordic nRF24L01+ Datasheet :- nRF24L01+ DS

Forum :-
- Raspberry Pi Forum on nRF24L01 Click here
- Arduino Forum on maniacbug nRf24L01 driver Click here


LinkWithin

Related Posts Plugin for WordPress, Blogger...