Serial connection to from ESP 32 (TTGO LoRa 32) to Raspberry Pi (with RS 485 Hat)

I am trying to receive data serially to my ESP32 TTGO LoRa 32 Board from the Raspberry Pi that has a RS 485 hat mounted on it. I am not sure how exactly I am supposed to establish the serial communication on both sides. I am planning to connect the GPIO pins 1 and 3 (Tx and Rx) to the Rx and Tx pins of the RS 485 hat. The board powers up fine and everything.

For the esp32, I have seen 'EspSoftwareSerial' library can be used to set up the serial communication but the examples they have provided are for the esp8266 and I do not understand how hard code the entire program for this.

For the raspberry Pi, I don't think this is the right forum to ask for the help but any guidance on the project would be much appreciated. RS485 Hat for anyone curious.

The aim of this project is for me to mount a HC-SR04 ultrasonic sensor on the Raspberry Pi hat and then data serially to the esp32 to transmit it to TTN over LoRaWan. Yes, I know this isn't a good way but this is what my supervisor has asked me to complete.

Thank you.

avoid using pins 1 U0_TXD and 3 U0_RXD as they are used by the USB-UART for programming the device and the Serial monitor
pins16 U2_RXD and 17 U2-TXD work OK as Serial1 and you could connect the RS484 module to these

you do not find examples of EspSoftwareSerial for the ERSP32 as they do not require it
the ESP32 has three hardware serial ports - one is used for Serial but Serial1 and Serial2 are available and may be mapped for specific pins, e.g.

#define RXD1 16 // can map Serial1 and Serial2 to many ESP32 GPIO pins
#define TXD1 17 // check pin usage https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);

is it a requirement to use RS485, e.g. is the RPi a long way from the ESP32?
you could

  1. connect the ESP32 Serial1 directly to the RPi GPIO14 (UART TX) and GPIO15 (UART RX)
  2. plug the ESP32 USB into a RPi USB port - it will create a serial port, e.g. /dev/ttyUSB0

what programming language are you planning to use on the RPi?
I tend to use Java but C++, Python, etc will communicate with serial ports OK

be simpler to get a LoRa HAT for the RPi

1 Like
  1. plug the ESP32 USB into a RPi USB port - it will create a serial port, e.g. /dev/ttyUSB0

Thank you for the reply. Ended up going with the USB since the connection is much more stable as opposed to the UART pins that get loosened and detached from the LoRa32 board. Was able to establish the connection.

is it a requirement to use RS485, e.g. is the RPi a long way from the ESP32?

Actually as you mentioned, there is no need to use the RS 485 too since I could directly pair it up with the RPi. The RS485 is the HAT version, so it is mounted on the RPi. but I didn't need that.

Thank you.

if you can avoid jumper leads do so - they are a source of poor connections and intermittent problems often leading to system crashes and resets

looking at post 1 you mention using a HC-SR04 on the RPi
you trigger the device and wait for the echo measuring the time difference
the RPi runs a multi-tasking operating system - how do you intend to measure time if your program is being interrupted by other tasks?

some years ago I built a radar demonstrator where a UNO used a HC-SR04 to measure distances to objects (the HC-SR04 rotated using a stepper motor)
the resultant distances were transmitted to a RPi 3B+ for display on a large monitor

looking at post 1 you mention using a HC-SR04 on the RPi
you trigger the device and wait for the echo measuring the time difference
the RPi runs a multi-tasking operating system - how do you intend to measure time if your program is being interrupted by other tasks?

Yes, after doing some research I found out that the Linux OS isn't that suitable for measuring the sensors. As of now, I am working on another project too. I have informed about this to my supervisor. Perhaps they will provide me with another device or simply another esp32 or Wifi ESP32 devkit with an expansion board for the project (I used that board to test the ultrasonic sensor earlier and worked like a charm).

Thank you

consider using a sensor on the RPi which is not time critical such as the BME280 Temperature, Humidity, and Pressure and transmitting the data to the TTGO LoRa 32 for transmission over LoRa - you would have to connect the BME280 to the I2C bus
make sure there is a suitable library for the RPi or you will end up having the implement low-level IO code

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