question

fth-9527 avatar image
0 Votes"
fth-9527 asked SeeyaXi-msft answered

Send and receive data wirelessly with raspberry pi+nrf24l01

Hello there,

I am developing a project using raspberrypi b3 and nrf24l01.

I am developing via the link below. But I can't send data wirelessly in any way.

I'm not sure which pins are nrf24l01 and raspberrypi as I'm just starting out.

When I run it via the code block below, I am unable to send wireless data.

original link: https://github.com/techfooninja/Radios.RF24

Operating system: Windows 10 iot core


arduino pro mini -> arduino uno (I can send data wirelessly)
arduino pro mini -> raspberrypi (can't send)
raspberrypi -> arduino pro mini (can't send)


connecting pins on raspberry pi
raspberrypi nRF24l01 SENDER
nRF1
VCC - 3.3V (Best)
GND - GND
MOSI - SPI0 MOSI (GPIO 10)
MISO - SPI0 MISO (GPIO 9)
SCK - SPI0 SCLK (GPIO 11)
CSN - SPI0 CS0 (GPIO 8)
CE - GPIO 23
IRQ - GPIO 24

raspberrypi nRF24l01 RECEIVER
nRF2
VCC - 3.3V (Best)
GND - GND
MOSI - SPI1 MOSI (GPIO 20)
MISO - SPI1 MISO (GPIO 19)
SCK - SPI1 SCLK (GPIO 21)
CSN - SPI1 CS0 (GPIO 16)
CE - GPIO 5
IRQ - GPIO 6



c# raspberrypi code

 using Radios.RF24;
 using System;
 using System.Diagnostics;
 using System.Text;
 using Windows.UI.Core;
 using Windows.UI.Xaml;
 using Windows.UI.Xaml.Controls;
 using Windows.UI.Xaml.Navigation;
    
    
 namespace MyApplication.UWP
 {
     public sealed partial class MainPage : Page
     {
    
         private const byte CHANNEL = 76;
         private byte[] SENDER_NODE1 = Encoding.UTF8.GetBytes("F0F0F0F0E2AL");
         private byte[] RECEIVER_NODE2 = Encoding.UTF8.GetBytes("F0F0F0F0E1LL"); 
    
    
         public RF24 sender;
         public RF24 receiver;
         bool isInitialized = false;
    
         public MainPage()
         {
             this.InitializeComponent();
             SendButton.Click += ButtonSend_Click;
    
             DataRate.ItemsSource = Enum.GetValues(typeof(DataRate));
             PowerLevel.ItemsSource = Enum.GetValues(typeof(PowerLevel));
    
             sender = new RF24();
             sender.OnDataReceived += Radio_OnDataReceived;
             sender.OnTransmitFailed += Radio_OnTransmitFailed;
             sender.OnTransmitSuccess += Radio_OnTransmitSuccess;
    
             receiver = new RF24(); // 
             receiver.OnDataReceived += Radio_OnDataReceived;
             receiver.OnTransmitFailed += Radio_OnTransmitFailed;
             receiver.OnTransmitSuccess += Radio_OnTransmitSuccess;
    
             isInitialized = true;
         }
    
    
    
         protected override async void OnNavigatedTo(NavigationEventArgs e)
         {
             await sender.Initialize(23, 0, 24, "SPI0");
             await receiver.Initialize(5, 0, 6, "SPI1");
    
             sender.IsEnabled = true;
             receiver.IsEnabled = true;
    
             sender.Channel = CHANNEL;
             sender.Address = SENDER_NODE1;
    
             receiver.Channel = CHANNEL;
             receiver.Address = RECEIVER_NODE2;
                
    
    
             //Sender
             Debug.WriteLine("Address: " + Encoding.UTF8.GetString(sender.Address));
             Debug.WriteLine("PA: " + sender.PowerLevel);
             Debug.WriteLine("IsAutoAcknowledge: " + sender.IsAutoAcknowledge);
             Debug.WriteLine("Channel: " + sender.Channel);
             Debug.WriteLine("DataRate: " + sender.DataRate);
             Debug.WriteLine("IsDynamicAcknowledge: " + sender.IsDyanmicAcknowledge);
             Debug.WriteLine("IsDynamicPayload: " + sender.IsDynamicPayload);
             Debug.WriteLine("IsEnabled: " + sender.IsEnabled);
             Debug.WriteLine("Frequency: " + sender.Frequency);
             Debug.WriteLine("IsInitialized: " + sender.IsInitialized);
             Debug.WriteLine("IsPowered: " + sender.IsPowered);
    
             //Receiver
             Debug.WriteLine("Address: " + Encoding.UTF8.GetString(receiver.Address));
             Debug.WriteLine("PA: " + receiver.PowerLevel);
             Debug.WriteLine("IsAutoAcknowledge: " + receiver.IsAutoAcknowledge);
             Debug.WriteLine("Channel: " + receiver.Channel);
             Debug.WriteLine("DataRate: " + receiver.DataRate);
             Debug.WriteLine("IsDynamicAcknowledge: " + receiver.IsDyanmicAcknowledge);
             Debug.WriteLine("IsDynamicPayload: " + receiver.IsDynamicPayload);
             Debug.WriteLine("IsEnabled: " + receiver.IsEnabled);
             Debug.WriteLine("Frequency: " + receiver.Frequency);
             Debug.WriteLine("IsInitialized: " + receiver.IsInitialized);
             Debug.WriteLine("IsPowered: " + receiver.IsPowered);
         }
    
         private void ButtonSend_Click(object sender1, RoutedEventArgs e)
         {
             var addr = Encoding.UTF8.GetBytes(SendToAddress.Text);
             Array.Reverse(addr);
    
             sender.SendTo(RECEIVER_NODE2, Encoding.UTF8.GetBytes(SendBuffer.Text));
         }
    
         private void Radio_OnTransmitSuccess()
         {
             Debug.WriteLine("Transmit Succeeded!");
             if (isInitialized)
                 Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SendStatus.Text = "Transmit Succeeded");
         }
    
         private void Radio_OnTransmitFailed()
         {
             Debug.WriteLine("Transmit FAILED");
             if (isInitialized)
                 Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => SendStatus.Text = "Transmit FAILED");
         }
    
         private void Radio_OnDataReceived(byte[] data)
         {
             Debug.WriteLine("Received: " + Encoding.UTF8.GetString(data));
             if (isInitialized)
                 Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => ReceiveBuffer.Text = Encoding.UTF8.GetString(data));
         }
     }
 }


