Esp32 serial2 to photon serial

Hello to all.

Having an issue with reading the serial2 of an esp32 TTGO LoRa board connected to a Photon serial1

Some assistance would be appreciated.

#include <blynk.h>
#include "Particle.h"
#include <Arduino.h>                             
#include <ArduinoJson.h>                           

SYSTEM_MODE(MANUAL)
SYSTEM_THREAD(ENABLED);

char auth[] = "XXXXX";

StaticJsonDocument<200> doc;                            

#define ESP32_PORT Serial1    // Photon tx to esp32 rx2 GPIO16 and Photon rx to esp32 tx2 GPIO17

float val1 = 0.0;
float val2 = 0.0;
float val3 = 0.0;
String conn = "";

#define BLYNK_PRINT Serial

WidgetTerminal terminal(V21);

unsigned long lastmillis = 0;

void setup() {
  Serial.begin(115200);
  ESP32_PORT.begin(115200);                            // LORA
  WiFi.on();
  WiFi.connect();
  waitFor(WiFi.ready, 90000);
  Blynk.config(auth);
  Particle.process();
  Particle.connect();
  Blynk.connect(); 
  System.enableUpdates();
}

void print_a_value(String name , String val){                            // LORA
    Serial.print(name);
    Serial.print(" : ");
    Serial.println(val);
}

void loop(){
  static uint32_t ms500 = 0;
  if (millis() - ms500 < 500) return;
  ms500 = millis();
  Particle.process();
  terminal_task();  
  Blynk.run();
  
if(ESP32_PORT.available() > 0){                            // LORA
        String incoming  = ESP32_PORT.readString();

        deserializeJson(doc, incoming);
        
        val1 = doc["v1"];
    //    val2 = doc["v2"];
    //    val3 = doc["v3"];
        conn = (const char*)doc["status"];
        
        print_a_value("value 1" , String(val1));
    //    print_a_value("value 2" , String(val2));
    //    print_a_value("value 3" , String(val3));
        print_a_value("connection status" , conn);
        Serial.println("\r\n");
     }
}


void terminal_task(){
    if ((millis() - lastmillis) > 2000) 
  {
   lastmillis = millis();
 
        terminal.println();
        terminal.print("LoRa val1: = " );
        terminal.print(val1);
        terminal.println();
        terminal.print("Status: = " );
        terminal.print(conn);
        
        terminal.println();
        terminal.flush();  
  }
}

Some more elaborate symptom description would be helpful.
Also an absolute minimum test script would be much better to tackle a specific issue - don’t add anything to the test that doesn’t immediately belong to the topic at hand.

Thanks ScruffR. Will do that later.

#include <Arduino.h>                             
#include <ArduinoJson.h>                           

SYSTEM_MODE(MANUAL)
SYSTEM_THREAD(ENABLED);

StaticJsonDocument<200> doc;                            

#define ESP32_PORT Serial1    // Photon tx to esp32 rx2 GPIO16 and Photon rx to esp32 tx2 GPIO17

float val1 = 0.0;
String conn = "";

void setup() {
  Serial.begin(115200);
  ESP32_PORT.begin(115200);                            
  WiFi.on();
  WiFi.connect();
  waitFor(WiFi.ready, 90000);
  Particle.process();
  Particle.connect();
  System.enableUpdates();
}

void print_a_value(String name , String val){                            
    Serial.print(name);
    Serial.print(" : ");
    Serial.println(val);
}

void loop(){
  static uint32_t ms500 = 0;
  if (millis() - ms500 < 500) return;
  ms500 = millis();
  Particle.process();

if(ESP32_PORT.available() > 0){                            
        String incoming  = ESP32_PORT.readString();

        deserializeJson(doc, incoming);
        
        val1 = doc["v1"];
        conn = (const char*)doc["status"];
        
        print_a_value("value 1" , String(val1));
        print_a_value("connection status" , conn);
        Serial.println("\r\n");
     }
}

particle serial monitor only displays val1 0.00000 and nothing for conn

When I said something about minimal test script I was rather thinking of something along this line :wink:

void setup() {
    Serial.begin();
    Serial1.begin(115200);
    while(Serial.read()  >= 0);    // flush Serial  input buffer
    while(Serial1.read() >= 0);    // flush Serial1 input buffer
}

void loop() {
    if (Serial.available()) Serial1.write(Serial.read());
    if (Serial1.available()) Serial.write(Serial1.read());
}

This will pass through USB Serial to Serial1 and vice versa.
Hence you can send and receive via any serial terminal on your computer to and from the ESP32.
When you then also post your ESP32 code we might see whether the issue is coming from that side.

3 Likes