Why is my transmitted information all garbled up using 2 UART NRF24L01 module?

The modules are the following: NRF24L01...? - Album on Imgur This is their respective AlieExpress page: https://aliexpress.com/item/4000317884559.html?gatewayAdapt=glo2nld I am trying to send test through C# to my Arduino but once I actually send it over, the following is being received:

`teeeeeeeesetts
etts
eteeeeeeeeeeeeeeeeeeeeeeeeeeeeeestttt

ttttttteeeeeeeeeeeee`

This tells me that the connection works and data is actually being received but there's something wrong with either sending or receiving. I'm personally guessing something being wrong with sending but I'm not sure.

What could I try in order to receive just plain "test"?

The C# code:

using System.IO.Ports;

namespace ArduinoCom

{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort port = new SerialPort("COM3", 115200, Parity.None, 6);

            port.Open();
            bool run = true;
            int counter = 0;

        for (int i = 0; i < 1000; i++)
        {
            port.Write("test\n");
        }
        port.Dispose();
        port.Close();
       }
    } 
}

The Arduino code is as follows:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <I2C_LCD.h>

I2C_LCD LCD;
uint8_t I2C_LCD_ADDRESS = 0x51; //Device address setting, default: 0x51
SoftwareSerial mySerial(0, 1); // RX, TX

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

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

}

void loop() {
  LCD.CleanAll(WHITE);
  LCD.FontModeConf(Font_6x8, FM_ANL_AAA, BLACK_BAC);
  if (Serial1.available()) {
      {
        Serial.print((char)Serial1.read());
        LCD.DispStringAt((char)Serial1.read(), 0, 10);
      }
  }
}

I suggest that you write the C# code to send a "test" message every second or so instead of blasting out 1000 "test"s (if i read the C# code correctly). The receive buffer may not be able to keep up.

Please post a schematic.

Do you really need the RF24 library?

Why the SoftwareSerial? It is not used.

#include <SoftwareSerial.h>
is indeed included, and yes, I figured it had to do with timing. I also secretly hoped that blasting would've worked but I've come to terms with it:

            string[] tx = new string[5] { "t", "e", "s", "t", "\n" };

            for (int i = 0; i < 4; i++)
            {
                port.Write(tx[i]);
                System.Threading.Thread.Sleep(300);
            }

This seems to have fixed the issue, it might simply be not possible to receive entire strings and as such, this facilitated a sure fire way to receive everything in the right order.

My next step is to generalise the input and figure out how I can bind the 1 by 1 received serial input to a value or array within the Arduino

In the RF24 code that I write, there is a 32 byte limit to the size of a packet. I am not sure if that limit is because of the library or if it is because of the rf24 chips themselves. You may want to investigate that.

There is also the size of the serial receive buffer. I think, for most Arduinos, that that size is 64 bytes.

I believe that it's the chip that imposes that 32 byte limit on the payload. My datasheet for the nRF24L01 chip says:

7.3.4 Payload
The payload is the user defined content of the packet. It can be 0 to 32 bytes wide and is transmitted on-air when it is uploaded to nRF24L01+.

Right, I have to admit that I have not read the data sheet in detail.

The buffer sizes is something to keep in mind.

The serial input basics tutorial may be of interest.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.