Hallo Leute,
Ich versuche seit Tagen ein nRF24L01 2.4GHz Modul mit zwei Arduinos an laufen zubringen so langsam bin ich am verzweifeln.
Eigentlich wollte ich nur für ein Schulprojekt eine Fernbedienung bauen, das hat mich jetzt so gefesselt das ich dies gerne über zwei Arduino lösen würde hierfür habe ich bereits mein nRF24L01 mit einem Arduino mega verbunden
1 GRN
2 3,3v
3 CE pin 7
4 CSN pin 8
5 SCK pin 52
6 MOSI pin 51
7 MISO pin 50
und auf der anderen Seite einen Arduino uno mit einem nRF24L01
1 GRN
2 3,3v
3 CE pin 7
4 CSN pin 8
5 SCK pin 13
6 MOSI pin 11
7 MISO pin 12
als Bibliothek habe ich die "Optimized fork of nRF24L01 for Arduino & Raspberry Pi/Linux Devices " verwendet:
und als code eine Beispiel:
#include <SPI.h>
#include "RF24.h"
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 0;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool role = 0;
void setup() {
Serial.begin(115200);
Serial.println(F("RF24/examples/GettingStarted"));
Serial.println(F("*** PRESS 'T' to begin transmitting to the other node"));
radio.begin();
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_LOW);
// Open a writing and reading pipe on each radio, with opposite addresses
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();
}
void loop() {
/****************** Ping Out Role ***************************/
if (role == 1) {
radio.stopListening(); // First, stop listening so we can talk.
Serial.println(F("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(F("failed"));
}
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
Serial.println(F("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(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 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(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 TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK"));
role = 1; // Become the primary transmitter (ping out)
}else
if ( c == 'R' && role == 1 ){
Serial.println(F("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK"));
role = 0; // Become the primary receiver (pong back)
radio.startListening();
}
}
}
als Ergebnis bekomme ich nur
Now sending
Sent 12286840, Got response 0, Round-trip delay 17940 microseconds
Now sending
Sent 13306248, Got response 0, Round-trip delay 17904 microseconds
Now sending
Sent 14325624, Got response 0, Round-trip delay 17912 microseconds
oder
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Sent response 0
Ich habe eigentlich schon alles probiert:
Andere Bibliotheken wie
maniacbug/RF24
nRF24/RF24 :keine Veränderung
Pin 7 und 8 getauscht :keine Veränderung
"radioNumber" kreuzgetauscht :keine Veränderung
nRF24L01 getauscht :keine Veränderung
Arduino getauscht :keine Veränderung
Kondensator an nRF24L01 :keine Veränderung
es gibt jetzt kaum noch Schwankungen und mein nRF24L01 hat konstant um die 3,2v-3,3v
was mir noch aufgefallen ist beim receiven bleibt das Ergebnis das selbe auch wenn mein nRF24L01 abgesteckt ist.
beim senden hingegen kommt ein failed.
und jenachdem wie ich die Kabel vom SPI bus (heißt der so? SCK/ MOSI/ MISO ) anfasse kommt dann doch mal ein etwas komisches Ergebnis welches definitiv nicht stimmen kann.
Kabel habe ich natürlich auch schon getaucht und sind nur etwa 5 cm lang.
kann ich irgendwo sehen ob er wirklich was sendet?
mein E-Technik Lehrer hat (natürlich
)auch keine Ahnung, vielleicht hab ich mir hier ein etwas zu großes Projekt vorgenommen und weiss nicht mehr weiter oder was ich noch probieren kann
.
aber vielleicht kann mir jemand von euch Helfen
währe super lieb


