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 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 :");

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 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, 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 :-
#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 :-
- 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 ( ) and can finally test all the combinations :-


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 and I've added some of the changes into the Raspberry Pi codes.

Do read an articl from Greg on RF24 performance enchantments at

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


Related Posts Plugin for WordPress, Blogger...