nRF24L01+ with attiny841

Has anyone successfully used an nRF24L01+ 2.4ghz transiever with an Attiny841?

I am attempting to make a wireless node using those 2 main components on a board I made up. I cannot get them to work. I’ve made multiple boards and tried a few different RF24 transievers with no luck. My master board is not getting any reply.

I am using the SpenceKonde Attiny core - GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8

And the tmrh20 NRF24 library - http://tmrh20.github.io/RF24/index.html

My Master Code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 8

#define reedSwitchStatusBit (1 << 0)
#define batteryLowAlarmBit (1 << 1)

uint8_t masterAddress;
uint8_t nodeAddressIndex = 0;
const byte numberNodes = 2;
const byte nodeAddress[numberNodes][5] = {{'R','x','A','A','A'},
                                          {'R','x','A','A','B'}};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

bool newData = 0;
uint16_t nodeDataWord[20];
bool nodeCommStatus[20];    //0 = communication failure, 1 = ok

unsigned long currentMillis;
unsigned long prevMillis = 0;
unsigned long txIntervalMillis = 2000; // send once per second

void setup() {
  Serial.begin(9600);
  Serial.println("Home Security Wireless Master"); 
  Serial.println("Version 1, 04AUG18"); 
  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.enableAckPayload();
  radio.setRetries(3,5); // delay, count

  masterAddress = 255;
  Serial.println("setup complete"); 
}

void loop() {
  currentMillis = millis();
  if ((currentMillis - prevMillis) >= txIntervalMillis) 
    requestNodeUpdate();
}

void requestNodeUpdate() {
  Serial.print("Request for update from node ");
  Serial.println(nodeAddressIndex + 1);
  radio.openWritingPipe(nodeAddress[nodeAddressIndex]);
  uint16_t radioWrite;
  radioWrite = masterAddress;
  radioWrite |= ((uint16_t(nodeAddressIndex) + 1) << 8);
  nodeCommStatus[nodeAddressIndex] = radio.write(&radioWrite,sizeof(radioWrite));

  if (nodeCommStatus[nodeAddressIndex]) {
    if (radio.isAckPayloadAvailable()) {
      radio.read(&nodeDataWord[nodeAddressIndex], sizeof(nodeDataWord[nodeAddressIndex]));
      newData = 1;
    }
    else { 
      Serial.println("Reply From Node But No Data");
    }
  }
  else {
    Serial.println("No Reply From Node");
  }
  showData();
  nodeAddressIndex += 1;
  if ((nodeAddressIndex + 1) > numberNodes)
    nodeAddressIndex = 0;
  prevMillis = millis();  
}

void showData() {
  if (newData) {
    Serial.print("Reply From Node ");
    Serial.print((nodeAddressIndex + 1));
    Serial.print(", ");
    Serial.println(nodeDataWord[nodeAddressIndex]);
    newData = 0;
    }
}

My wireless node code

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 3        //attiny841 pin 6, PA7, digital pin 3
#define CSN_PIN 2      //attiny841 pin 5, PB2, digital pin 2

uint8_t reedSwitchInput = 7;        //Reed Switch Input, attiny841 pin 10, PA3, digital pin 7
uint8_t heartbeatOutput = 10;       //Heartbeat Output, attiny841 pin 13, PA0, digital pin 10

#define reedSwitchStatusBit (1 << 0)

