PDA

View Full Version : RF24 (maniacbug) and Nrf24L01 with Teensy 3.0



matheusbrat
01-24-2013, 04:22 AM
Hello Guys,

I got MIRF Library working on Teensy 3.0 (http://forum.pjrc.com/threads/16001-Does-anybody-get-Teensy-3-working-with-NRF24L01) I looked into http://forum.pjrc.com/threads/433-nordic-radio-tlc5940-t2-t3-possible?highlight=nrf24l01 and Paul said that there is a lot of AVR specific stuff. But I want to get it working since it is much better.

So I started trying to compile it directly which give me a lot of errors. First of all I needed to comment this line on pingpair example: fdevopen(&serial_putc, 0);

It started going further, but still gives me errors. So I noticed that there is a lot of PRINTS that use some kind of printf definition. So I commented all PRINTF lines. Then I started getting PROGMEN erros and tried to remove all of then, and that lead me to this error:


/home/x-warrior/arduino-1.0.3-teensy/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2/libc.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text+0x14): undefined reference to `_fstat'
/home/x-warrior/arduino-1.0.3-teensy/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2/libc.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text+0x12): undefined reference to `_isatty'
collect2: error: ld returned 1 exit status


Any ideas how to pass throught this?

PS: As attachment I'm sending my RF24 Library in the current state.

185

PS2: Maybe I removed something wrong... but lets keep dig

matheusbrat
01-24-2013, 04:16 PM
So I got RF24 library from Maniacbug. And then created my own files (RF24t.cpp, RF24t.h, NRF24L01.h) and started copy pasting the .h then I started doing the same for the .cpp and checking all functions/methods and removing "printf/IF_SERIAL_DEBUG/PSTR".

And it seems to be working. \o/

The bad part is, all useful information that RF24 library used to print, isn't available. But it is a start.

188

OE8PCK
03-18-2017, 01:28 PM
So I got RF24 library from Maniacbug. And then created my own files (RF24t.cpp, RF24t.h, NRF24L01.h) and started copy pasting the .h then I started doing the same for the .cpp and checking all functions/methods and removing "printf/IF_SERIAL_DEBUG/PSTR".

And it seems to be working. \o/

The bad part is, all useful information that RF24 library used to print, isn't available. But it is a start.

188

Hi Matheusbrat

did you ever get the Teensy to work with the nrf24l01. I am still having a lot of trouble. Could you be so kind as to post a TX sketch using the Arduino UNO and an RX Sketch using the Teensy 3.0 that you know works. If it it not too much trouble also the wiring and a link to the required libraries. Regarding the libraries, I am using the RF24 from Maniacbug and it works well with other applications that I use for the arduino, it appears that there are a number of versions with the same name, can you confirm this? How do I get round this problem when I am using the arduino IDE?
I am very much a beginner when it comes to the Teensy, I have heard that the SPI speed is important etc. etc.


Paul OE8PCK

PaulStoffregen
03-21-2017, 12:36 PM
@OE8PCK - I see you've posted essentially the same question 3 times on 3 different thread, all within a several hours of each other. Which should I try to answer? And which get left unanswered for people to find in the future? I'm going to post this same reply on all 3 locations. Please, if you reply, keep it all on 1 thread, ok?

First, look at this thread where a similar problem was recently solved.

https://forum.pjrc.com/threads/42711-Teensy-3-2-with-NRF24L01?p=137080&viewfull=1#post137080

The code originally written for Arduino Uno prints all the info too quickly, before you can open the Arduino Serial Monitor. Read that thread for the solution, and more followup about things needed to make this really work communicating between 2 boards.

OE8PCK
03-21-2017, 06:36 PM
Hi Paul
That you very much for your answer.
I have now made two sketches based on the Information in the link ypu sent me and I do not get the same results. I have really checked the wiring VERY carefully. I will post the two skeches below, perhaps you could have a look and see if you can find any Problems. On the Teensy side I get a dump of the Information and it says it is sending the info but nothing else on the UNO side I get only a remark telling me to push T the tx. At the top of each sketch I have written where I have loaded the relevant sketch to.
Your valued comments would be VERY welcome.




//Arduino UNO
#include <SPI.h>
#include "RF24.h"


bool radioNumber = 0;

RF24 radio(7,8);

byte addresses[][6] = {"1Node","2Node"};

bool role = 0; // 0 = pong back , 1 = ping out

void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for arduino serial monitor
delay(2000); // WNG - println's below started working after I put in this delay
Serial.println("RF24/examples/GettingStarted");
Serial.println("*** PRESS 'T' to begin transmitting to the other node");

