nRF24 / RF24

OSI Layer 2 driver for nRF24L01 on Arduino & Raspberry Pi/Linux Devices
https://nrf24.github.io/RF24
GNU General Public License v2.0
2.21k stars 1.02k forks source link

Example for ATtiny85 with pin layout #17

Closed tong67 closed 9 years ago

tong67 commented 10 years ago

Hi, After some struggle I have managed to get a ATtiny85 to communicate with an UNO. The readme reports the ATtinyXX is supported and in the end this is definitely true! However, the examples do not have an example for ATtiny85 out of the box. Also the pin assignment and power issue with 3v3 line on arduino board almost made me quit (problems never come alone). To easy the use of ATtiny85 is an experiment I propose to add the example code I made. It is the gettingStarted.ino stripped to transmit mode only with some introduction text for the setup. Within IDE the text shows much better. Don't know (yet) how to show it in courier font.

rf24ping85.ino / This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. /

/*

// Hardware configuration: // ATtiny25/45/85 Pin map // +-\/-+ // Reset/Ain0 (D 5) PB5 1|o |8 Vcc (3v3 or -- LED -- 5v) // nRF24L01 CE, Pin3 - Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 - nRF24L01 SCK, pin5 // nRF24L01 CSN, Pin4 - Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 - nRF24L01 MOSI, pin7 // GND 4| |5 PB0 (D 0) pwm0 - nRF24L01 MISO, pin6 // CE and CSN are configurable

define CE_PIN 3

define CSN_PIN 4

include "RF24.h"

RF24 radio(CE_PIN, CSN_PIN);

byte addresses[][6] = {"1Node","2Node"}; unsigned long payload = 0;

void setup() { // Setup and configure rf radio radio.begin(); // Start up the radio radio.setAutoAck(1); // Ensure autoACK is enabled radio.setRetries(15,15); // Max delay between retries & number of retries radio.openWritingPipe(addresses[0]); // Write to device address '1Node' radio.openReadingPipe(1,addresses[1]); // Read on pipe 1 for device address '2Node' radio.startListening(); // Start listening }

void loop(void){ radio.stopListening(); // First, stop listening so we can talk. payload++; radio.write( &payload, sizeof(unsigned long) ); radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds boolean timeout = false; // Set up a variable to indicate if a response was received or not

while ( !radio.available() ){ // While nothing is received if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop timeout = true; break; }
}

if ( !timeout ){ // Describe the results unsigned long got_time; // Grab the response, compare, and send to debugging spew radio.read( &got_time, sizeof(unsigned long) ); }

// Try again 1s later delay(1000); }

TMRh20 commented 10 years ago

Nice, I think the library could definitely use an ATTiny example or two, and I will test it out asap, just FYI I may not have a chance for a few days.

TMRh20 commented 10 years ago

Example tested and added, please let me know if you find any problems with it.

tong67 commented 10 years ago

The comment part around the hardware configuration has been screw-up completely. It should show the pinning from nRF24l01 to ATtiny85. In the middle you see an ASCII representation of 8 pins IC. Snippet from sketch shown here: image

ortegafernando commented 10 years ago

Hi,

Could it be possible to change or improve your library for doing something like that ?

http://nerdralph.blogspot.com.es/2014/01/nrf24l01-control-with-3-attiny85-pins.html

Or may be with only 4 pins, but wiht 5 five, we only have free the reset pin of the Attiny85.

TMRh20 commented 10 years ago

Op2 - This is something that I've been looking at and discussing, but haven't had a chance to dig into it much more.

Tong67 - The example formatting should be fixed, and the documentation updated

Carminepz commented 10 years ago

Ciao, Funziona perfettamente con ATtiny84A attiny84a

tong67 commented 9 years ago

I have created a ATtiny85 setup where CSN and CE pin are not needed (see http://nerdralph.blogspot.ca/2014/01/nrf24l01-control-with-3-attiny85-pins.html). I updated RF24.cpp so that when csn == ce it will use special code based on special hardware configuration. The rf24ping85.ino contains ASCII schematic. Also added ATtiny84 schematic to the sketch. Added new sketch to be determine the settletime delays. Sketch is completely independent of RF24 but gives values that might be changed in RF24::csn() before burn prog to chip. Merged changes with latest master code. All three files are put in zip and available at https://anonfiles.com/file/934e29b4e6fb33cc0748022638fdd8c5 Can there changes be merged into the master code? (Don't know how to do it with git, therefore used the upload zip method, hope it is not to inconveniant).

lnxbil commented 9 years ago

I also struggeled with examples for use of ATTiny84 and ATTiny85. I would also like to provide some examples for ATTiny8X for simple usage. I would also like to see better documentation of how to get it to work. It took me a couple of hours to get a simple example up and running on a good channel. The interpretation of the scanner example was also not straight forward if you're not familiar with waterfall diagrams. Maybe a beginners guide to work with the library would be good to same some time to get started. I'm willing to write something or document what I have done with some Fritzing schematics for plug&play. Don't get me wrong, the API documentation and such is good, I only had a hard time to kickstart the whole thing and show and explain things like the ping program. (I'm still wondering why I always got RTT of over 1 second).

I stripped the GettingStarted-Example for 85 and 84 so that it only replies for easy setup. I was not able to get a working 84 example of the ping test.

It's great so see that this project is alive and vivid. Keep the good work up.

ortegafernando commented 9 years ago

tong67: Thanks a lot, your post is great news for me and for lots of people, I hope TMRh20 will have time to check and merge your proposal to the master code.

Thank you very much, tong67 and TMRh20

Best regards,

Carminepz commented 9 years ago

Errore connessione SSL
https://anonfiles.com/file/934e29b4e6fb33cc0748022638fdd8c5

ortegafernando commented 9 years ago

I have downloaded it perfectly.

TMRh20 commented 9 years ago

Nice work, and thanks for making these improvements! I think the changes will merge nicely into the master branch.

It is nice to have contributions done through github forks & pull requests, just to keep track of everybody who contributes, but I don't mind otherwise.

@lnxbil Feel free to contribute improvements or additional examples. I'll probably just make a new folder under examples for ATTiny sketches, etc. The main documentation can also be modified or pages added by editing the RF24.h file. It is generated with Doxygen. Any kind of contributions, whether youtube videos, blog posts, etc that explain how to do things can be added to the links or new pages as well. *edit to add: RTT over 1 millisecond is normal, RTT over 1 second seems really strange.

TMRh20 commented 9 years ago

I haven't fully tested them yet, but I've merged the changes into a new branch called Updates which can be downloaded here or viewed here

I created a new folder called rf24_ATTiny for any related examples. Once everybody is ok with the changes, and confirmed I didn't mess anything up, I can move it into the master branch.

@tong67 I assumed the timingsearch2pin.tst file was just for your testing, so I only included the .ino file. Please correct me if you intended them both to be included.

tong67 commented 9 years ago

I tested the Updates branch successfully. The .tst file was present by mistake, it was a previous saved version. When you commit the changes back into the master the issue can be closed from my point of view. Thanks for the cooperation.

TMRh20 commented 9 years ago

I've had good success with the 3-pin setup as well, and this all looks OK to me.

ortegafernando commented 9 years ago

Hi tong67,

I have been trying your ATTINY85 5 pins example but I'm getting strange responses in the Arduino UNO. I have try both 3.3V and 5V with LED power.

May be it is because my ATTINY85 is fused as 1 Mhz Internal Clock ? It has to be 8 Mhz ??

I don't know what is happening. I have check more than five times all the cables and pins,

Best regards,

ortegafernando commented 9 years ago

I have already try "blink basic" and it works fine, so IC and Arduino as ISP (it is what i use) is working perfect.

tong67 commented 9 years ago

I only tested it with 8Mhz setting. Did you use the same core: tiny-core by CodingBadly (https://code.google.com/p/arduino-tiny/)?

ortegafernando commented 9 years ago

[SOLVED] Excuse me and thank a lot. I'm embarrassed. After checking, putting 1Mhz, and so on, I realized that I have to check this in GettingStarted.ino: // Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 RF24 radio(9,10);

In my projects I always use pins 9 and 10, and the RF24 library's default is 7 & 8.

Excuse me.

It works perfect for 1Mhz and for 8Mhz Attiny85. Thanks a lot for all of you.

I will try then the 3 pin stuff.

NOTE: I will contribute soon about a example for getting a ackpayload from a low power sensor (my objetive is to control a relay with an Attiny85 (i will send to it relay state) and it will write an ackpayload (in order not to change between RX and TX) with an AnalogRead value. May be TMRh20 will include that example.

Best regards,