const byte thisNodeAddress[5] = {'R','x','A','A','B'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

uint16_t nodeDataWord = 0;  

uint32_t previousMillis = 0;

void setup() {
//  Serial.begin(9600);
//  Serial.println("Home Security Wireless Node"); 
//  Serial.println("Attiny841, 8MHz, 3.3v");
//  Serial.println("Version 1, 04AUG2018"); 
  pinMode(reedSwitchInput, INPUT);
  pinMode(heartbeatOutput, OUTPUT);
  digitalWrite(heartbeatOutput, HIGH);
  
  radio.begin();
  radio.setDataRate( RF24_250KBPS );
  radio.openReadingPipe(1, thisNodeAddress);
  radio.enableAckPayload();
  radio.writeAckPayload(1,&nodeDataWord,sizeof(nodeDataWord)); // pre-load data
  radio.startListening();
  
//  Serial.println("setup complete"); 
}

void reedswitch() {
  bool reedSwitchState = digitalRead(reedSwitchInput);
  if (reedSwitchState)
    nodeDataWord |= reedSwitchStatusBit;
  else
    nodeDataWord &= ~reedSwitchStatusBit;

  radio.writeAckPayload(1,&nodeDataWord,sizeof(nodeDataWord)); // pre-load data  
} 

void updatePayload() {
  radio.writeAckPayload(1,&nodeDataWord,sizeof(nodeDataWord)); // pre-load data  
}

void heartbeat() {
  uint32_t currentMillis = millis();

  if ((currentMillis - previousMillis) >= 2000) {
    previousMillis = currentMillis;
    bool currentState = digitalRead(heartbeatOutput);
    if (currentState)
      digitalWrite(heartbeatOutput, LOW);
    else
      digitalWrite(heartbeatOutput, HIGH);
  }
} 

void getData() {
  if (radio.available()) {
    uint16_t radioRead; 
    radio.read(&radioRead,sizeof(radioRead));
  }
}

void loop() {
  reedswitch();  
  heartbeat();
  updatePayload();
  getData();
}

Pins to pins are as follows
nRF24L01+ - Attiny841
1 (GND)
2 (3.3v)
3 (CE) - Pin 6, PA7, Digital Pin 3
4 (CSN) - Pin 5, PB2, Digital Pin 2
5 (SCK) - Pin 9, PA4, Digital Pin 6, SCK
6 (MOSI) - Pin 7, PA6, Digital Pin 4, MOSI
7 (MISO) - Pin 8, PA5, Digital Pin 5, MISO
8 (IRQ) - Pin 3, PB1, Digital Pin 1, INT0

I thought it would be because of digital pin 3 being the default SS for the SPI, and I am using digital pin 2. I used wire jumpers and swapped them around but still no luck. I also tried changing what pin was defined as SS in pins_arduino.h (under tinymodern folder in the hardware directory). Changed it from 3 to 2. Still no luck.

Pictures of my board are attached.

Any help would be appreciated.

Other picture.

I used the same code for my wireless node on an arduino pro and pro mini board with good results, both on 5v 16mhz and 3.3v 8mhz. Just can’t figure out why it doesn’t work on the Attiny841. The 841 has hardware SPI support. I am not using a bootloader.

In the code I put in a heartbeat tied to one of the outputs so I can check that the code is at least executing and scanning through the loop.

I think you have the Attiny841 Pins mixed up. Assuming you are using the SOIC chip then Physical Pin 13 is MISO,12 is MOSI and 10 is SCK. And Physical Pin 11 is SS - which (I presume) must be used as and OUTPUT.

Check out the Attiny841 datasheet.

...R

Robin2: I think you have the Attiny841 Pins mixed up. Assuming you are using the SOIC chip then Physical Pin 13 is MISO,12 is MOSI and 10 is SCK. And Physical Pin 11 is SS - which (I presume) must be used as and OUTPUT.

Check out the Attiny841 datasheet.

...R

Those positions are actually the alternative positions for the SPI pins- the pins that the OP is using are the default ones. See page 159 of the datasheet (17.5.4 REMAP – Remap Port Pins).

BJHenry: Those positions are actually the alternative positions for the SPI pins- the pins that the OP is using are the default ones. See page 159 of the datasheet (17.5.4 REMAP – Remap Port Pins).

Thanks for that. I had not been aware that they can be remapped. There is no such thing as simple :)

...R

Image from Original Post so we don't have to download it. See this Simple Image Guide

And from Reply #1

...R

I’m not sure what the images are intended to show. A schematic would be a lot more informative,

I don’t see any sign of a 10µF capacitor across Vcc and GND for the nRF24, nor is it clear how the whole thing is being powered. A pair of AA alkaline cells (3v) should work fine.

…R

Attached is a schematic.

Located next to the attiny chip and the socket for the nRF24 are 0.1uF ceramic capacitors, and between them a 10uF Electrolytic Capacitor.

Boards are powered by a 1 cell lipo that feeds into a 3.3v buck-boost converter with an output current of 850mA. On the bench I am using a 3.3v power supply that can supply up to 3 amps.

drummin89: Attached is a schematic.

Please display your image(s) in your post so we can see it(them) without downloading it(them). I have already given you the link to the instructions.

I am wary of those voltage converters. I have not used one myself but IIRC there have been other Threads where people have had problems with nRF24s. Maybe their output has a ripple.

I use an nRF24 with a 1S Lipo and just use a diode to drop the voltage. I have done that with an Atmega 328 and an Attiny1634 but I have never used an Attiny841

...R

Thanks.

I will try powering the nRF24 from a different power source just to rule it out but on the bench I am using an adjustable power supply with the same failed results. I have other types of power supplies I can try but I’ve already tried a few so that is why I don’t think its power related.

