Seeeduino Xiao + nRF24L01+2.4G + MPU6050

Hello
I’d like to connect Seeeduino Xiao with nRF24L01+2.4G and MPU6050
to send x, y, z sensor values via nRF24L01 communication
I was doing it successfully with the code below, when I was testing with Arduino Nano boards
But I don’t have any idea where should I plug the pins with Seeeduino Xiao

Is there anyone who can explain the Pinouts?

RX
///////////////////////////////////////////////////////////////////////////

/*

Demonstrates simple RX and TX operation.
Any of the Basic_TX examples can be used as a transmitter.
Please read through 'NRFLite.h' for a description of all the methods available in the library.

Radio    Arduino
CE    -> 9
CSN   -> 10 (Hardware SPI SS)
MOSI  -> 11 (Hardware SPI MOSI)
MISO  -> 12 (Hardware SPI MISO)
SCK   -> 13 (Hardware SPI SCK)
IRQ   -> No connection
VCC   -> No more than 3.6 volts
GND   -> GND

*/

#include <SPI.h>
#include <NRFLite.h>

const static uint8_t RADIO_ID = 0;       // Our radio's id.  The transmitter will send to this id.
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;

struct RadioPacket // Any packet up to 32 bytes can be sent.
{
    uint8_t FromRadioId;
    uint32_t OnTimeMillis;
    uint32_t FailedTxCount;
    
    int AccelValueX;
    int AccelValueY;
    int AccelValueZ;
};

NRFLite _radio;
RadioPacket _radioData;

void setup()
{
    Serial.begin(115200);

    // By default, 'init' configures the radio to use a 2MBPS bitrate on channel 100 (channels 0-125 are valid).
    // Both the RX and TX radios must have the same bitrate and channel to communicate with each other.
    // You can run the 'ChannelScanner' example to help select the best channel for your environment.
    // You can assign a different bitrate and channel as shown below.
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE2MBPS, 100) // THE DEFAULT
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE1MBPS, 75)
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE250KBPS, 0)
    
    if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN))
    {
        Serial.println("Cannot communicate with radio");
        while (1); // Wait here forever.
    }
}

void loop()
{
    while (_radio.hasData())
    {
        _radio.readData(&_radioData); // Note how '&' must be placed in front of the variable name.

        String msg = "";

        msg += _radioData.AccelValueX;
        msg += " ";
        msg += _radioData.AccelValueY;
        msg += " ";
        msg += _radioData.AccelValueZ;
        
        Serial.println(msg);
    }
}

////////////////////////////////////////////////////////////////////////////////

TX
////////////////////////////////////////////////////////////////////////////////

/*

Demonstrates simple RX and TX operation.
Any of the Basic_RX examples can be used as a receiver.
Please read through 'NRFLite.h' for a description of all the methods available in the library.

Radio    Arduino
CE    -> 9
CSN   -> 10 (Hardware SPI SS)
MOSI  -> 11 (Hardware SPI MOSI)
MISO  -> 12 (Hardware SPI MISO)
SCK   -> 13 (Hardware SPI SCK)
IRQ   -> No connection
VCC   -> No more than 3.6 volts
GND   -> GND

*/

#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

#include <SPI.h>
#include <NRFLite.h>

const static uint8_t RADIO_ID = 1;             // Our radio's id.
const static uint8_t DESTINATION_RADIO_ID = 0; // Id of the radio we will transmit to.
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;

struct RadioPacket // Any packet up to 32 bytes can be sent.
{
    uint8_t FromRadioId;
    uint32_t OnTimeMillis;
    uint32_t FailedTxCount;
    
    int AccelValueX;
    int AccelValueY;
    int AccelValueZ;
};

NRFLite _radio;
RadioPacket _radioData;

void setup()
{
    Serial.begin(115200);
    
    // By default, 'init' configures the radio to use a 2MBPS bitrate on channel 100 (channels 0-125 are valid).
    // Both the RX and TX radios must have the same bitrate and channel to communicate with each other.
    // You can run the 'ChannelScanner' example to help select the best channel for your environment.
    // You can assign a different bitrate and channel as shown below.
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE2MBPS, 100) // THE DEFAULT
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE1MBPS, 75)
    //   _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE250KBPS, 0)
    Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
  
    if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN))
    {
        Serial.println("Cannot communicate with radio");
        while (1); // Wait here forever.
    }
    
    _radioData.FromRadioId = RADIO_ID;
}

