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.
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:
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
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!