Serial Between Seeedstudio XIAO nRF52840 and Lolin Wemos D1 Mini Pro ESP8266

// Lolin WEMOS D1 Mini Pro ESP8266:

#include <SoftwareSerial.h>
#include <Wire.h>
#include "SparkFunHTU21D.h"

#define RX (12)
#define TX (1)

#define BAUD_RATE 9600
#define MAX_FRAMEBITS (1 + 8 + 1 + 2)

EspSoftwareSerial::UART testSerial;

HTU21D myHumidity;
int getarPin = 15;
char ip;

// Becomes set from ISR / IRQ callback function.
std::atomic<bool> rxPending(false);

void IRAM_ATTR receiveHandler() {
	rxPending.store(true);
	esp_schedule();
}

void setup() {
	Serial.begin(9600);
  pinMode(getarPin,INPUT);
  myHumidity.begin();
	Serial.setDebugOutput(false);
	Serial.swap();
	testSerial.begin(BAUD_RATE, EspSoftwareSerial::SWSERIAL_8N1, RX, TX);
	// Only half duplex this way, but reliable TX timings for high bps
	testSerial.enableIntTx(false);
	testSerial.onReceive(receiveHandler);

	testSerial.println(PSTR("\nSoftware serial onReceive() event test started"));

	for (char ch = ' '; ch <= 'z'; ch++) {
		testSerial.write(ch);
	}
	testSerial.println();
}

void loop() {
#ifdef ESP8266
	bool isRxPending = rxPending.load();
	if (isRxPending) {
		rxPending.store(false);
	}
#else
	bool isRxPending = m_isrOverflow.exchange(false);
#endif
	auto avail = testSerial.available();
	if (isRxPending && !avail) {
		// event fired on start bit, wait until first stop bit of longest frame
		delayMicroseconds(1 + MAX_FRAMEBITS * 1000000 / BAUD_RATE);
		avail = testSerial.available();
	}
	if (!avail) {
		// On development board, idle power draw at USB:
		// with yield() 77mA, 385mW (160MHz: 82mA, 410mW)
		// with esp_suspend() 20mA, 100mW (at 160MHz, too)
		//yield();
		esp_suspend();
		return;
	}
	// try to force to half-duplex
	decltype(avail) prev_avail;
	do {
		delayMicroseconds(1 + MAX_FRAMEBITS * 1000000 / BAUD_RATE);
		prev_avail = avail;
	} while (prev_avail != (avail = testSerial.available()));
	while (avail > 0) {
		testSerial.write(testSerial.read());
		avail = testSerial.available();
	}

  float humd = myHumidity.readHumidity();
  float temp = myHumidity.readTemperature();
  int getarData = digitalRead(getarPin);
  int smokeValue = analogRead(A0);


  testSerial.print("Time:");
  testSerial.print(millis());
  testSerial.print(" Temperature:");
  testSerial.print(temp, 1);
  testSerial.print("C");
  testSerial.print(" Humidity:");
  testSerial.print(humd, 1);
  testSerial.print("%");
  testSerial.print(" Getar Data:");
  testSerial.println(getarData);
  testSerial.print(" Smoke Data:");
  testSerial.println(smokeValue);

	testSerial.println();
}

I am trying do serial communication between Lolin Wemos D1 Mini Pro as Receiver and SeeedStudio XIAO nRF52840 Sense as Transmitter. How to make my data from transmitter as a variable, so I can show it in serial monitor with USB?

I want to show like bellow:

Time:378243 Temperature:31.9C Humidity:55.5% Getar Data:0
 Smoke Data:166 MyData From TX: Data

The title of the topic is "Serial Between Arduino and ESP8266". What is your arduino board?

I'm sorry, I have changed itt

Thank you

not sure about using pin 1 as TX - have a look at esp8266-pinout-reference-gpios
I have used GPIO14 and GPIO12 OK on the ESP8266, e.g.


// ESP8266 SoftwareSerial
// https://circuits4you.com/2016/12/14/software-serial-esp8266/

#include <SoftwareSerial.h>

// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6) 
 SoftwareSerial swSer(D5, D6);//14, 12);  

void setup() {
  Serial.begin(115200);   //Initialize hardware serial with baudrate of 115200
  swSer.begin(9600);    //Initialize software serial with baudrate of 115200
  Serial.println("\nESP8266 Software serial test started");
}

void loop() {
  while (swSer.available() > 0) {  //wait for data at software serial
    Serial.write(swSer.read()); //Send data recived from software serial to hardware serial    
  }
  while (Serial.available() > 0) { //wait for data at hardware serial
    swSer.write(Serial.read());     //send data recived from hardware serial to software serial
  }
}

also make sure you install espsoftwareserial

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