Particle Boron LTE + Adafruit Huzzah32/ESP32 - Serial/UART

I have a Particle Boron and Adafruit Huzzah32/ESP32 which are connected through Serial/UART:

Boron TX pin connected to Huzzah32/ESP32 RX pin
and
Boron RX pin connected to Huzzah32/ESP32 TX pin

I can’t find any example how to send a simple number lets say “123” from Boron to Huzzah32/32 and back. Just looking for simple working example, nothing complicated.

Thank you.

Welcome to the community.
What you are looking for is doable and it wouldn't matter whether you are talking to a ESP32 or another Particle device. As long as both sides don't exceed the voltage limit of the respectively other you can connect any micro with any other via UART.

Having said that, have you searched the forum before posting as this is a rather common question?
This would be a tip stated in this Forum Etiquette post.

e.g. these threads would have come up

I can’t get it to work, it’s my 3rd day of struggle, information is very misleading.
I noticed there is a difference between Arduino UNO/Mega/ESP32 the way code is written and read by boards.

I’m trying to make it as simple as possible.

ESP is a transmitter:

int A = 9;

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

void loop()
{
  Serial.write(A);
  delay(1000);
}

Boron is a receiver

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

int B;

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

void loop()
{

  if (Serial1.available())
  {
    B = Serial1.read();
    Serial.print("Value is: " + String(B));
  }
}

Where is my mistake? Thank you

I’d have to look into the ESP32 jargon but I’d think that Serial also refers to the USB Serial interface there as it does on the Particle devices.
I thing with the Adafruit Huzzah32 it’s also Serial1.

A simple test would be to start with loop-back communication. Just connect RX and TX on the same board and read back the data you send out of the device itself.

Also how have you connected the two controlers?
Do you have common GND between the two?
Have you got TX->RX and vice versa?

BTW, since between iterations of loop() other things might be happening it’s better to use while(Serial1.available()) instead of if()

It was a good idea to connect RX to TX, I was able to troubleshoot.

Everything is working now, here is a code for:

Boron is transmitting to ESP32

/*****************************************************************************
 * Serial Communication between Particle Boron and Adafruit Huzzah32 
 * Upload this sketch to Particle Boron
 * You can loop pin TX with RX to test it on Boron itself
 * 
 * Using Serial1
 * PIN RX = 10
 * PIN TX = 9
*****************************************************************************/

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

int counter;

//char example1[11] = "Example(1)";
char example1[14] = ">> From Boron";

void setup()
{
  delay(1000);
  Serial.begin(9600);
  Serial1.begin(115200);

  Serial.println();
  Serial.println("Serial1 RX/Pin: " + String(RX));
  Serial.println("Serial1 TX/Pin: " + String(TX));
  Serial.println();
  Serial1.flush();
  delay(1000);
}

void loop()
{

  //Example 1
  Serial1.write(example1);
  //Serial1.print(example1);

  //Example 2
  //Serial1.write("Example(2)");
  //Serial1.print("Example(2)");

  delay(2000);

  while (Serial1.available() && counter == 0)
  {

    for (counter = 0; counter <= 12; counter++)
    {
      Serial.print(char(Serial1.read()));
      delay(100);
    }
  }

  counter = 0;
  Serial.println("\nFlushing Serial");
  Serial1.flush();
  Serial.println();
  delay(2000);
}

ESP32 is transmitting to Boron

/*****************************************************************************
 * Serial Communication between Adafruit Huzzah32 and Particle Boron
 * Upload this sketch to Adafruit Huzzah32
 * You can loop pin TX with RX to test it on Adafruit Huzzah32 itself
 *
 * Using Serial2
 * PIN RX = 16
 * PIN TX = 17
*****************************************************************************/

#define RXD2 16
#define TXD2 17

int counter;
//char example1[11] = "Example(1)";
char example1[14] = ">> From ESP32";

void setup()
{
  delay(1000);
  Serial.begin(9600);
  Serial2.begin(115200);

  Serial.println();
  Serial.println("Serial1 RX/Pin: " + String(RX));
  Serial.println("Serial1 TX/Pin: " + String(TX));
  Serial.println("Serial2 RX/Pin: " + String(RXD2));
  Serial.println("Serial2 TX/Pin: " + String(TXD2));
  Serial.println();
  Serial2.flush();
  delay(1000);
}

void loop()
{

  //Example 1
  Serial2.write(example1);
  //Serial1.print(example1);

  //Example 2
  //Serial1.write("Example(2)");
  //Serial1.print("Example(2)");

  delay(2000);
  while (Serial2.available() && counter == 0)
  {

    for (counter = 0; counter <= 12; counter++)
    {
      Serial.print(char(Serial2.read()));
      delay(100);
    }
  }

  counter = 0;
  Serial.println("\nFlushing Serial");
  Serial2.flush();
  Serial.println();
  delay(2000);
}
1 Like