ATTiny84 + nRF24L01 network.update() freeze

Hello friends,

I’m trying to create an wireless multiple sensors node for my greenhouse using ATTiny84 and NRF24L01+. I’ve successfully fitted all the code in the tiny, but I’m unable to execute the basic rx/tx examples in the RF24Network library.

Both nodes are on a breadboard, powered with a 3.3V regulated, with a huge 4700uf electrolytic capacitor across + and -.

The connections of the nRF module are (all pin numbers are the actual ATTiny84 pins):
1 → GND
2 → 3.3V
3 → PIN 10
4 → PIN 11
5 → PIN 9
6 → PIN 8
7 → PIN 7
8 → Not connected

According to this image:

my CE pin is ATTiny’s 10, which is 3 in the IDE, and my CSN pin is ATTiny’s 11 or 2 in the IDE.

The running sketch is:

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(3,2);
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;
// How often to send 'hello world to the other unit
const unsigned long interval = 2000; //ms
// When did we last send?
unsigned long last_sent;
// How many have we sent already
unsigned long packets_sent;
// Structure of our payload
struct payload_t
{
  unsigned long ms;
  unsigned long counter;
};


#include <SendOnlySoftwareSerial.h>
SendOnlySoftwareSerial mySerial (10);
#define LED 1

void setup()
{
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  mySerial.begin(9600);
  mySerial.println("Preparing for sending!");
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
  mySerial.println("Ready for sending!");
  last_sent = 0;
}

void loop()
{
  mySerial.println("Entering loop...");
  network.update();
  unsigned long now = millis();
  if ( now - last_sent >= interval )
  {
    last_sent = now;
    mySerial.print("Sending...");
    payload_t payload = { millis(), packets_sent++ };
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if(ok) {
      mySerial.println("SENT OKAY!");
      digitalWrite(LED, HIGH);
      delay(100);
      digitalWrite(LED, LOW);
    } else {
      mySerial.println("ERRROR WHILE SENDING!!!!");
      digitalWrite(LED, HIGH);
      delay(1000);
      digitalWrite(LED, LOW);
    }
  }
}

On the serial monitor I can see only:

Preparing for sending!
Ready for sending!
Entering loop…

Now, I can say that network.update() is hanging up for some reason stopping the loop, but I couldn’t find why.

Thank you!

Hi sstoayanov

Different "cores" for the ATtiny can have different pin mappings.

Which core have you installed? Maybe one of these?

https://code.google.com/p/arduino-tiny/

Regards

Ray

Hello Hackscribble! I’ve used this core, which seems to be a clone of GitHub - damellis/attiny: ATtiny microcontroller support for the Arduino IDE.

I’ve used all available pins to wire the sensors, and the mapping seems to work fine, then when the wireless didn’t work I started to play with the bare wireless in order to exclude possible issues from the rest of the code.

Here is the pin mapping from pins_arduino.h

edit: while programming the chip, I used this board:

attiny84-8.name=ATtiny84 (internal 8 MHz clock)
attiny84-8.bootloader.low_fuses=0xe2
attiny84-8.bootloader.high_fuses=0xdf
attiny84-8.bootloader.extended_fuses=0xff
attiny84-8.upload.maximum_size=8192
attiny84-8.build.mcu=attiny84
attiny84-8.build.f_cpu=8000000L
attiny84-8.build.core=arduino:arduino
attiny84-8.build.variant=tiny14

tiny84-to-arduino-pin-mapping.png

Which version of the SPI library are you using? A special one for the ATtiny or the standard one in the Arduino IDE? The latter would be looking to use Arduino pins 10-13, I guess, which aren't in the ATtiny pin mapping.

I’m using this SPI library. What should I change in there if that is the issue?

edit:
it seems that this is the issue. Thank you Hackscribble! I see that in the SPI.h the pins defined are for the google’s core:

#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
// these depend on the core used (check pins_arduino.h)
// this is for jeelabs' one (based on google-code core)
# define DI 4 // PA6
# define DO 5 // PA5
# define USCK 6 // PA4
# define SS 3 // PA7
#endif

Are these the correct one for my core?

DI 6
DO 5
USCK 4
SS 7

I found this page about using that SPI library with RF24: Bits on a Board: RF24 with ATtiny84

It makes the point that the physical pins on the ATtiny which must be used are DO, DI and USCK. From the pinout diagram on that page, on the ATtiny84 these are ...

DI   PA6   physical 7
DO   PA5            8
USCK PA4            9

The pin mapping you posted has:

DI    physical 7 = Arduino 6
DO             8 =         5
USCK  	      9 =         4

So I agree that 6, 5, 4 look right.

SS is less critical, I believe. If you set the #define to 7, that will map to physical pin 6.

I've reprogrammed both chips, and now we have data flying around! There is some packet losses, but thats beyond the scope of this topic. Thank you very much for the help, buddy!

@sstoyanov : I have same problem, my attiny didn't send data with attiny.
Could you tell me what you have changed?

Thanks