Commit d9c7df3a authored by TMRh20's avatar TMRh20

Add ATTiny example, change Minimal define

- Added ATTiny example per tong67, issue #17
- included print functions in #define MINIMAL per Damme, issue #16
- add #define RF24_TINY for simplification
parent 9da3eac0
...@@ -19,7 +19,7 @@ void RF24::csn(bool mode) ...@@ -19,7 +19,7 @@ void RF24::csn(bool mode)
// divider of 4 is the minimum we want. // divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz // CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO #ifdef ARDUINO
#if ( !defined( __AVR_ATtiny85__ ) && !defined( __AVR_ATtiny84__) && !defined (__arm__) ) || defined (CORE_TEENSY) #if ( !defined(RF24_TINY) && !defined (__arm__) ) || defined (CORE_TEENSY)
SPI.setBitOrder(MSBFIRST); SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0); SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2); SPI.setClockDivider(SPI_CLOCK_DIV2);
...@@ -270,7 +270,7 @@ uint8_t RF24::get_status(void) ...@@ -270,7 +270,7 @@ uint8_t RF24::get_status(void)
} }
/****************************************************************************/ /****************************************************************************/
#if !defined (MINIMAL)
void RF24::print_status(uint8_t status) void RF24::print_status(uint8_t status)
{ {
printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"), printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"),
...@@ -325,7 +325,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty) ...@@ -325,7 +325,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
printf_P(PSTR("\r\n")); printf_P(PSTR("\r\n"));
} }
#endif
/****************************************************************************/ /****************************************************************************/
RF24::RF24(uint8_t _cepin, uint8_t _cspin): RF24::RF24(uint8_t _cepin, uint8_t _cspin):
...@@ -1293,7 +1293,7 @@ void RF24::setRetries(uint8_t delay, uint8_t count) ...@@ -1293,7 +1293,7 @@ void RF24::setRetries(uint8_t delay, uint8_t count)
# define SS 3 // PA7 # define SS 3 // PA7
#endif #endif
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) #if defined(RF24_TINY)
void SPIClass::begin() { void SPIClass::begin() {
......
...@@ -28,7 +28,11 @@ ...@@ -28,7 +28,11 @@
// Define _BV for non-Arduino platforms and for Arduino DUE // Define _BV for non-Arduino platforms and for Arduino DUE
#if defined (ARDUINO) && !defined (__arm__) #if defined (ARDUINO) && !defined (__arm__)
#include <SPI.h> #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#define RF24_TINY
#else
#include <SPI.h>
#endif
#else #else
#include <stdint.h> #include <stdint.h>
...@@ -55,7 +59,7 @@ ...@@ -55,7 +59,7 @@
#define IF_SERIAL_DEBUG(x) ({x;}) #define IF_SERIAL_DEBUG(x) ({x;})
#else #else
#define IF_SERIAL_DEBUG(x) #define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__) #if defined(RF24_TINY)
#define printf_P(...) #define printf_P(...)
#endif #endif
#endif #endif
...@@ -101,7 +105,7 @@ ...@@ -101,7 +105,7 @@
// ATTiny support code is from https://github.com/jscrane/RF24 // ATTiny support code is from https://github.com/jscrane/RF24
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) #if defined(RF24_TINY)
#include <stdio.h> #include <stdio.h>
#include <Arduino.h> #include <Arduino.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
......
/*
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.
rf24ping85.ino by tong67 ( https://github.com/tong67 )
This is an example of how to use the RF24 class to communicate with ATtiny85 and other node.
Write this sketch to an ATtiny85. It will act like the 'transmit' mode of GettingStarted.ino
Write GettingStarted.ino sketch to UNO (or other board or RPi) and put the node in 'receiver' mode.
The ATtiny85 will transmit a counting number every second starting from 1.
The ATtiny85 uses the tiny-core by CodingBadly (https://code.google.com/p/arduino-tiny/)
When direct use of 3v3 does not work (UNO boards have bad 3v3 line) use 5v with LED (1.8V ~ 2.2V drop)
** 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);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment