2016-06-24 7 views
0

Я использую arduino UNO и mega2560. Я использовал 2 модуля NRF24L01. один предназначен для передачи и другого приема. Проблема: Я получаю случайные значения на стороне приемника последовательного монитора arduino. Когда я использую тип int, он дает случайные целые числа непрерывно. Когда я использую тип String, он дает случайные символы.NRF24L01 + PA + LNA (Transciever) не сообщается между двумя ардуинами

Кодирование:

/*-----(Import needed libraries)-----*/ 
#include <SPI.h> // Comes with Arduino IDE 
#include "RF24.h" // Download and Install (See above) 
/*-----(Declare Constants and Pin Numbers)-----*/ 
//None yet 
/*-----(Declare objects)-----*/ 
// (Create an instance of a radio, specifying the CE and CS pins.) 
RF24 myRadio (7, 8); // "myRadio" is the identifier you will use in following methods 
/*-----(Declare Variables)-----*/ 
byte addresses[][6] = {"1Node"}; // Create address for 1 
int dataReceived; // Data that will be received from the transmitter 

void setup() /****** SETUP: RUNS ONCE ******/ 
{ 
    // Use the serial Monitor (Symbol on far right). Set speed to 115200 (Bottom Right) 
    Serial.begin(115200); 
    delay(1000); 
    //Serial.println(F("RF24/Simple Receive data Test")); 
    //Serial.println(F("Questions: [email protected]")); 

    myRadio.begin(); // Start up the physical nRF24L01 Radio 
    myRadio.setChannel(108); // Above most Wifi Channels 
    // 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. 
    myRadio.setPALevel(RF24_PA_MIN); 
    // myRadio.setPALevel(RF24_PA_MAX); // Uncomment for more power 

    myRadio.openReadingPipe(1, addresses[0]); // Use the first entry in array 'addresses' (Only 1 right now) 
    myRadio.startListening(); 

}//--(end setup)--- 


void loop() /****** LOOP: RUNS CONSTANTLY ******/ 
{ 

    if (myRadio.available()) // Check for incoming data from transmitter 
    { 
    while (myRadio.available()) // While there is data ready 
    { 
     myRadio.read(&dataReceived, sizeof(dataReceived)); 
     //Serial.println("Data is coming"); 
     // Get the data payload (You must have defined that already!) 
    } 
    } // DO something with the data, like print it 
    else{ 
    Serial.println("Data received = "); 
    Serial.println(dataReceived); 
delay(200);} 

}//--(end main loop)--- 

Reciever serial monitor

ответ

0

Похоже, вы потенциально вызывая myRadio.read() несколько раз с одной и той же целевой переменной.

Это приведет к тому, что данные, уже сохраненные в этой переменной, будут перезаписаны во второй раз, когда вы проходите цикл while.