Getting 0 as a value from the nRF52840 through RX TX pins

Hello,
I get the value I want to get from nRF52840 but it also gives me the value 0 inbetween the real values.
What is the issue here?

nRF52840 code below,

#include <Arduino.h>
#include <Adafruit_TinyUSB.h>  
#include "LSM6DS3.h"
#include "Wire.h"

//Create a instance of class LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A);    //I2C device address 0x6A

void setup() {

  Serial.begin(115200);
  delay(1000);
  while (!Serial);
  //Call .begin() to configure the IMUs
  if (myIMU.begin() != 0) {
      Serial.println("Device error");
  } else {
      Serial.println("Device OK!");
  }
  Serial1.begin(115200);
  delay(1000);

}
void loop() {

    Serial.print("\nAccelerometer:\n");
    Serial.print(" X1 = ");
    Serial.println(myIMU.readFloatAccelX(), 4);


    value = myIMU.readFloatAccelX()


  Serial1.println(value);

  
  while(Serial1.available()>0) {

    char c = Serial1.read();
    Serial.print(c);
  }

}

ESP32S3 code below,


#include <HardwareSerial.h>
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>


WiFiMulti wiFiClient;


#define USE_SERIAL Serial
//WiFi connection
const char * WIFI_SSID ="777777";
const char * WIFI_PASSWORD = "yyyyyy";


HardwareSerial MySerial0(0);



void setup() {
  // USE_SERIAL.begin(921600);
USE_SERIAL.begin(115200);

  Serial.setTxTimeoutMs(0); // maybe needed for Serial.print()
  delay(500);
  wiFiClient.addAP(WIFI_SSID, WIFI_PASSWORD);

  // WiFi.disconnect();
  while(wiFiClient.run() != WL_CONNECTED) 
  {
    Serial.printf(".");
    delay(100);
  }

  Serial.printf("Connected to the WiFi!");

  MySerial0.begin(115200, SERIAL_8N1, -1, -1);  // default TX~D6 RX=D7
  delay(500);
}

int* readRXTXData(){
  
  if(MySerial0.available() > 0) {
      int temp_char = MySerial0.parseInt();
      Serial.print("TEMP CHAR ");
      Serial.println(temp_char);

}


void loop() {
  readRXTXData();

}

Thanks in advance.

Hi there,
Try "to flush the Serial port or, every time through the loop the print will print “C” empty or not.
Empty = 0
HTH
GL :slight_smile: PJ

Hi there,
Thanks for your response.
What do you exactly mean by “will print “C” empty or not” ?

Have a nice day.

Hit there,
SO first time through You see the green Arrow, Good Data from IMU,
Then in prints it,
And Now is in a polling loop waiting on Serial1 , the value of “C” variable.
Once you read the serial ports the buffer is empty.
You try and read again it’s ZERO. or NULL.
LOWER the baud rate. The default for IDE is 9600 anyway. No benefit to running higher than default, just makes Serial port data interrupts more often. less time to break out of a boot loop from bad code.
HTH
YMMV
GL :slight_smile: PJ
more simply put …
You are not receiving tons of 0’s. You are not receiving anything. Since you are not receiving anything, the global variable ‘C’ is not being changed from its default value: 0. Every time you look the value it is still 0. Did you only want to process each incoming byte once? If so:
do it like this.

void loop()
{
  if (Serial.available() > 0)
  {
    incomingByte = Serial.read();


    if (incomingByte != 0)
    {
      digitalWrite(13, HIGH);
    }
    else // if (incomingByte == 0)
    {
      digitalWrite(13, LOW);
      delay(1000);
      digitalWrite(13, HIGH);
    }


    Serial.println(incomingByte, DEC);
  }
}

Hi PJ,
I get it now.
Thank you very much!

Have a great day :slight_smile:

1 Like

Great, Pls mark as the solution so others can find it.
:wink: :v: