Problems with Getting Started Sketch from RF24 library from TMRH20
hello
i'm pretty new try networking between 2 arduinos. @ present i'm trying getting started sketch rf24 library tmrh20 work. i'm planning transmit data ds18s20 through attiny84 arduino uno nrf24l01.
but since don't manage start getting started sketch (from arduino uno arduino uno) bit difficulte.
it great if me.
i followed instructions on following website: https://arduino-info.wikispaces.com/nrf24l01-2.4ghz-howto
i think there problem in communication because don't receive answer on serial display.
ps: code website talks about:
i'm pretty new try networking between 2 arduinos. @ present i'm trying getting started sketch rf24 library tmrh20 work. i'm planning transmit data ds18s20 through attiny84 arduino uno nrf24l01.
but since don't manage start getting started sketch (from arduino uno arduino uno) bit difficulte.
it great if me.
i followed instructions on following website: https://arduino-info.wikispaces.com/nrf24l01-2.4ghz-howto
i think there problem in communication because don't receive answer on serial display.
ps: code website talks about:
code: [select]
/*
* getting started example sketch nrf24l01+ radios
* basic example of how send data 1 node another
* updated: dec 2014 tmrh20
*/
#include <spi.h>
#include "rf24.h"
/****************** user config ***************************/
/*** set radio radio number 0 or 1 ***/
bool radionumber = 0;
/* hardware configuration: set nrf24l01 radio on spi bus plus pins 7 & 8 */
rf24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1node","2node"};
// used control whether node sending or receiving
bool role = 0;
void setup() {
serial.begin(115200);
serial.println(f("rf24/examples/gettingstarted"));
serial.println(f("*** press 't' begin transmitting other node"));
radio.begin();
// set pa level low prevent power supply related issues since a
// getting_started sketch, , likelihood of close proximity of devices. rf24_pa_max default.
radio.setpalevel(rf24_pa_low);
// open writing , reading pipe on each radio, opposite addresses
if(radionumber){
radio.openwritingpipe(addresses[1]);
radio.openreadingpipe(1,addresses[0]);
}else{
radio.openwritingpipe(addresses[0]);
radio.openreadingpipe(1,addresses[1]);
}
// start radio listening data
radio.startlistening();
}
void loop() {
/****************** ping out role ***************************/
if (role == 1) {
radio.stoplistening(); // first, stop listening can talk.
serial.println(f("now sending"));
unsigned long start_time = micros(); // take time, , send it. block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
serial.println(f("failed"));
}
radio.startlistening(); // now, continue listening
unsigned long started_waiting_at = micros(); // set timeout period, current microseconds
boolean timeout = false; // set variable indicate if response received or not
while ( ! radio.available() ){ // while nothing received
if (micros() - started_waiting_at > 200000 ){ // if waited longer 200ms, indicate timeout , exit while loop
timeout = true;
break;
}
}
if ( timeout ){ // describe results
serial.println(f("failed, response timed out."));
}else{
unsigned long got_time; // grab response, compare, , send debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();
// spew it
serial.print(f("sent "));
serial.print(start_time);
serial.print(f(", got response "));
serial.print(got_time);
serial.print(f(", round-trip delay "));
serial.print(end_time-start_time);
serial.println(f(" microseconds"));
}
// try again 1s later
delay(1000);
}
/****************** pong role ***************************/
if ( role == 0 )
{
unsigned long got_time;
if( radio.available()){
// variable received timestamp
while (radio.available()) { // while there data ready
radio.read( &got_time, sizeof(unsigned long) ); // payload
}
radio.stoplistening(); // first, stop listening can talk
radio.write( &got_time, sizeof(unsigned long) ); // send final 1 back.
radio.startlistening(); // now, resume listening catch next packets.
serial.print(f("sent response "));
serial.println(got_time);
}
}
/****************** change roles via serial commands ***************************/
if ( serial.available() )
{
char c = toupper(serial.read());
if ( c == 't' && role == 0 ){
serial.println(f("*** changing transmit role -- press 'r' switch back"));
role = 1; // become primary transmitter (ping out)
}else
if ( c == 'r' && role == 1 ){
serial.println(f("*** changing receive role -- press 't' switch back"));
role = 0; // become primary receiver (pong back)
radio.startlistening();
}
}
} // loop
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Problems with Getting Started Sketch from RF24 library from TMRH20
arduino
Comments
Post a Comment