3

I'm sending currently data from a Raspberry to an Arduino, but I have a problem with receiving response from the Arduino back to the Raspberry:

Sent the message: ['H', 'i', '.', '.', 'A', 'r', 'd', 'u', 'i', 'n', 'o', ' ', 'U', 'N', 'O', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Timed out.

Currently message received is in "got_time", so I see numerical value. When I change it to string I see "Hi..Arduino UNO" response. Problem is with timeout on the Raspberry. Raspberry sends message, Arduino receives it, Arduino should send confirmation of receipt of the message, Raspberry shows timeout of it. Can you guide me to the solution?

Arduino Nano code:

/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/

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

/****************** User Config *************************/ /* Set this radio as radio number 0 or 1 ***/ bool radioNumber = 1;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 / RF24 radio(9,10); /*********************************************************/

const uint64_t addresses[2] = { 0xE1E2E3E4E5LL, 0xE6E7E8E9E0LL }; // byte addresses[][6] = {"1Node","2Node"};

// Used to control whether this node is sending or receiving bool role = 0;

void setup() { Serial.begin(115200); printf_begin(); 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);

// radio.setRetries(15,15); radio.setPayloadSize(32); radio.setChannel(0x76); // radio.setPALevel(RF24_PA_MIN); // radio.setAutoAck(true);

// 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(); radio.printDetails(); }

void loop() {

/****************** Ping Out Role *************************/
if (role == 1) { /* Not used in this case */ } /
**************** 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( &amp;got_time, sizeof(unsigned long) );             // Get the payload
  }

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

}

/****************** Change Roles via Serial Commands **************************/ / Not used in this case */ } // Loop

Raspberry Pi 0 code:

import RPi.GPIO as GPIO  # import gpio
import time      #import time library
import spidev
from lib_nrf24 import NRF24   #import NRF24 library

GPIO.setmode(GPIO.BCM) # set the gpio mode

set the pipe address. this address shoeld be entered on the receiver alo

pipes = [[0xE1, 0xE2, 0xE3, 0xE4, 0xE5], [0xE6, 0xE7, 0xE8, 0xE9, 0xE0]] radio = NRF24(GPIO, spidev.SpiDev()) # use the gpio pins radio.begin(0, 25) # start the radio and set the ce,csn pin ce= GPIO08, csn= GPIO25 radio.setPayloadSize(32) #set the payload size as 32 bytes radio.setChannel(0x76) # set the channel as 76 hex radio.setDataRate(NRF24.BR_1MBPS) # set radio data rate radio.setPALevel(NRF24.PA_MIN) # set PA level

radio.setAutoAck(True) # set acknowledgement as true radio.enableDynamicPayloads() radio.enableAckPayload()

radio.openWritingPipe(pipes[0]) # open the defined pipe for writing radio.openReadingPipe(1,pipes[1]) # open the defined pipe for writing

radio.printDetails() # print basic detals of radio time.sleep(3)

sendMessage = list("Hi..Arduino UNO") #the message to be sent while len(sendMessage) < 32:
sendMessage.append(0) try: while True: start = time.time() #start the time for checking delivery time radio.write(sendMessage) # just write the message to radio print("Sent the message: {}".format(sendMessage)) # print a message after succesfull send radio.startListening() # Start listening the radio

while not radio.available(0):
  time.sleep(1/100)
  if time.time() - start &gt; 2:
    print(&quot;Timed out.&quot;)  # print errror message if radio disconnected or not functioning anymore
    break

radio.stopListening()     # close radio
time.sleep(3)  # give delay of 3 seconds

finally:
GPIO.cleanup() # this ensures a clean exit

Arduino console:

RF24/examples/GettingStarted
*** PRESS 'T' to begin transmitting to the other node
SPI Speedz   = 10 Mhz
STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xe6e7e8e9e0 0xe1e2e3e4e5
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0xe6e7e8e9e0
RX_PW_P0-6   = 0x10 0x10 0x00 0x00 0x00 0x00
EN_AA        = 0x3f
EN_RXADDR    = 0x02
RF_CH        = 0x76
RF_SETUP     = 0x03
CONFIG       = 0x0f
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model        = nRF24L01+
CRC Length   = 16 bits
PA Power     = PA_LOW
ARC      = 5
Sent response Hi..Arduino UNO
Sent response Hi..Arduino UNO
Sent response Hi..Arduino UNO
Sent response Hi..Arduino UNO

Raspberry Pi 0 console:

STATUS   = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     =
 0xe1e2e3e4e5 0xe6e7e8e9e0
RX_ADDR_P2-5     =
0xc3
0xc4
0xc5
0xc6

TX_ADDR = 0xe1e2e3e4e5 RX_PW_P0-6 = 0x10 0x10 0x00 0x00 0x00 0x00

EN_AA = 0x3f

EN_RXADDR = 0x03

RF_CH = 0x76

RF_SETUP = 0x01

CONFIG = 0x0f

DYNPD/FEATURE = 0x3f 0x06

Data Rate = 1MBPS Model = nRF24l01+ CRC Length = 16 bits PA Power = PA_MIN Timed out. Timed out. Timed out.

NezumiRyu
  • 31
  • 4

0 Answers0