Arduino pro mini code

 #include <SPI.h>
 #include <nRF24L01.h>
 #include <RF24.h>
 #include "printf.h"
    
 RF24 radio (9, 10); //yours
 const uint64_t devices[3] = { 0xF0F0F0F0E1AL, 0xF0F0F0F0E1LL, 0xF0F0F0F0E3CL };
 struct dataStruct {int p1; int t1; int s1;} transmitter2_data;
    
 void setup()
 {
   radio.begin();
   radio.setChannel(76);
   Serial.begin(9600);
   printf_begin();
   radio.setRetries(15, 15);
   radio.enableDynamicPayloads();
   radio.setDataRate(RF24_2MBPS);
      
   radio.openWritingPipe(devices[0]);
   radio.openWritingPipe(devices[1]);
   radio.openWritingPipe(devices[2]);
      
   radio.stopListening();
   radio.printDetails();
 }
    
 void loop()
 {
   transmitter2_data.p1 = 300;
   transmitter2_data.t1 = 400;
   transmitter2_data.s1 = 500;
    
   bool ok = radio.write(&transmitter2_data, sizeof(transmitter2_data));
    
   if (ok)
   {
     Serial.println("ProMini 2");
     Serial.println(transmitter2_data.p1);
     Serial.println(transmitter2_data.t1);
     Serial.println(transmitter2_data.s1);
   }
   else
   {
     Serial.println("it failed to send");
   }
   delay(1000);
 }






windows-iot-10core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SeeyaXi-msft avatar image
0 Votes"
SeeyaXi-msft answered

Hi @fth-9527,

Did you execute the process like this: https://www.tomshardware.com/how-to/use-raspberry-pi-with-arduino
Please refer to it.

Best regards,
Seeya


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.