ESP32-C3-DevKitM-1 and #include<SoftwareSerial.h

Hi everyone.

I want to use ESP-C3-DevkitM-1 with softwareserial.h library
ESP32-C3-DevKitM-1 - ESP32-C3 - — ESP-IDF Programming Guide latest documentation (espressif.com)

#include<SoftwareSerial.h>
SoftwareSerial mySerial(5, 6);//

I already downloaded library of #include<SoftwareSerial.h
I think pin 5 and 6 of ESP32-C3-DevKitM-1 is not work.

Could you recommend me about pin for SoftwareSerial mySerial ?

Hi

Actually, I run this code on Arduino MEGA. It is success.

But I don't know how to run on ESP32

#include<SoftwareSerial.h>
SoftwareSerial mySerial(12, 13);// RX, TX  - 12 yellow  13 white(this is check ok)
//COMMANDS FROM DATASHEETs
byte auto_baud = 0x55;
byte continous_exit = 0x58;
byte rd_status[5] = {0xAA, 0x80, 0x00, 0x00, 0x80}; 
byte rd_hw[5] = {0xAA, 0x80, 0x00, 0x0A, 0x8A};
byte rd_sw[5] = {0xAA, 0x80, 0x00, 0x0C, 0x8C};
byte rd_sn[5] = {0xAA, 0x80, 0x00, 0x0E, 0x8E};
byte rd_vo[5] = {0xAA, 0x80, 0x00, 0x06, 0x86};
byte rd_meas[5] ={0xAA, 0x80, 0x00, 0x22, 0xA2};
byte laser_on[9] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x01, 0xC1};   
byte laser_off[9]  = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0xC0};  
byte one_shot_auto[9]  = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};
byte continous_fast[9]  = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x06, 0x27};
//VARs FOR WORKING WITH DATA
unsigned long  Data = 0;
byte Read[13];
//
void setup() {
  //Serial is comms with computer & mySerial comms with sensor
  Serial.begin(19200);//Baudrate with computer
  pinMode(8, OUTPUT);
  digitalWrite(8, LOW);
  delay(1000);
  Serial.println(" ");
  Serial.println("M88 SERIES LASER SENSOR.......");
  Serial.println("Serial ports OPEN");
  digitalWrite(8, HIGH);
  delay(1000);
  Serial.println("Sensor ON");
  Serial.println("wait..."); 
  mySerial.begin(19200);//Baudrate for comms with sensor
  mySerial.setTimeout(0.001);
  while (mySerial.read()!= 0x00) {}
  Serial.println("ok");
  mySerial.write(0x55);//auto baudrate commas
  delay(100);
  //test ON and OFF pointer
  Serial.println("LASER POINT ON...");
  mySerial.write(laser_on, 9);
  delay(1000);
  Serial.println("LASER POINT OFF...");
  mySerial.write(laser_off, 9);
  delay(200);
}
void loop() {
  Serial.println("read one shot mode: ");
  Data = 0;
  mySerial.write(one_shot_auto, 9); // Send command to sensor
  //
  //Received command in HEX format
  while (mySerial.available()>0){
  mySerial.readBytes(Read,13);
  }
  //
  //Print Data for test
  Serial.println(" ");
  Serial.print("dato trama en HEX:");
  for (int i = 0; i <= 12; i++){
  Serial.print(Read[i],HEX);  
  }
  //Print only measure data
  Serial.println(" ");
  Serial.print("dato medida en HEX:");
  for (int i = 6; i <= 9; i++){
  Serial.print(Read[i], HEX);
  }

esp32 has multiple hardware serials, why do you need a softserial?

And it seems that for ESP32 you should use another library

Not sure they are exposed on that Dev board.

Hi

Actually, I run this code on Arduino MEGA. It is success.

But I don't know how to run on ESP32

#include<SoftwareSerial.h>
SoftwareSerial mySerial(12, 13);// RX, TX  - 12 yellow  13 white(this is check ok)
//COMMANDS FROM DATASHEETs
byte auto_baud = 0x55;
byte continous_exit = 0x58;
byte rd_status[5] = {0xAA, 0x80, 0x00, 0x00, 0x80}; 
byte rd_hw[5] = {0xAA, 0x80, 0x00, 0x0A, 0x8A};
byte rd_sw[5] = {0xAA, 0x80, 0x00, 0x0C, 0x8C};
byte rd_sn[5] = {0xAA, 0x80, 0x00, 0x0E, 0x8E};
byte rd_vo[5] = {0xAA, 0x80, 0x00, 0x06, 0x86};
byte rd_meas[5] ={0xAA, 0x80, 0x00, 0x22, 0xA2};
byte laser_on[9] = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x01, 0xC1};   
byte laser_off[9]  = {0xAA, 0x00, 0x01, 0xBE, 0x00, 0x01, 0x00, 0x00, 0xC0};  
byte one_shot_auto[9]  = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x21};
byte continous_fast[9]  = {0xAA, 0x00, 0x00, 0x20, 0x00, 0x01, 0x00, 0x06, 0x27};
//VARs FOR WORKING WITH DATA
unsigned long  Data = 0;
byte Read[13];
//
void setup() {
  //Serial is comms with computer & mySerial comms with sensor
  Serial.begin(115200);//Baudrate with computer
  pinMode(34, OUTPUT);
  digitalWrite(34, LOW);
  delay(1000);
  Serial.println(" ");
  Serial.println("M88 SERIES LASER SENSOR.......");
  Serial.println("Serial ports OPEN");
  digitalWrite(34, HIGH);
  delay(1000);
  Serial.println("Sensor ON");
  Serial.println("wait..."); 
  mySerial.begin(19200);//Baudrate for comms with sensor
  //mySerial.setTimeout(0.001);
  while (mySerial.read()!= 0x00) {}
  Serial.println("ok");
 // mySerial.write(0x55);//auto baudrate commas
  delay(100);
  //test ON and OFF pointer
  Serial.println("LASER POINT ON...");
  mySerial.write(laser_on, 9);
  delay(1000);
  Serial.println("LASER POINT OFF...");
  mySerial.write(laser_off, 9);
  delay(200);
}
void loop() {

  
 
  Serial.println("read one shot mode: ");
  Data = 0;
  mySerial.write(continous_fast, 9); // Send command to sensor
  //
  //Received command in HEX format
  while (mySerial.available()>0){
  mySerial.readBytes(Read,13);
  
  }
  //
  
  
  //Print Data for test
  Serial.println(" ");
  Serial.print("dato trama en HEX:");
  for (int i = 0; i <= 12; i++){
  Serial.print(Read[i],HEX);  
  }
  //Print only measure data
  Serial.println(" ");
  Serial.print("dato medida en HEX:");
  for (int i = 6; i <= 9; i++){
  Serial.print(Read[i], HEX);
  }
  
  // If you want convert to Decimal
 for (int i = 6; i <= 9; i++){
  Data = (Data |= Read[i]) << 8 ;
  }
  Data = Data >> 8;
  //Print in mm
  Serial.println(" ");
  Serial.print("MEDIDA EN mm: "); 
  Serial.println(Data, DEC);
  delay(1000);  
}

https://esp32.com/viewtopic.php?f=19&t=22682

I uploaded coding as above.
Actually, I run this code on Arduino MEGA. It is success.

But I don't know how to run on ESP32

The ESP32 is not the problem. The board you are using does not appear to expose the additional serial ports.

use the ESP32's software serial library.

I've tried ESPSoftwareSerial with all the pins on ESP32-C3-12F (from AiThinker), nothing works.

Can init, but no data when communication with another module.
Have tried using USB-TTL (with Teraterm) with the other module, and no issue.

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