I'm trying to read (and later write) data to my garage door opener with an ESP8266 using the Software Serial library.
The wired garage door opener button uses two wires, 12v and ground. The 12v line is pulled to ground and both RX & TX are done on the same wire. I used a voltage divider to drop the 12v to 3.3v and have this connected to D6 on the ESP.
The chip in the door opener is an STM8S, and the UART is configured to be 9600 baud, 8 bits, no parity, 2 stop bits.
I wrote a data logger which uses an interrupt to record the microseconds of the signal. I manually converted this signal from timestamps to binary, and then loaded it into pulseview.
As we can see, there are three messages, each starting with 0x00, 0x55, 0x01, 0x00, and each one is 20 bytes in length. I repeated my tests several times and compared the interpreted wave form with my scope, so I'm quite confident that its correct.
The problem is that the software serial library is only returning a few random bytes of data. I setup the port with
mySerial.begin(9600, SWSERIAL_8N2, D6, D5, true);
Here's the result after pressing the door opener button 5 times (each line is one message as seen by the Software Serial library)
4 B4 6E 32 CE
DE BA A 11
E6 E 2
9A E 36 6E 6A
8A A6 12
Sketch:
#include <SoftwareSerial.h>
#define RX D6
#define TX D5
#define MSGLEN 20 // number of expected bytes in each message
byte data[MSGLEN]; // hold the data received from the uart
int counter = 0; // counter to keep track of how many bytes were received from the uart
int lastInterrupt = 0; // the last interrupt time from the uart
SoftwareSerial mySerial(D6, D5); // RX, TX
void setup()
{
// Open serial communication for debugger and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Native USB only
}
// Open the software serial port and set the data rate
mySerial.begin(9600, SWSERIAL_8N2, D6, D5, true);
while (! mySerial) {
;
}
Serial.println("Setup completed");
}
void loop() // run over and over
{
if (mySerial.available() > 0) {
lastInterrupt = millis();
data[counter] = mySerial.read();
counter++;
}
if (counter == MSGLEN - 1) {
Serial.println("Message overflow");
counter = 0;
}
if (counter > 0 && millis() > lastInterrupt + 60) {
// Serial.print("last interrupt: ");
// Serial.print(lastInterrupt);
// Serial.print(" counter: ");
// Serial.println(counter);
for (int i = 0; i < counter; i++) {
Serial.print(data[i], HEX);
Serial.print(" ");
}
Serial.println("");
counter = 0;
}
}
Does anyone have any idea why it's not reading the data correctly?