Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RF24
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
RF24
Commits
c51049de
Commit
c51049de
authored
Nov 04, 2014
by
TMRh20
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace old examples with the current ones for RPi
Accidentally copied old RPi examples on last commit (code merge)
parent
85038040
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
53 deletions
+78
-53
examples_RPi/extra/rpi-hub.cpp
examples_RPi/extra/rpi-hub.cpp
+2
-2
examples_RPi/extra/scanner.cpp
examples_RPi/extra/scanner.cpp
+2
-2
examples_RPi/gettingstarted.cpp
examples_RPi/gettingstarted.cpp
+23
-18
examples_RPi/gettingstarted_call_response.cpp
examples_RPi/gettingstarted_call_response.cpp
+20
-16
examples_RPi/pingpair_dyn.cpp
examples_RPi/pingpair_dyn.cpp
+6
-2
examples_RPi/transfer.cpp
examples_RPi/transfer.cpp
+25
-13
No files found.
examples_RPi/extra/rpi-hub.cpp
View file @
c51049de
...
...
@@ -29,7 +29,7 @@
#include <cstdlib>
#include <iostream>
#include
"../RF24.h"
#include
<RF24/RF24.h>
using
namespace
std
;
...
...
@@ -50,7 +50,7 @@ const uint64_t pipes[6] =
//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
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_2
6
,
BCM2835_SPI_SPEED_8MHZ
);
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_2
4
,
BCM2835_SPI_SPEED_8MHZ
);
int
main
(
int
argc
,
char
**
argv
)
...
...
examples_RPi/extra/scanner.cpp
View file @
c51049de
...
...
@@ -25,7 +25,7 @@
#include <cstdlib>
#include <iostream>
#include
"../RF24.h"
#include
<RF24/RF24.h>
using
namespace
std
;
...
...
@@ -42,7 +42,7 @@ using namespace std;
//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
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_2
6
,
BCM2835_SPI_SPEED_8MHZ
);
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_2
4
,
BCM2835_SPI_SPEED_8MHZ
);
//
...
...
examples_RPi/gettingstarted.cpp
View file @
c51049de
...
...
@@ -23,7 +23,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream>
#include <sstream>
#include <string>
#include
"./RF24.h"
#include
<RF24/RF24.h>
using
namespace
std
;
//
...
...
@@ -38,19 +38,22 @@ using namespace std;
// 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);
// 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
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.
const
uint64_t
pipes
[
2
]
=
{
0xABCDABCD71LL
,
0x544d52687CLL
};
const
uint8_t
pipes
[][
6
]
=
{
"1Node"
,
"2Node"
};
//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
){
bool
role_ping_out
=
true
,
role_pong_back
=
false
;
bool
role
=
role_pong_back
;
// Print preamble:
printf
(
"RF24/examples/pingtest/
\n
"
);
...
...
@@ -60,7 +63,6 @@ int main(int argc, char** argv){
// optionally, increase the delay between retries & # of retries
radio
.
setRetries
(
15
,
15
);
// Dump the configuration of the rf unit for debugging
radio
.
printDetails
();
...
...
@@ -94,7 +96,7 @@ int main(int argc, char** argv){
radio
.
startListening
();
}
// forever loop
while
(
1
)
{
...
...
@@ -120,8 +122,6 @@ int main(int argc, char** argv){
unsigned
long
started_waiting_at
=
millis
();
bool
timeout
=
false
;
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
)
timeout
=
true
;
}
...
...
@@ -143,7 +143,8 @@ int main(int argc, char** argv){
}
// Try again 1s later
// delay(1000);
// delay(1000);
sleep
(
1
);
}
...
...
@@ -154,9 +155,10 @@ int main(int argc, char** argv){
if
(
role
==
role_pong_back
)
{
// if there is data ready
//printf("Check available...\n");
//delay(3);
if
(
radio
.
available
()
)
{
// Dump the payloads until we've gotten everything
...
...
@@ -164,22 +166,25 @@ int main(int argc, char** argv){
// Fetch the payload, and see if this was the last one.
radio
.
read
(
&
got_time
,
sizeof
(
unsigned
long
)
);
while
(
radio
.
available
()){
radio
.
read
(
&
got_time
,
sizeof
(
unsigned
long
)
);
}
radio
.
stopListening
();
//delay(1);
// Seem to need a delay, or the RPi is too quick
radio
.
write
(
&
got_time
,
sizeof
(
unsigned
long
)
);
//delay(1);
// Now, resume listening so we catch the next packets.
radio
.
startListening
();
//delay(1);
// Spew it
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
return
0
;
...
...
examples_RPi/gettingstarted_call_response.cpp
View file @
c51049de
...
...
@@ -17,7 +17,7 @@ TMRh20 2014 - Updated to work with optimized RF24 Arduino library
#include <iostream>
#include <sstream>
#include <string>
#include
"./RF24.h"
#include
<RF24/RF24.h>
using
namespace
std
;
...
...
@@ -28,17 +28,20 @@ using namespace std;
// CE Pin, CSN Pin, SPI Speed
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22,
RPI_V2_GPIO_P1_26
, BCM2835_SPI_SPEED_1MHZ);
//RF24 radio(RPI_V2_GPIO_P1_22,
BCM2835_SPI_CS1
, BCM2835_SPI_SPEED_1MHZ);
// Setup for GPIO
22
CE and CE0 CSN with SPI Speed @ 4Mhz
// Setup for GPIO
15
CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
// NEW: Setup for RPi B+
//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
);
// Radio pipe addresses for the 2 nodes to communicate.
const
uint
64_t
addresses
[
2
]
=
{
0xABCDABCD71LL
,
0x544d52687CLL
};
const
uint
8_t
addresses
[][
6
]
=
{
"1Node"
,
"2Node"
};
bool
role_ping_out
=
1
,
role_pong_back
=
0
,
role
=
0
;
...
...
@@ -48,14 +51,12 @@ uint8_t counter = 1; //
int
main
(
int
argc
,
char
**
argv
){
printf
(
"RF24/examples/gettingstarted_call_response
\n
"
);
printf
(
"RPi/RF24/examples/gettingstarted_call_response
\n
"
);
radio
.
begin
();
radio
.
setAutoAck
(
1
);
// Ensure autoACK is enabled
radio
.
enableAckPayload
();
// Allow optional ack payloads
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.powerUp();
radio
.
printDetails
();
// Dump the configuration of the rf unit for debugging
...
...
@@ -76,9 +77,8 @@ int main(int argc, char** argv){
}
}
/***********************************/
// This
simple sketch
opens two pipes for these two nodes to communicate
// This opens two pipes for these two nodes to communicate
// back and forth.
if
(
role
==
role_ping_out
)
{
radio
.
openWritingPipe
(
addresses
[
0
]);
radio
.
openReadingPipe
(
1
,
addresses
[
1
]);
...
...
@@ -96,7 +96,7 @@ while (1){
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.
printf
(
"Now sending %d as payload. "
,
counter
);
// Use a simple byte counter as payload
...
...
@@ -116,18 +116,22 @@ while (1){
}
else
{
printf
(
"Sending failed.
\n\r
"
);
}
// If no ack response, sending failed
sleep
(
1
);
// Try again later
//delay(250);
}
/****************** Pong Back Role ***************************/
if
(
role
==
role_pong_back
)
{
uint8_t
pipeNo
,
gotByte
;
// Declare variables for the pipe and the byte received
while
(
radio
.
available
(
&
pipeNo
)){
// Read all available payloads
uint8_t
pipeNo
,
gotByte
;
// Declare variables for the pipe and the byte received
if
(
radio
.
available
(
&
pipeNo
)){
// Read all available payloads
radio
.
flush_tx
();
// Clear any unused ACK payloads
radio
.
read
(
&
gotByte
,
1
);
// 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
radio
.
writeAckPayload
(
pipeNo
,
&
gotByte
,
1
);
// This can be commented out to send empty payloads.
// 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
radio
.
writeAckPayload
(
pipeNo
,
&
gotByte
,
1
);
// This can be commented out to send empty payloads.
printf
(
"Sent response %d
\n\r
"
,
gotByte
);
delay
(
900
);
//Delay after a response to minimize CPU usage on RPi
//Expects a payload every second
}
}
...
...
examples_RPi/pingpair_dyn.cpp
View file @
c51049de
...
...
@@ -28,6 +28,9 @@ using namespace std;
// 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);
// 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
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_24
,
BCM2835_SPI_SPEED_8MHZ
);
...
...
@@ -35,8 +38,7 @@ 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.
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
max_payload_size
=
32
;
...
...
@@ -47,6 +49,8 @@ char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating
int
main
(
int
argc
,
char
**
argv
){
bool
role_ping_out
=
1
,
role_pong_back
=
0
;
bool
role
=
0
;
// Print preamble:
printf
(
"RF24/examples/pingpair_dyn/
\n
"
);
...
...
examples_RPi/transfer.cpp
View file @
c51049de
...
...
@@ -16,7 +16,7 @@ TMRh20 2014
#include <iostream>
#include <sstream>
#include <string>
#include
"./RF24.h"
#include
<RF24/RF24.h>
using
namespace
std
;
...
...
@@ -32,6 +32,9 @@ using namespace std;
// 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);
// 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
RF24
radio
(
RPI_V2_GPIO_P1_15
,
RPI_V2_GPIO_P1_24
,
BCM2835_SPI_SPEED_8MHZ
);
...
...
@@ -40,13 +43,14 @@ 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.
const
uint64_t
addresses
[
2
]
=
{
0xABCDABCD71LL
,
0x544d52687CLL
};
bool
role_ping_out
=
1
,
role_pong_back
=
0
;
bool
role
=
0
;
uint8_t
data
[
32
];
unsigned
long
startTime
,
stopTime
,
counter
,
rxTimer
=
0
;
int
main
(
int
argc
,
char
**
argv
){
bool
role_ping_out
=
1
,
role_pong_back
=
0
;
bool
role
=
0
;
// Print preamble:
...
...
@@ -55,9 +59,9 @@ int main(int argc, char** argv){
radio
.
begin
();
// Setup and configure rf radio
radio
.
setChannel
(
1
);
radio
.
setPALevel
(
RF24_PA_MAX
);
radio
.
setDataRate
(
RF24_
2
MBPS
);
radio
.
setDataRate
(
RF24_
1
MBPS
);
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
.
printDetails
();
/********* Role chooser ***********/
...
...
@@ -89,7 +93,7 @@ int main(int argc, char** argv){
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
...
...
@@ -99,16 +103,24 @@ int main(int argc, char** argv){
sleep
(
2
);
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
();
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
if
(
!
radio
.
writeFast
(
&
data
,
32
)){
//Write to the FIFO buffers
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
if
(
!
radio
.
writeFast
(
&
data
,
32
)){
//Write to the FIFO buffers
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
();
if
(
!
radio
.
txStandBy
()){
counter
+=
3
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment