Nano BLE serial send to regular nano wont work

hello,
reciever of data is always a regular nano, the sender should be a nano BLE, in the following referred to as "nano" and "BLE".
the following codes work fine, if the sender is a nano every. if its a BLE, no data is recieved.

sender:

int zahl1 = 42;
float zahl2 = 3.1415;
long zahl3 = 123456;

void setup() {
  Serial1.begin(9600);
  delay(2000); // wait for slave
}

void loop() {

  // In Zeichenketten konvertieren
  String strZahl1 = String(zahl1);
  String strZahl2 = String(zahl2, 4);
  String strZahl3 = String(zahl3);

// chars anlegen
  char c_zahl1[strZahl1.length()+1];
  char c_zahl2[strZahl2.length()+1];
  char c_zahl3[strZahl3.length()+1];

  // str in char-Arrays kopieren
  strZahl1.toCharArray(c_zahl1, sizeof(c_zahl1));
  strZahl2.toCharArray(c_zahl2, sizeof(c_zahl2));
  strZahl3.toCharArray(c_zahl3, sizeof(c_zahl3));

//Größe der gesamtstruktur
  unsigned int dataSize = sizeof(c_zahl1) + sizeof(c_zahl2) + sizeof(c_zahl3);
  String strdataSize = String(dataSize);
  char c_dataSize[strdataSize.length()+1];
  strdataSize.toCharArray(c_dataSize, sizeof(c_dataSize));

// senden
  Serial1.write(c_dataSize, sizeof(c_dataSize));
  Serial1.write(c_zahl1, sizeof(c_zahl1));
  Serial1.write(c_zahl2, sizeof(c_zahl2));
  Serial1.write(c_zahl3, sizeof(c_zahl3));

  delay(2000);
}

reciever:

char buf1[10];
char buf2[10];
char buf3[10];
char buf4[10];

void setup() {
  Serial.begin(9600);
}

void loop() {

  while (!Serial.available());

    Serial.readBytesUntil('\0', buf1, sizeof(buf1));
    Serial.readBytesUntil('\0', buf2, sizeof(buf2));
    Serial.readBytesUntil('\0', buf3, sizeof(buf3));
    Serial.readBytesUntil('\0', buf4, sizeof(buf4));

    Serial.print("Größe: "); Serial.println(buf1);
    Serial.print("Empfangene Zahl 1: "); Serial.println(buf2);
    Serial.print("Empfangene Zahl 2: "); Serial.println(buf3);
    Serial.print("Empfangene Zahl 3: "); Serial.println(buf4);
    Serial.println("");
  
}

same ground, connected only Tx (BLE) PIN 0 to Rx (nano) PIN 1, which is connected via USB to monitor the print outputs. the slave furthermore powers the master. l even put a level shifter module between the boards, which shouldt be necessary when sending from 3.3 to 5V.
any ideas?

You have the possibility that you destroyed the receiving port on the 3V3 device, possibly even more damage. It is the 5V to 3V3 that causes the problem as you connected both Tx and Rx. Post a simple schematic showing how these are interconnected, show all connections and power.

1 Like


there has never been a connection from 5V Tx to 3.3V Rx.

1 Like

Your Nano's RXD is being driven by the BLE, but the Nano also receives from the PC, on that same pin. Though some have reported success doing this, most find that at a minimum, the Serial Monitor content is corrupted by this. It may be that the BLE is completely blocked by the signal output from the USB-serial chip onboard the Nano.
Try bringing the BLE serial line in on another pin, and using SoftwareSerial to receive the output from the BLE.

1 Like

so i provided an independent power source for both boards with no USB cable attached, added a blink function to see if data came in, no success.
included softwareserial like this:

#include <SoftwareSerial.h>
SoftwareSerial Serial2(2, 3); // Rx, Tx
[...]
Serial2.readBytesUntil('\0', buf1, sizeof(buf1));
[...]

with the wire connected in D2, it recieves nothing, not even from a standard nano. with the wire connected to Rx, it recieves the correct data (from regular nano!), which should be impossible when reading at Serial2. nothing from BLE.

Nice pictures not much help. What is the Red Blob? The board on the right is not annotated. Try running a simple hello world type program on each by themselves and see if it works. That will verify the Tx signals. The Rx were verified when the code was uploaded. These pictures do not mean anything to me as I do not have the corresponding parts. Posting links to technical information on each part also helps get you a accurate answer.

Include your entire new code, please. We need to confirm you did what you said you did, without errors. Otherwise, we'll do the spin cycle some more.

sender:

int zahl1 = 42;
float zahl2 = 3.1415;

void setup() {
  Serial1.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  delay(2000);
}

void loop() {
  
  Serial1.flush();
  Serial1.write((byte*)&zahl1, sizeof(zahl1));
  blink();
  Serial1.write((byte*)&zahl2, sizeof(zahl2));
  blink();

  delay(2000);
}
void blink(void){
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}

reciever:

#include <SoftwareSerial.h>

SoftwareSerial Serial2(2,3);

int receivedZahl1;
float receivedZahl2;

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(2, INPUT);
}

void loop() {
  
  Serial2.flush();
  while (Serial2.available() < sizeof(receivedZahl1));
  Serial2.readBytes((char*)&receivedZahl1, sizeof(receivedZahl1));
  blink();
  while (Serial2.available() < sizeof(receivedZahl2));
  Serial2.readBytes((char*)&receivedZahl2, sizeof(receivedZahl2));
  blink();


  Serial.print("Empfangene Zahl 1: "); Serial.println(receivedZahl1);
  Serial.print("Empfangene Zahl 2: "); Serial.println(receivedZahl2, 4);
  Serial.println();

}
void blink(void){
  digitalWrite(LED_BUILTIN, HIGH);
  delay(100);
  digitalWrite(LED_BUILTIN, LOW);
  delay(100);
}

serial monitor:

Empfangene Zahl 1: 16457
Empfangene Zahl 2: 0.0000

Empfangene Zahl 1: 3670
Empfangene Zahl 2: 0.0000

Empfangene Zahl 1: 0
Empfangene Zahl 2: 3.1415

Empfangene Zahl 1: 42
Empfangene Zahl 2: 0.0000

that cycle repeats, so with softwareserial at least something happens. same outcome, if the signal goes over the level shifter:

describe how you start these two talking, because your receiving code has no method of ensuring it's starting with the int; if the talker was started before the receiver, you could be anywhere in the repeat transmission cycle.
Highly recommend

1 Like

i added a "starting sign" (<) to mark the beginning of a transmissing and it works now with softwareserial! that wasnt necessary with a regular nano or nano every as sender. but hardware serial still doesnt work, like the Rx port of the reciever is broken, but its not - if the sender is a nano every, like said, it works.

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