nRF24L01+ Running on Maple

nRF24L01+ connected to Leaf Labs Maple Native

Last weekend, I got a Maple Native board from Leaf Labs. This is a somewhat-Arduino-compatible board running a STM Cortex-M3 processor with 512k flash and 1M of external RAM. I figure it will ease the wait for the Arduino Due.

So my first task is to port RF24, my Driver for nRF24L01(+) 2.4GHz Wireless Transceiver library. This library makes it easy to use dirt-cheap nRF24L01+ modules for radio communication.

It turns out the port was dead simple. So now Maple users can enjoy the benefits of $4 RF Radios.

The Hardware

In the picture above, I re-used the board introduced earlier in my Getting Started with nRF24L01+ on Arduino post. Happily, the pins are in the same order on the Arduino as the Maple, so the same board fits neatly onto the Maple Native, albeit oriented backwards. Then, wires are needed to connect VCC and GND over to the module. All of the other power (red & black) wires on the green board are extraneous on Maple.

The Example

Check out the specific example for Maple, pingpair_maple.

Put the same sketch on two units. On one of the boards, tie pin #10 to ground. On the other, leave it floating. This mechanism identifies one of the units as the sender, and the other as the receiver. Power them both up, and watch the debug spew tell the tale.

Now sending 90...ok...Got response 90, round-trip delay: 28
Now sending 1122...ok...Got response 1122, round-trip delay: 26
Now sending 2152...ok...Got response 2152, round-trip delay: 27
Now sending 3182...ok...Got response 3182, round-trip delay: 29
Now sending 4214...ok...Got response 4214, round-trip delay: 27
Now sending 5244...ok...Got response 5244, round-trip delay: 29
Now sending 6277...ok...Got response 6277, round-trip delay: 26
Now sending 7307...ok...Got response 7307, round-trip delay: 26
Now sending 8337...ok...Got response 8337, round-trip delay: 29
Now sending 9369...ok...Got response 9369, round-trip delay: 27
Now sending 10399...ok...Got response 10399, round-trip delay: 29
Now sending 11431...ok...Got response 11431, round-trip delay: 27
Now sending 12462...ok...Got response 12462, round-trip delay: 28

As I only have one Maple, I tested it using a Maple and one of my Wireless Sensor Nodes

The Changes

Mainly what was needed was to re-arrange the Arduino-specific header files into their own header, and add some compatibility glue.


#ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__
#if ARDUINO < 100
#include <WProgram.h>
#include <Arduino.h>
#include <stddef.h>
// Stuff that is normally provided by Arduino
#ifndef ARDUINO
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#define _BV(x) (1<<(x))
#define IF_SERIAL_DEBUG(x) ({x;})
#define IF_SERIAL_DEBUG(x)
// Avoid spurious warnings
#if ! defined( NATIVE ) && defined( ARDUINO )
#undef PROGMEM
#define PROGMEM __attribute__(( section("") ))
#undef PSTR
#define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); &__c[0];}))
// Progmem is Arduino-specific
#ifdef ARDUINO
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
typedef char const prog_char;
typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#endif // __RF24_CONFIG_H__

SPI Configiration

Needed to avoid setting SPI parameters in the Arduino fashion. Fortunately, the defaults for Maple HardwareSPI were correct for this radio, so no SPI configuration was needed whatsoever.

void RF24::csn(int mode)
#ifdef ARDUINO


The example needed a little tuning:

// Maple specific setup. Other than this section, the sketch is the same on Maple as on
// Arduino
#ifdef MAPLE_IDE
// External startup function
extern void board_start(const char* program_name);
// Use SPI #2.
HardwareSPI SPI(2);
#define board_startup printf
#define toggleLED(x) (x)


Filed under Maple, RF Radio

7 responses to “nRF24L01+ Running on Maple

  1. I’ve had no luck getting this to work with my Maple (ret6)
    These are the errors i’m getting with the standard example
    Any clues as to why this wont build? Using v0.0.12 of the Maple IDE.
    However it works excellently for my Arduino🙂 Thanks.

    • Well, it worked great when I posted that🙂 It wouldn’t surprise me if this atrophied, because I gave up on Maple not too long after. I will take a look though.

      • Thanks, I’ve been using Maple on and off, and recently got hold of some of these lovely nrf24l01+ and am trying to setup a mesh type network for some simple sensors. If i can’t use a maple its not the end of the world.😛

      • Interesting. Is there any particular reason for you giving up on Maple? If there are, could you please specify them? Also, do you suggest any particular platform, besides Arduino, for Wireless Sensor Networking with support to your RF24 and RF24Network libraries?

        Despite that, I’ve been researching about Wireless Sensor Networks (WSN) for a while (about a year) and one of the major drawbacks that affect most well-known platforms (like Micaz, Zolertia Z1, T-Mote Sky and etc) is the lack of resources, especially in terms of RAM and FLASH as you probably already know. Besides that, most of the aforementioned platforms use Texas Instrument’s MSP430, which by the way is inferior to ATMEGA 1284P. Both of these MCUs, however, when compared to ARM alternatives are much more expensive and less powerful.

        For instance, a STM32F103RBT6 on Aliexpress, also known as the Chinese ebay, costs about $3 dollars (10/lot) and provides a 32-bit Cortex M3 128K FLASH 20KB RAM. Of course there are more powerful STM32 MCUs, but this is a clear example of why I’m inclined to believe that Arm can do a great job by replacing Avr’s ATMEGA in the long run. Maybe not in Arduino itself, but for other platforms like Maple which want to leverage on the whole Wiring/Processing code available out there.

        Finally, I said all that because you already developed sensor nodes with Arduinos and you probably realised how Arduino’s ATMEGA hindered your implementations as well as I noticed that when using Contiki OS with WSN platforms that had MSP430 as their MCU. Obviously, nRF24L01 with your RF24 and RF24Network libraries are a must when price is important for a sensor network, but an Arm MCU can help even more to lower the final price while providing even better specs.

      • Support for the Maple was pretty limited. The core software didn’t make available much of the functionality of the chip. They seemed to be waiting for ‘community support’ to develop, which didn’t seem to be coming. Cool platform, though. I learned a lot about ARM with it.

  2. Aaron

    I keep getting this error
    C:\Users\A\Documents\MapleIDE\libraries\SPI\/SPI.h:16: fatal error: avr/pgmspace.h: No such file or directory
    Any Ideas? This is driving me crazy.

Leave a Reply

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

You are commenting using your 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