I have other devices that use SPI that I might try hooked up to the attiny841 to see if that works. I just don’t know where to look. If its something with the Attiny core, nRF24 library, or my board (which is pretty basic).

I purchased an attiny841 dev board from Azzy's Electronics to test with the nRF24. To rule out issues with my board. Wondering if it could be because I am using the internal clock. My board doesn't use an external crystal or oscillator.

The attiny841 doesn't seem to be widely used. Not many google results, especially with the nRF24. Even though the 841 has hardware SPI, does the nRF24 library still have to specifically support the 841? I see there is code in the .h files for the attiny's that don't have hardware SPI.

What is RF24tiny?

Anyone aware of a small microcontroller board that is about the same size as the nrf24 that the nrf24 plugs into and has a few pins for io? In case my board tanks. I might still be able to use a attiny84 with my board.

Is there a particular reason that you need to use the Tiny841? The Tiny84 is similar (the pinout might even be the same- I can’t check right now but can do later tonight) and although it doesn’t have as many features as the Tiny841 it is specifically supported by the RF24 library.

If you think the library is the cause of your problem, why not try without it?

http://www.picaxeforum.co.uk/entry.php?2230-nrf24-Transmitter-(bis)

http://www.picaxeforum.co.uk/entry.php?2228-nrf24-Receiver-(bis)

You'll have to change the pin numbers.

Tested on Raspberry Pi, Picaxe 20X2, Arduino Pro Mini.

I use the internal 8MHz oscillator on all my Attiny1634s with nRF24s without any problems.

Can you build an Attiny841 that you can connect on a breadboard so you have some flexibility with the connections while you are experimenting?

...R

BJHenry: Is there a particular reason that you need to use the Tiny841?

I mainly picked the 841 because of the features it has. The hardware SPI and UART so I didn't have to use a software implementation. But I am not opposed to using the 84 if it works.

Is it possible to define which pin is MISO (DI) and MOSI (DO) when using USI? The pinout looks the same, but just in case those lines are crossed.

kayel: If you think the library is the cause of your problem, why not try without it?

Thanks!, I will try it without to see.

Robin2: Can you build an Attiny841 that you can connect on a breadboard so you have some flexibility with the connections while you are experimenting?...R

As far as I am aware the 841 is only available in SMD. There were a couple of attiny841 breakout boards on tindie but they are not active. Azzy's board is the only one that I could find, which is nice because it has on board power and headers for ISP and FTDI and the IO pins are breadboard friendly.

My datasheet says that the Attiny841 is available an SOIC format (same as the Attiny1634 that I use).

Using a double-sided sticky pad you can glue it upside-down to a piece of veroboard (stripboard) and solder wires from its legs to header pins in the veroboard and then you have a module you can plug into a breadboard.

This is my Attiny1634 attached to an nRF24 - with the PCB antenna sawed off the nRF24 and relaced with a short piece of wire. (Small size was the critical factor).

...R

never thought of doing it like that. The chips that I have are the SOIC.

did you have to do anything to get the nrf24 to work with the 1634? Was it already supported by the library?

I am leaning towards the 841 not being supported by the nrf24 library. I’ve been looking through the header files but a lot of that is way over my head. I can understand some of it. I see some areas where the attiny chips are mentioned. Not sure why it wouldn’t be supported since the 841 has hardware SPI support like the atmega chips. That’s what I understand anyways.

I have a couple attiny84 chips in DIP form that I think I am going to try setting up on a breadboard before I look at purchasing some in SOIC form to solder onto my wireless node boards. I hate to give up on the 841.

drummin89:
did you have to do anything to get the nrf24 to work with the 1634? Was it already supported by the library?

Now that you remind me, what I did was create my own .h files with SPI code and with nRF24 functions. I wrote the SPI code because the 1634 has a USI (Universal Serial Interface) rather than a specific SPI interface. I just took the code from the TMRh20 RF24.cpp source code. For some reason that I cannot now remember I have a comment at the top of my file to the effect that the code the same as for an Attiny84 except for the pinouts.

IIRC I wrote the nRF24 functions (also taken from the TMRh20 code) so I could be sure of only having the stuff I wanted. The TMRh20 code can be hard to figure out because it has Linux code and code for different Arduinos.

Attached are the 2 .h files.

You will also need the definitions that are in the TMRh20 file nRF24L01.h

…R

R2Attiny1634Spi.h (1.02 KB)

R2nRF24R2spi.h (3.57 KB)

So do you reference these directly in your sketch? Or did you make changes to the nrf library?

I just use those.h files in my program in place of the TMRh20 library.

But keep in mind that they are extracted from the library. For all I know the library would work fine.

...R