All readings are "nan", except the first reading
marcelroeder opened this issue · 6 comments
Hello,
i am trying to connect an nodemcu board through an rs485 transceiver to the SDM630 v2 meter over softwareserial.
The problem is that all readings show "nan". When i perform a reset of the nodemcu board, the first reading is working and showing the correct value, but after this all other readings are "nan". After an reset of the nodemcu board i can read another value. Get error code shows me error 4.
Do i need to clear some buffers after a reading was performed?
To test the hardware i tried an arduino uno with softwareserial and an arduino mega with hardwareserial, both without any problems. Also i tried another nodemcu board, but without any help.
What am i doing wrong?
#include <SoftwareSerial.h> //import SoftwareSerial library
#include <SDM.h> //import SDM library
SoftwareSerial swSerSDM(12, 14); //config SoftwareSerial
SDM sdm(swSerSDM, 9600, 4); //import SDM library
void setup() {
Serial.begin(9600); //initialize serial
sdm.begin(); //initialize SDM communication
}
void loop() {
char bufout[10];
sprintf(bufout, "%c[1;0H", 27);
Serial.print(bufout);
Serial.print("Voltage: ");
Serial.print(sdm.readVal(SDM630_VOLTAGE1), 2); //display voltage
Serial.println("V");
delay(50);
Serial.print("Current: ");
Serial.print(sdm.readVal(SDM630_CURRENT1), 2); //display current
Serial.println("A");
delay(50);
Serial.print("Power: ");
Serial.print(sdm.readVal(SDM630_POWER1), 2); //display power
Serial.println("W");
delay(50);
Serial.print("Frequency: ");
Serial.print(sdm.readVal(SDM630_FREQUENCY), 2); //display frequency
Serial.println("Hz");
delay(50);
Serial.print("Total Power: ");
Serial.print(sdm.readVal(SDM630_IMPORT_ACTIVE_ENERGY), 2); //display Total Used Power
Serial.println("kWh");
delay(50);
uint16_t lasterror = sdm.getErrCode(true);
sdm.clearErrCode();
Serial.print("Error Code: ");
Serial.println(lasterror);
lasterror = 0;
delay(1000); //wait a while before next loop
}
Ok after some more testing, i think the problem is the softwareserial library for the esp8266. Now i am using hardwareserial and for now it works.
Have you tried this lib on arduino uno with softwareserial? And it works correctly?
Only esp with swserial does not work properly?
Yes i tested the uno with softwareserial and it worked. Only the esp8266 makes problems with softwareserial.
tnx for the info.
What version of esp softwareserial You are using?
The latest version, i just downloaded the library yesterday from your link in the introduction