radio.begin();

radio.setPALevel(RF24_PA_MIN);

if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

// Start the radio listening for data
radio.startListening();
radio.printDetails();
}

void loop() {
/****************** Ping Out Role ***************************/
if (role == 1) {

radio.stopListening();
Serial.println("Now sending");

unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
Serial.println("failed");
}

radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros();
boolean timeout = false;

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println("Failed, response timed out.");
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();

// Spew it
Serial.print("Sent ");
Serial.print(start_time);
Serial.print(", Got response ");
Serial.print(got_time);
Serial.print(", Round-trip delay ");
Serial.print(end_time-start_time);
Serial.println(" microseconds");
}

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

/****************** Pong Back Role ***************************/

if ( role == 0 )
{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print("Sent response ");
Serial.println(got_time);
}
}


} // Loop





//Teensy 3.2

#include <SPI.h>
#include "RF24.h"


bool radioNumber = 1;

RF24 radio(9,10);

byte addresses[][6] = {"1Node","2Node"};

bool role = 1; // 0 = pong back , 1 = ping out

void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for arduino serial monitor
delay(2000); // WNG - println's below started working after I put in this delay
Serial.println("RF24/examples/GettingStarted");
Serial.println("*** PRESS 'T' to begin transmitting to the other node");

radio.begin();

radio.setPALevel(RF24_PA_MIN);

if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

// Start the radio listening for data
radio.startListening();
radio.printDetails();
}

void loop() {
/****************** Ping Out Role ***************************/
if (role == 1) {

radio.stopListening();
Serial.println("Now sending");

unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
Serial.println("failed");
}

radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros();
boolean timeout = false;

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println("Failed, response timed out.");
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();

// Spew it
Serial.print("Sent ");
Serial.print(start_time);
Serial.print(", Got response ");
Serial.print(got_time);
Serial.print(", Round-trip delay ");
Serial.print(end_time-start_time);
Serial.println(" microseconds");
}

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

/****************** Pong Back Role ***************************/

if ( role == 0 )
{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print("Sent response ");
Serial.println(got_time);
}
}


} // Loop

PaulStoffregen
03-22-2017, 12:22 PM
I have really checked the wiring VERY carefully.

Can you post photos to show us the actual wiring?

OE8PCK
03-22-2017, 12:33 PM
10070100711007210073100741007510076100771007810079

If this not OK please tell me how you want the Pictures,

Many Thanks,

Paul

PaulStoffregen
03-22-2017, 01:23 PM
It's difficult to see which wires go where.

Your RF24 looks like this one? Is that right?

http://www.instructables.com/id/Arduino-NRF24L01-USING-RF-Module/

I see Arduino Uno is providing power to the RF24 module, but Teensy is not powering its RF24. There are no connections to any of Teensy's power pins!

Perhaps you've connected everything wrong to Teensy, rotated 180 degrees? I see the red and brown wires, which looks like they are (maybe) meant to be VCC and GND, go to Teensy pins 10 and 11. That looks very wrong. Maybe you meant to connect these to 3.3V and GND, but you're viewing the Teensy 180 degrees rotated?

Hold the pinout card close to your Teensy. Look carefully at the orientation of the Teensy and rotate your pinout card so the picture is facing the same direction as your Teensy. I believe you will discover you've connected all the wires in the wrong places.

OE8PCK
03-22-2017, 04:04 PM
OK I now have a red face but what the heck,
I am sort of getting info now but have also had to adjust the sketches. Before I explain everything I will include the code agin, the wiring and the Monitor info.
Here goes,



//Arduino UNO
#include <SPI.h>
#include "RF24.h"


bool radioNumber = 0;

RF24 radio(9,10);

byte addresses[][6] = {"1Node","2Node"};

bool role = 1; // 0 = pong back , 1 = ping out

void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for arduino serial monitor
delay(2000); // WNG - println's below started working after I put in this delay
Serial.println("RF24/examples/GettingStarted");
Serial.println("*** PRESS 'T' to begin transmitting to the other node");

radio.begin();

radio.setPALevel(RF24_PA_MIN);

if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

// Start the radio listening for data
radio.startListening();
radio.printDetails();
}

void loop() {
/****************** Ping Out Role ***************************/
if (role == 1) {

radio.stopListening();
Serial.println("Now sending");

unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
Serial.println("failed");
}

radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros();
boolean timeout = false;

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println("Failed, response timed out.");
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();

// Spew it
Serial.print("Sent ");
Serial.print(start_time);
Serial.print(", Got response ");
Serial.print(got_time);
Serial.print(", Round-trip delay ");
Serial.print(end_time-start_time);
Serial.println(" microseconds");
}

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

