Go Down

Topic: ATTiny84 + NRF24L01 Transcieve issue (Read 245 times) previous topic - next topic

Dean_Bean

Hey all, I'm currently working with an ATTiny84 being programmed by an Arduino Uno as isp.
I'm trying to get it to receive or send anything at all using an NRF module.

Currently trying to get the ATTiny84 to be a Receiver. The transmitter (which I've been using for a month in testing, so I know it works) is an ESP8266 with another NRF module.

The code for the ATTiny is this

Code: [Select]
//ATTiny
#include <nRF24L01.h>
#include <RF24.h>
#include <EEPROM.h>
#include <math.h>
//#include <SPI.h> //apparently rf24 calls this already

#define CE_PIN  2 //connected to physical pin 11
#define CSN_PIN 3 //connected to physical pin 10
RF24 radio(CE_PIN, CSN_PIN);

const byte generaladdress[5] = {1,'e','l','l','o'} ;

int led = 0 ;

byte datacommands[3] = {0,0,0};
byte ackData[3] = {2,0,0};







void setup() {
 

pinMode(led, OUTPUT);

  radio.begin();
  radio.setDataRate( RF24_250KBPS );


 digitalWrite(led, HIGH); //Just tell that the board has turned on
      delay(1000);
 digitalWrite(led, LOW);
    delay(1000);

  radio.openReadingPipe(1, generaladdress);
  radio.setPALevel(RF24_PA_MIN);
  radio.setAutoAck(true);
  radio.writeAckPayload(1, &ackData, sizeof(ackData));

  radio.startListening();
  radio.enableAckPayload();
  radio.enableDynamicAck();

ackData[0] = 1;

}

void loop() {
   if (radio.available()){
    radio.read( &datacommands, sizeof(datacommands)); 
      digitalWrite(led, HIGH); //to signal a message received
      delay(1000);
   
  } else {
    digitalWrite(led, LOW);
    delay(1000);
  }

}



Also the connections for the ATTiny are this




And the code for the ESP is this
Code: [Select]
//ESP
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>3
#define CE_PIN  2
#define CSN_PIN 15

RF24 radio(CE_PIN, CSN_PIN);
const byte generaladdress[5] = {1,'e','l','l','o'} ;

byte datacommands[3] = {4,1,1};
byte ackData[3] = {-1,-1,-1};

byte i = 0;

void setup() {

Serial.begin(9600);
  Serial.println("Proto test ESP starting");
  delay(10);
  radio.begin();
  radio.setDataRate( RF24_250KBPS );

radio.openWritingPipe(generaladdress);
  radio.stopListening();


  radio.enableAckPayload();
  radio.enableDynamicAck();


 
}

void loop() {
 
for(i=0;i<3;i++) {
  radio.write( &datacommands, sizeof(datacommands));
  printCommands();
  if ( radio.isAckPayloadAvailable() ) {
    radio.read(&ackData, sizeof(ackData));
   
    printAck();
   
    delay(1000);
  }
  delay(1000);
}
}



void printCommands() {
  Serial.print("Sending: ");
  Serial.print(datacommands[0]);
  Serial.print(" , ");
  Serial.print(datacommands[1]);
  Serial.print(" , ");
  Serial.print(datacommands[2]);
  Serial.print(" to: ");
 
  Serial.println();
}

void printAck() {
  Serial.print("Ackrecieved: ");
  Serial.print(ackData[0]);
  Serial.print(" , ");
  Serial.print(ackData[1]);
  Serial.print(" , ");
  Serial.print(ackData[2]);
  Serial.println();
}



Is there perhaps something I'm doing wrong? I have been testing various libraries and tutorials but none seem to work.

Imgur doesn't seem to work for adding the picture in preview mode so I attached the connections picture below

DrAzzy

#1
Apr 19, 2019, 07:20 pm Last Edit: Apr 19, 2019, 07:25 pm by DrAzzy
You need a 0.1uF ceramic cap between Vcc and Gnd on the tiny84 (you need this on almost all digital ICs, including all the AVR microcontrollers), as close to chip as possible (I'd put it over the top of the chip in this case). Without it, the part may not be stable (nearly-random hang/reset is possible).

Try doing some serial logging, either with the builtin software serial implementation (see https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/ATtiny_x4.md Serial section) or SoftwareSerial so you can see where it's hanging up.

Does the same code (with only pin number adjustments) work on the Uno? That's a good check to make sure that there isn't a problem hiding somewhere else.

ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Dean_Bean

You need a 0.1uF ceramic cap between Vcc and Gnd on the tiny84 (you need this on almost all digital ICs, including all the AVR microcontrollers), as close to chip as possible (I'd put it over the top of the chip in this case). Without it, the part may not be stable (nearly-random hang/reset is possible).
Oh really? I have never seen something like that needed for an AVR, thanks! Sadly I only have electrolytic at the moment so I'll need to find out if those will work.

Try doing some serial logging, either with the builtin software serial implementation (see https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/extras/ATtiny_x4.md Serial section) or SoftwareSerial so you can see where it's hanging up.
Yeah I hadn't gotten started trying to figure out how to do that yet so what I did before was just use a little LED as a workaround. It blinked like I wanted when it turned on but didn't blink when it should have been receiving a message.

I'm really not sure how to do the Serial for this tiny but I'll give it a go and see.


Does the same code (with only pin number adjustments) work on the Uno? That's a good check to make sure that there isn't a problem hiding somewhere else.

Yes absolutely. I tested it first with the arduino, switched to the tiny, went back to arduino and verified it was working only on that before I posted here.

Not sure if this helps but I can't seem to call isChipConnected(), it gives me an undeclared error. Perhaps thats a question for the nrf forum


Dean_Bean

Okay I've gotten a ceramic capacitor (0.1uf) and placed it over gnd and vcc but that has not solved the issue.

Go Up