esp8266 SoftwareSerial reading incorrect values

I am programming a nodemcu, manufactured by amica. I am reading TTL input from an EM-18 module on digital pin D2 (mapped to GPIO pin 4).

The RFID tag IDs read by the nodemcu are incorrect. For example:

Actual tag ID : 0005452711
Value read by esp8266 : 12005333A7

Actual Tag ID : 0003949515
Value read by esp8266 : 45003C43CB

Here is my code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(D2, -1, false, 128);
char input[12];
int count = 0;

void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.println(“setup”);
}

void loop()
{
if(mySerial.available())
{
count = 0;
while(mySerial.available() && count < 12
{
char a = mySerial.read();
input[count++] = a;
delay(2);
}

for(int i = 0; i < 12; i++){
Serial.print(input*);*

  • }*
  • Serial.println();*
  • }*
    }

I seem to recall that a special version of SoftwareSerial is required when using the ESP8266

Is the TTL output from the other device at 5V ? What level is the 8266 input expecting ?

Yes, I have used the esp8266 Software Serial library by plerup. https://github.com/plerup/espsoftwareserial

EM-18 works on a 5v logic, while esp8266 works on 3.3v. The nodemcu accepts inputs of 5v without frying the board. Also https://learn.sparkfun.com/tutorials/logic-levels/33-v-cmos-logic-levels states that 3.3v and 5v logic levels are compatible as long as the 5v input doesn't fry the 3.3v board.

Could the voltage level differences still be an issue? Is there any way I can read the input as if it was a 3.3v, with just software changes?

Is there any way I can read the input as if it was a 3.3v, with just software changes?

No

The easiest thing to try would be a level shifter using 2 resistors