void loop()
{
  mpu6050.update();
  
    _radioData.AccelValueX = mpu6050.getAngleX();
    _radioData.AccelValueY = mpu6050.getAngleY();
    _radioData.AccelValueZ = mpu6050.getAngleZ();

    Serial.print(_radioData.AccelValueX);
    Serial.print(" ");
    Serial.print(_radioData.AccelValueY);
    Serial.print(" ");
    Serial.print(_radioData.AccelValueZ);
    

    // By default, 'send' transmits data and waits for an acknowledgement.  If no acknowledgement is received,
    // it will try again up to 16 times.  This retry logic is built into the radio hardware itself, so it is very fast.
    // You can also perform a NO_ACK send that does not request an acknowledgement.  In this situation, the data packet
    // will only be transmitted a single time and there is no verification of delivery.  So NO_ACK sends are suited for
    // situations where performance is more important than reliability.
    //   _radio.send(DESTINATION_RADIO_ID, &_radioData, sizeof(_radioData), NRFLite::REQUIRE_ACK) // THE DEFAULT
    //   _radio.send(DESTINATION_RADIO_ID, &_radioData, sizeof(_radioData), NRFLite::NO_ACK)
    
    if (_radio.send(DESTINATION_RADIO_ID, &_radioData, sizeof(_radioData))) // Note how '&' must be placed in front of the variable name.
    {
        Serial.println("...Success");
    }
    else
    {
        Serial.println("...Failed");
        _radioData.FailedTxCount++;
    }


}

/////////////////////////////////////////////////////////////////////////////////////////

Is it a connection problem? Can you provide a photo? I can check it for you.

Thanks for your reply
Actually I was running Seeeduino xiao board and Arduino Nano Board
But I tried to run 2 Seeeduino Xiao board
And fortunately everything works fine
:slight_smile:

Hey Erikk,

Im working on the same kind of project but with just the xiao and nrf24l01 modules and a couple relays. What was your solution as to the correct pin connections from nrf to xiao and initial code setup?
On arduinos everything works perfectly, on the xiao im having troubles.

Thank you so much this is driving me nuts!

Hey Bmazey,
I have connected pin 6 as CE
pin 7 as CSN
And it Worked.
Here is example code of Rx

#include <SPI.h>
#include “RF24.h”

int msg = 0;
byte address[6] = “1Node”;

RF24 radio(6,7); // CE, CSN

void setup(void) {
Serial.begin(9600);
radio.begin();
/*
radio.setPALevel(RF24_PA_MAX); // MIN, LOW, HIGH, MAX
radio.setDataRate(RF24_250KBPS);
radio.setRetries(15,15);
radio.setCRCLength(RF24_CRC_16);
radio.setChannel(108);
*/
radio.openReadingPipe(1, address);
radio.startListening();
}

void loop(void) {
if(radio.available()) {
radio.read(&msg, sizeof(msg));
Serial.print("Meassage (RX) = ");
Serial.println(msg);
}
}

1 Like

Hey Erikk thank you man, I did get it working one of my nrf modules was busted. Thanks for the response man!

I have the same situation where I’m running a Seeeduino and an Arduino Nano and can’t get them to work. Unfortunately I’m not in a situation where I can run two Seeeduino’s.

My setup is as follows:

  • Arduino Nano as Master
  • Arduino Nano as Child
  • Seeeduino Xiao as Child

Both children run the exact same code and the master only receives the messages from the Arduino Nano Child. I triple checked the connections on the Xiao and I still can’t get a message through to the Master.

At this point any idea will do.
Thank you.


Update

The issue turned out to be that sizeof for int are different for the Arduino Nano and Seeeduino Xiao and I was sending a structure between them.

On the Seeeduino the sizeof my structure was exceeding the 32 byte payload limit. I’ve switched to uint-s and int-s standard sizes (uint8_t, int_16t, etc) and everything is working now.

Any idea why normal MPU6050.h does not compile and throws error for xiao but MPU6050_tockn.h compiles error free?

@Erikk @Bmazey hi, I am new to Seeduino xiao. I am trying to connect NRF24L01 + modules to my 2 seeduino xiao boards set up one as transmitter and other as Reciever. Can you please help me with the pin connections? I am not able to find which pin of the nrf module I should connect to the seeduino board.