/****************** Pong Back Role ***************************/

if ( role == 1 )
{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print("Sent response ");
Serial.println(got_time);
}
}


} // Loop







//Teensy 3.2

#include <SPI.h>
#include "RF24.h"


bool radioNumber = 1;

RF24 radio(9,10);

byte addresses[][6] = {"1Node","2Node"};

bool role = 0; // 0 = pong back , 1 = ping out

void setup() {
Serial.begin(115200);
while (!Serial) ; // wait for arduino serial monitor
delay(2000); // WNG - println's below started working after I put in this delay
Serial.println("RF24/examples/GettingStarted");
Serial.println("*** PRESS 'T' to begin transmitting to the other node");

radio.begin();

radio.setPALevel(RF24_PA_MIN);

if(radioNumber){
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[0]);
}else{
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
}

// Start the radio listening for data
radio.startListening();
radio.printDetails();
}

void loop() {
/****************** Ping Out Role ***************************/
if (role == 0) {

radio.stopListening();
Serial.println("Now sending");

unsigned long start_time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &start_time, sizeof(unsigned long) )){
Serial.println("failed");
}

radio.startListening(); // Now, continue listening

unsigned long started_waiting_at = micros();
boolean timeout = false;

while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){
timeout = true;
break;
}
}

if ( timeout ){ // Describe the results
Serial.println("Failed, response timed out.");
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();

// Spew it
Serial.print("Sent ");
Serial.print(start_time);
Serial.print(", Got response ");
Serial.print(got_time);
Serial.print(", Round-trip delay ");
Serial.print(end_time-start_time);
Serial.println(" microseconds");
}

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

/****************** Pong Back Role ***************************/

if ( role == 0 )
{
unsigned long got_time;

if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}

radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print("Sent response ");
Serial.println(got_time);
}
}


} // Loop


10083100841008510086100871008810089

Teensy Mon.

Now sending
failed
Sent 159481763, Got response 255948888, Round-trip delay 231826 microseconds
Now sending
failed
Sent 160714233, Got response 257181400, Round-trip delay 231825 microseconds
Now sending
failed
Sent 161946696, Got response 258413920, Round-trip delay 231870 microseconds
Now sending
failed
Sent 163179209, Got response 259646432, Round-trip delay 231824 microseconds
Now sending
failed
Sent 164411671, Got response 260878952, Round-trip delay 231822 microseconds
Now sending
failed
Sent 165644138, Got response 262111472, Ro


UNO Mon.

failed
Failed, response timed out.
Now sending
failed
Failed, response timed out.
Now sending
failed
Failed, response timed out.
Now sending
failed
Failed, response timed out.
Now sending
failed
Failed, response timed out.
Now sending
failed
Failed, response timed

PaulStoffregen
03-22-2017, 04:31 PM
Use GND, not AGND.

AGND is only meant to analog signals.

OE8PCK
03-22-2017, 04:44 PM
I have moved the gnd pin but the Monitors are showing the same as before. One Point I have rduced the Teensy Speed to 24 MHZ because at a higher Speed the Monitor Shows intermitend rx. Optimize is set to fast all in the IDE tools

OE8PCK
03-24-2017, 09:42 AM
Hi Paul,
Thank you very much for your help, I have another set of questions. I have been looking at this problem now for some time... I just don't understand what I am doing wrong... The Arduino is Transmitting because when I remove the power the Teensy stopy receiving..... but why the failed on the Teensy monitor? and why the fail on the arduino monitor. Is this a timing problem. I am afraid I bitten more than I can chew. Is there an easier way to just send data to the Teensy with no aknowledge because as far I understand the NEF2401 the acknowledgment is automatic anyway.

Best wishes Paul OE8PCK

OE8PCK
03-31-2017, 09:45 AM
Hi Paul,
Thank you very much for your help, I have another set of questions. I have been looking at this problem now for some time... I just don't understand what I am doing wrong... The Arduino is Transmitting because when I remove the power the Teensy stopy receiving..... but why the failed on the Teensy monitor? and why the fail on the arduino monitor. Is this a timing problem. I am afraid I bitten more than I can chew. Is there an easier way to just send data to the Teensy with no aknowledge because as far I understand the NEF2401 the acknowledgment is automatic anyway.

Best wishes Paul OE8PCK

FINALLY got it all going. It was a mixture of getting the pins on the Teensy right and small code corrections. Basically not being careful enough.
Thank you very much for your patience it is very much appreciated.