reaper7 / SDM_Energy_Meter

reading SDM72 SDM120 SDM220 SDM230 SDM630 modbus energy meters from arduino (esp8266, esp32, avr)
240 stars 97 forks source link

ESP32 with SoftwareSerial #35

Closed micha6554 closed 4 years ago

micha6554 commented 4 years ago

Its ESP32 with SoftwareSerial possible?

Or, its possible to use RX2 and TX2?

Thanks

reaper7 commented 4 years ago

Theoretically yes, why not... but I've never tested it.

you can be first :)

micha6554 commented 4 years ago

Its from ESP32 the pin 16/17 RX2/TX2 Soft- or Hardwareserial?

reaper7 commented 4 years ago

don't ask me, I don't know, you have to understand it yourself

you must decide if you want to use the software or hardware implementation

reaper7 commented 4 years ago

Personally I do not recommend using swserial, especially for esp32 where we have 3 hardware uarts. ...so, for the test, if you have hwserial 2

  1. uncomment in SDM_Config_User.h:
    #define USE_HARDWARESERIAL
  2. in sdm_simple/sdm_simple.ino example:
    
    //#include <SoftwareSerial.h> // < comment out
    #include <SDM.h>

//SoftwareSerial swSerSDM(13, 15); // < comment out

SDM sdm(Serial2, 9600, NOT_A_PIN, SERIAL_8N1, 16, 17); //config SDM

(of course, modify the baud rate if you have other than 9600)

basically if you use the default uart pins, then initialization may look simpler:

SDM sdm(Serial2, 9600, NOT_A_PIN)

micha6554 commented 4 years ago

Thanks reaper7!!!!


Its work!!

// // modbus for SDM-120 Energiemesser // https://github.com/reaper7/SDM_Energy_Meter // Config unter https://github.com/reaper7/SDM_Energy_Meter/blob/master/SDM_Config_User.h (unkomment #define USE_HARDWARESERIAL !!!!!!!!!) //

define USE_HARDWARESERIAL // hardwareserial|softwareserial

define BAUDRATE 2400 // 2400bps (SDM-120)

define MAX3485_RE_DE_PIN GPIO18 // RE-DE pin

define RX GPIO16

define TX GPIO17

include // SDM library

SDM sdm(Serial2, BAUDRATE, MAX3485_RE_DE_PIN, SERIAL_8N1, RX, TX); // (Serial2, baudrate, MAX3485_RE_DE_PIN, SERIAL_8N1, RX, TX)

reaper7 commented 4 years ago

I'm glad to hear that :) You are the first who confirmed :D