Commit 435e4db8 authored by TMRh20's avatar TMRh20

Merge RPi and Arduino code

Merged code to simplify everything
- #31 Timing of stopListening() adjusted slightly to further prevent
blank ack-payloads if powering down while using ack-payloads or
switching between modes
parent 79eb4107
...@@ -60,3 +60,116 @@ CE and CSN are configurable. ...@@ -60,3 +60,116 @@ CE and CSN are configurable.
[1] http://highlowtech.org/?p=1695 [1] http://highlowtech.org/?p=1695
## Raspberry Pi Configuration:
Library functions are mostly the same.
See the included examples for RPi specific usage
## Raspberry Pi - PreConfig
### Possible pre-configuration:
If SPI is not already enabled, load it on boot:
sudo raspi-config
A. Update the tool via the menu as required
B. Select Advanced and enable the SPI kernel module
C. Update other software and libraries:
sudo apt-get update
sudo apt-get upgrade
# RPi - RF24 Quick-Start
A. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:
mkdir ~/rf24libs
cd ~/rf24libs
B. Clone the RF24 Repo
git clone https://github.com/tmrh20/RF24.git RF24
C. Copy the RPi library folder to the current directory, and delete the rest
cd RF24
D. Build the library, and run an example file:
sudo make install
cd examples
make
sudo ./gettingstarted
# RPi - RF24Network Quick-Start
A. Enter the same directory that contains the RF24 library folder
cd ~/rf24libs
B. Clone the RF24Network Repo
git clone https://github.com/tmrh20/RF24Network.git ntemp
C. Copy the RF24Network folder to the current directory, and delete the rest
mv ntemp/RPi/RF24Network ./
rm -r ntemp
cd RF24Network
D. Build the library
sudo make install
cd examples
make
sudo ./helloworld_rx OR sudo ./helloworld_tx
# Connection Info
Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN
Can use either RPi CE0 or CE1 pins for radio CSN.
Choose any RPi output pin for radio CE pin.
**Constructor:**
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS1, BCM2835_SPI_SPEED_8MHZ);
RPi B+:
RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_26, BCM2835_SPI_SPEED_8MHZ);
**Pins:**
| PIN | NRF24L01 | RPI | RPi -P1 Connector |
|-----|----------|------------|-------------------|
| 1 | GND | rpi-gnd | (25) |
| 2 | VCC | rpi-3v3 | (17) |
| 3 | CE | rpi-gpio22 | (15) |
| 4 | CSN | rpi-gpio8 | (24) |
| 5 | SCK | rpi-sckl | (23) |
| 6 | MOSI | rpi-mosi | (19) |
| 7 | MISO | rpi-miso | (21) |
| 8 | IRQ | - | - |
See http://www.airspayce.com/mikem/bcm2835/index.html for BCM2835 class documentation.
Note: The BCM library has been customized slightly to allow use of hardware CE pins not
in use for SPI, and to include a millis() function.
****************
Based on the arduino lib from J. Coliz <maniacbug@ymail.com>.
the library was berryfied by Purinda Gunasekara <purinda@gmail.com>.
then forked from github stanleyseow/RF24 to https://github.com/jscrane/RF24-rpi
Network lib also based on https://github.com/farconada/RF24Network
Currently optimized and aligned with Arduino fork of libraries by TMRh20:
https://github.com/tmrh20/RF24/RPi and https://github.com/tmrh20/RF24Network/RPi
Documentation: http://tmrh20.github.io
\ No newline at end of file
This diff is collapsed.
...@@ -16,9 +16,12 @@ ...@@ -16,9 +16,12 @@
#define __RF24_H__ #define __RF24_H__
#include <RF24_config.h> #include <RF24_config.h>
#if defined SOFTSPI #if defined (RF24_LINUX)
#include <DigitalIO.h> #include "bcm2835.h"
#elif defined SOFTSPI
#include <DigitalIO.h>
#endif #endif
/** /**
* Power Amplifier level. * Power Amplifier level.
* *
...@@ -54,14 +57,21 @@ private: ...@@ -54,14 +57,21 @@ private:
#endif #endif
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */ uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */ uint8_t csn_pin; /**< SPI Chip select */
#if defined (__linux)
uint16_t spi_speed; /**< SPI Bus Speed */
uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
#endif
bool p_variant; /* False for RF24L01 and true for RF24L01P */ bool p_variant; /* False for RF24L01 and true for RF24L01P */
uint8_t payload_size; /**< Fixed size of payloads */ uint8_t payload_size; /**< Fixed size of payloads */
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */ bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
uint8_t pipe0_reading_address[5]; /**< Last address set on pipe 0 for reading. */ uint8_t pipe0_reading_address[5]; /**< Last address set on pipe 0 for reading. */
uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */ uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */
uint32_t lastAvailableCheck; /**< Limits the amount of time between reading data, only when switching between modes */ uint32_t lastAvailableCheck; /**< Limits the amount of time between reading data, only when switching between modes */
boolean listeningStarted; /**< Var for delaying available() after start listening */ bool listeningStarted; /**< Var for delaying available() after start listening */
public: public:
...@@ -80,9 +90,12 @@ public: ...@@ -80,9 +90,12 @@ public:
* *
* @param _cepin The pin attached to Chip Enable on the RF module * @param _cepin The pin attached to Chip Enable on the RF module
* @param _cspin The pin attached to Chip Select * @param _cspin The pin attached to Chip Select
* @param spispeed For RPi, the SPI speed in MHZ ie: BCM2835_SPI_SPEED_8MHZ
*/ */
RF24(uint8_t _cepin, uint8_t _cspin); RF24(uint8_t _cepin, uint8_t _cspin);
//#if defined (RF24_LINUX)
RF24(uint8_t _cepin, uint8_t _cspin, uint32_t spispeed );
//#endif
/** /**
* Begin operation of the chip * Begin operation of the chip
* *
......
...@@ -12,6 +12,51 @@ ...@@ -12,6 +12,51 @@
#ifndef __RF24_CONFIG_H__ #ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__ #define __RF24_CONFIG_H__
/*** USER DEFINES: ***/
//#define FAILURE_HANDLING
//#define SERIAL_DEBUG
//#define MINIMAL
//#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART
//#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
/**********************/
#if defined (__linux) || defined (linux)
#define RF24_LINUX
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <stddef.h>
#include "bcm2835.h"
// GCC a Arduino Missing
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define _BV(x) (1<<(x))
#define pgm_read_word(p) (*(p))
#define pgm_read_byte(p) (*(p))
//typedef uint16_t prog_uint16_t;
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define PRIPSTR "%s"
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#if defined(RF24_TINY)
#define printf_P(...)
#endif
#endif
#else //Everything else
#if ARDUINO < 100 #if ARDUINO < 100
#include <WProgram.h> #include <WProgram.h>
#else #else
...@@ -19,15 +64,8 @@ ...@@ -19,15 +64,8 @@
#endif #endif
#include <stddef.h> #include <stddef.h>
/*** USER DEFINES: ***/
//#define FAILURE_HANDLING
//#define SERIAL_DEBUG
//#define MINIMAL
//#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART
//#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO
/**********************/
// 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__)
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
...@@ -120,6 +158,7 @@ ...@@ -120,6 +158,7 @@
#endif #endif
#endif //Defined Linux
// ATTiny support code is from https://github.com/jscrane/RF24 // ATTiny support code is from https://github.com/jscrane/RF24
......
This diff is collapsed.
This diff is collapsed.
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
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.
03/17/2013 : Charles-Henri Hallard (http://hallard.me)
Modified to use with Arduipi board http://hallard.me/arduipi
Modified to use the great bcm2835 library for I/O and SPI
*/
#ifndef __RF24_CONFIG_H__
#define __RF24_CONFIG_H__
/*** USER DEFINES: ***/
//#define FAILURE_HANDLING
//#define DEBUG
/**********************/
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <stddef.h>
#include "bcm2835.h"
// GCC a Arduino Missing
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define _BV(x) (1<<(x))
#define pgm_read_word(p) (*(p))
#define pgm_read_byte(p) (*(p))
#endif // __RF24_CONFIG_H__
// vim:ai:cin:sts=2 sw=2 ft=cpp
/*
Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
Portions Copyright (C) 2011 Greg Copeland
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/* Memory Map */
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
#define DYNPD 0x1C
#define FEATURE 0x1D
/* Bit Mnemonics */
#define MASK_RX_DR 6
#define MASK_TX_DS 5
#define MASK_MAX_RT 4
#define EN_CRC 3
#define CRCO 2
#define PWR_UP 1
#define PRIM_RX 0
#define ENAA_P5 5
#define ENAA_P4 4
#define ENAA_P3 3
#define ENAA_P2 2
#define ENAA_P1 1
#define ENAA_P0 0
#define ERX_P5 5
#define ERX_P4 4
#define ERX_P3 3
#define ERX_P2 2
#define ERX_P1 1
#define ERX_P0 0
#define AW 0
#define ARD 4
#define ARC 0
#define PLL_LOCK 4
#define RF_DR 3
#define RF_PWR 6
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
#define RX_P_NO 1
#define TX_FULL 0
#define PLOS_CNT 4
#define ARC_CNT 0
#define TX_REUSE 6
#define FIFO_FULL 5
#define TX_EMPTY 4
#define RX_FULL 1
#define RX_EMPTY 0
#define DPL_P5 5
#define DPL_P4 4
#define DPL_P3 3
#define DPL_P2 2
#define DPL_P1 1
#define DPL_P0 0
#define EN_DPL 2
#define EN_ACK_PAY 1
#define EN_DYN_ACK 0
/* Instruction Mnemonics */
#define R_REGISTER 0x00
#define W_REGISTER 0x20
#define REGISTER_MASK 0x1F
#define ACTIVATE 0x50
#define R_RX_PL_WID 0x60
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xA0
#define W_ACK_PAYLOAD 0xA8
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
/* Non-P omissions */
#define LNA_HCURR 0
/* P model memory Map */
#define RPD 0x09
#define W_TX_PAYLOAD_NO_ACK 0xB0
/* P model bit Mnemonics */
#define RF_DR_LOW 5
#define RF_DR_HIGH 3
#define RF_PWR_LOW 1
#define RF_PWR_HIGH 2
# Optimized Raspberry Pi RF24 and RF24 Network Libraries See https://github.com/TMRh20/RF24/blob/master/README.md
General Documentation: http://tmrh20.github.io
Library functions are mostly the same.
See the included examples for RPi specific usage
## Raspberry Pi - PreConfig
### Possible pre-configuration:
If SPI is not already enabled, load it on boot:
sudo raspi-config
A. Update the tool via the menu as required
B. Select Advanced and enable the SPI kernel module
C. Update other software and libraries:
sudo apt-get update
sudo apt-get upgrade
# RPi - RF24 Quick-Start
A. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:
mkdir ~/rf24libs
cd ~/rf24libs
B. Clone the RF24 Repo
git clone https://github.com/tmrh20/RF24.git rtemp
C. Copy the RPi library folder to the current directory, and delete the rest
mv rtemp/RPi/RF24 ./
rm -r rtemp
cd RF24
D. Build the library, and run an example file:
sudo make install
cd examples
make
sudo ./gettingstarted
# RPi - RF24Network Quick-Start
A. Enter the same directory that contains the RF24 library folder
cd ~/rf24libs
B. Clone the RF24Network Repo
git clone https://github.com/tmrh20/RF24Network.git ntemp
C. Copy the RF24Network folder to the current directory, and delete the rest
mv ntemp/RPi/RF24Network ./
rm -r ntemp
cd RF24Network
D. Build the library
sudo make install
cd examples
make
sudo ./helloworld_rx OR sudo ./helloworld_tx
# Connection Info
Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN
Can use either RPi CE0 or CE1 pins for radio CSN.
Choose any RPi output pin for radio CE pin.
**Constructor:**
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_V2_GPIO_P1_15,BCM2835_SPI_CS1, BCM2835_SPI_SPEED_8MHZ);
RPi B+:
RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
or
RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_26, BCM2835_SPI_SPEED_8MHZ);
**Pins:**
| PIN | NRF24L01 | RPI | RPi -P1 Connector |
|-----|----------|------------|-------------------|
| 1 | GND | rpi-gnd | (25) |
| 2 | VCC | rpi-3v3 | (17) |
| 3 | CE | rpi-gpio22 | (15) |
| 4 | CSN | rpi-gpio8 | (24) |
| 5 | SCK | rpi-sckl | (23) |
| 6 | MOSI | rpi-mosi | (19) |
| 7 | MISO | rpi-miso | (21) |
| 8 | IRQ | - | - |
See http://www.airspayce.com/mikem/bcm2835/index.html for BCM2835 class documentation.
Note: The BCM library has been customized slightly to allow use of hardware CE pins not
in use for SPI, and to include a millis() function.
****************
Based on the arduino lib from J. Coliz <maniacbug@ymail.com>.
the library was berryfied by Purinda Gunasekara <purinda@gmail.com>.
then forked from github stanleyseow/RF24 to https://github.com/jscrane/RF24-rpi
Network lib also based on https://github.com/farconada/RF24Network
Currently optimized and aligned with Arduino fork of libraries by TMRh20:
https://github.com/tmrh20/RF24/RPi and https://github.com/tmrh20/RF24Network/RPi
Documentation: http://tmrh20.github.io
See RPi/RF24/readme.md See https://github.com/TMRh20/RF24/blob/master/README.md
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <RF24/RF24.h> #include "../RF24.h"
using namespace std; using namespace std;
...@@ -50,7 +50,7 @@ const uint64_t pipes[6] = ...@@ -50,7 +50,7 @@ const uint64_t pipes[6] =
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ);
int main(int argc, char** argv) int main(int argc, char** argv)
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <RF24/RF24.h> #include "../RF24.h"
using namespace std; using namespace std;
...@@ -42,7 +42,7 @@ using namespace std; ...@@ -42,7 +42,7 @@ using namespace std;
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_8MHZ);
// //
......
...@@ -23,7 +23,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library ...@@ -23,7 +23,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <RF24/RF24.h> #include "./RF24.h"
using namespace std; using namespace std;
// //
...@@ -38,22 +38,19 @@ using namespace std; ...@@ -38,22 +38,19 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint8_t pipes[][6] = {"1Node","2Node"}; const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
//const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = true, role_pong_back = false;
bool role = role_pong_back;
// Print preamble: // Print preamble:
printf("RF24/examples/pingtest/\n"); printf("RF24/examples/pingtest/\n");
...@@ -63,6 +60,7 @@ int main(int argc, char** argv){ ...@@ -63,6 +60,7 @@ int main(int argc, char** argv){
// optionally, increase the delay between retries & # of retries // optionally, increase the delay between retries & # of retries
radio.setRetries(15,15); radio.setRetries(15,15);
// Dump the configuration of the rf unit for debugging // Dump the configuration of the rf unit for debugging
radio.printDetails(); radio.printDetails();
...@@ -96,7 +94,7 @@ int main(int argc, char** argv){ ...@@ -96,7 +94,7 @@ int main(int argc, char** argv){
radio.startListening(); radio.startListening();
} }
// forever loop // forever loop
while (1) while (1)
{ {
...@@ -122,6 +120,8 @@ int main(int argc, char** argv){ ...@@ -122,6 +120,8 @@ int main(int argc, char** argv){
unsigned long started_waiting_at = millis(); unsigned long started_waiting_at = millis();
bool timeout = false; bool timeout = false;
while ( ! radio.available() && ! timeout ) { while ( ! radio.available() && ! timeout ) {
// by bcatalin » Thu Feb 14, 2013 11:26 am
//delay(5); //add a small delay to let radio.available to check payload
if (millis() - started_waiting_at > 200 ) if (millis() - started_waiting_at > 200 )
timeout = true; timeout = true;
} }
...@@ -143,8 +143,7 @@ int main(int argc, char** argv){ ...@@ -143,8 +143,7 @@ int main(int argc, char** argv){
} }
// Try again 1s later // Try again 1s later
// delay(1000); // delay(1000);
sleep(1); sleep(1);
} }
...@@ -155,10 +154,9 @@ int main(int argc, char** argv){ ...@@ -155,10 +154,9 @@ int main(int argc, char** argv){
if ( role == role_pong_back ) if ( role == role_pong_back )
{ {
// if there is data ready // if there is data ready
//printf("Check available...\n"); //printf("Check available...\n");
//delay(3);
if ( radio.available() ) if ( radio.available() )
{ {
// Dump the payloads until we've gotten everything // Dump the payloads until we've gotten everything
...@@ -166,25 +164,22 @@ int main(int argc, char** argv){ ...@@ -166,25 +164,22 @@ int main(int argc, char** argv){
// Fetch the payload, and see if this was the last one. // Fetch the payload, and see if this was the last one.
while(radio.available()){ radio.read( &got_time, sizeof(unsigned long) );
radio.read( &got_time, sizeof(unsigned long) );
}
radio.stopListening(); radio.stopListening();
//delay(1);
// Seem to need a delay, or the RPi is too quick
radio.write( &got_time, sizeof(unsigned long) ); radio.write( &got_time, sizeof(unsigned long) );
//delay(1);
// Now, resume listening so we catch the next packets. // Now, resume listening so we catch the next packets.
radio.startListening(); radio.startListening();
//delay(1);
// Spew it // Spew it
printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time); printf("Got payload(%d) %lu...\n",sizeof(unsigned long), got_time);
delay(925); //Delay after payload responded to, minimize RPi CPU time
} }
//delay(5);
} }
} // forever loop } // forever loop
return 0; return 0;
......
...@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library ...@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <RF24/RF24.h> #include "./RF24.h"
using namespace std; using namespace std;
...@@ -28,20 +28,17 @@ using namespace std; ...@@ -28,20 +28,17 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed // CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz // Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS1, BCM2835_SPI_SPEED_1MHZ); //RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_26, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+ // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 15 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint8_t addresses[][6] = {"1Node","2Node"}; const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0, role = 0; bool role_ping_out = 1, role_pong_back = 0, role = 0;
...@@ -51,12 +48,14 @@ uint8_t counter = 1; // ...@@ -51,12 +48,14 @@ uint8_t counter = 1; //
int main(int argc, char** argv){ int main(int argc, char** argv){
printf("RPi/RF24/examples/gettingstarted_call_response\n"); printf("RF24/examples/gettingstarted_call_response\n");
radio.begin(); radio.begin();
radio.setAutoAck(1); // Ensure autoACK is enabled radio.setAutoAck(1); // Ensure autoACK is enabled
radio.enableAckPayload(); // Allow optional ack payloads radio.enableAckPayload(); // Allow optional ack payloads
radio.setRetries(1,15); // Smallest time between retries, max no. of retries radio.setRetries(1,15); // Smallest time between retries, max no. of retries
radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed radio.setPayloadSize(1); // Here we are sending 1-byte payloads to test the call-response speed
//radio.powerUp();
radio.printDetails(); // Dump the configuration of the rf unit for debugging radio.printDetails(); // Dump the configuration of the rf unit for debugging
...@@ -77,8 +76,9 @@ int main(int argc, char** argv){ ...@@ -77,8 +76,9 @@ int main(int argc, char** argv){
} }
} }
/***********************************/ /***********************************/
// This opens two pipes for these two nodes to communicate // This simple sketch opens two pipes for these two nodes to communicate
// back and forth. // back and forth.
if ( role == role_ping_out ) { if ( role == role_ping_out ) {
radio.openWritingPipe(addresses[0]); radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]); radio.openReadingPipe(1,addresses[1]);
...@@ -96,7 +96,7 @@ while (1){ ...@@ -96,7 +96,7 @@ while (1){
if (role == role_ping_out){ // Radio is in ping mode if (role == role_ping_out){ // Radio is in ping mode
uint8_t gotByte; // Initialize a variable for the incoming response uint8_t gotByte; // Initialize a variable for the incoming response
radio.stopListening(); // First, stop listening so we can talk. radio.stopListening(); // First, stop listening so we can talk.
printf("Now sending %d as payload. ",counter); // Use a simple byte counter as payload printf("Now sending %d as payload. ",counter); // Use a simple byte counter as payload
...@@ -116,22 +116,18 @@ while (1){ ...@@ -116,22 +116,18 @@ while (1){
}else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed }else{ printf("Sending failed.\n\r"); } // If no ack response, sending failed
sleep(1); // Try again later sleep(1); // Try again later
//delay(250);
} }
/****************** Pong Back Role ***************************/ /****************** Pong Back Role ***************************/
if ( role == role_pong_back ) { if ( role == role_pong_back ) {
uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received uint8_t pipeNo, gotByte; // Declare variables for the pipe and the byte received
if( radio.available(&pipeNo)){ // Read all available payloads while( radio.available(&pipeNo)){ // Read all available payloads
radio.flush_tx(); // Clear any unused ACK payloads
radio.read( &gotByte, 1 ); radio.read( &gotByte, 1 );
// Since this is a call-response. Respond directly with an ack payload. // Since this is a call-response. Respond directly with an ack payload.
// Ack payloads are much more efficient than switching to transmit mode to respond to a call // Ack payloads are much more efficient than switching to transmit mode to respond to a call
radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads. radio.writeAckPayload(pipeNo,&gotByte, 1 ); // This can be commented out to send empty payloads.
printf("Sent response %d \n\r", gotByte); printf("Sent response %d \n\r", gotByte);
delay(900); //Delay after a response to minimize CPU usage on RPi
//Expects a payload every second
} }
} }
......
...@@ -28,9 +28,6 @@ using namespace std; ...@@ -28,9 +28,6 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
...@@ -38,7 +35,8 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -38,7 +35,8 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
const int min_payload_size = 4; const int min_payload_size = 4;
const int max_payload_size = 32; const int max_payload_size = 32;
...@@ -49,8 +47,6 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating ...@@ -49,8 +47,6 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
printf("RF24/examples/pingpair_dyn/\n"); printf("RF24/examples/pingpair_dyn/\n");
......
...@@ -16,7 +16,7 @@ TMRh20 2014 ...@@ -16,7 +16,7 @@ TMRh20 2014
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <RF24/RF24.h> #include "./RF24.h"
using namespace std; using namespace std;
...@@ -32,9 +32,6 @@ using namespace std; ...@@ -32,9 +32,6 @@ using namespace std;
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// NEW: Setup for RPi B+
//RF24 radio(RPI_BPLUS_GPIO_J8_15,RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz // Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
...@@ -43,14 +40,13 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ); ...@@ -43,14 +40,13 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe addresses for the 2 nodes to communicate.
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
uint8_t data[32]; uint8_t data[32];
unsigned long startTime, stopTime, counter, rxTimer=0; unsigned long startTime, stopTime, counter, rxTimer=0;
int main(int argc, char** argv){ int main(int argc, char** argv){
bool role_ping_out = 1, role_pong_back = 0;
bool role = 0;
// Print preamble: // Print preamble:
...@@ -59,9 +55,9 @@ int main(int argc, char** argv){ ...@@ -59,9 +55,9 @@ int main(int argc, char** argv){
radio.begin(); // Setup and configure rf radio radio.begin(); // Setup and configure rf radio
radio.setChannel(1); radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX); radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_1MBPS); radio.setDataRate(RF24_2MBPS);
radio.setAutoAck(1); // Ensure autoACK is enabled radio.setAutoAck(1); // Ensure autoACK is enabled
radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8); radio.setCRCLength(RF24_CRC_8);
radio.printDetails(); radio.printDetails();
/********* Role chooser ***********/ /********* Role chooser ***********/
...@@ -93,7 +89,7 @@ int main(int argc, char** argv){ ...@@ -93,7 +89,7 @@ int main(int argc, char** argv){
for(int i=0; i<32; i++){ for(int i=0; i<32; i++){
data[i] = rand() % 255; //Load the buffer with random data data[i] = rand() % 255; //Load the buffer with random data
} }
// forever loop // forever loop
...@@ -103,24 +99,16 @@ int main(int argc, char** argv){ ...@@ -103,24 +99,16 @@ int main(int argc, char** argv){
sleep(2); sleep(2);
printf("Initiating Basic Data Transfer\n\r"); printf("Initiating Basic Data Transfer\n\r");
long int cycles = 10000; //Change this to a higher or lower number. long int cycles = 10000; //Change this to a higher or lower number.
// unsigned long pauseTime = millis(); //Uncomment if autoAck == 1 ( NOACK )
startTime = millis(); startTime = millis();
for(int i=0; i<cycles; i++){ //Loop through a number of cycles for(int i=0; i<cycles; i++){ //Loop through a number of cycles
data[0] = i; //Change the first byte of the payload for identification data[0] = i; //Change the first byte of the payload for identification
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
counter++; //Keep count of failed payloads counter++; //Keep count of failed payloads
} }
}
//This is only required when NO ACK ( enableAutoAck(0) ) payloads are used
/* if(millis() - pauseTime > 3){ // Need to drop out of TX mode every 4ms if sending a steady stream of multicast data
pauseTime = millis();
radio.txStandBy(); // This gives the PLL time to sync back up
}
*/
}
stopTime = millis(); stopTime = millis();
if(!radio.txStandBy()){ counter+=3; } if(!radio.txStandBy()){ counter+=3; }
......
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