Hello again!
I did some experiments with which I would like to share.
The experiment consisted of comparing libraries and duplexes.
The experiment #1. Library: SoftwareSerial; Checking half-duplex: YES (line 25)
#include <SoftwareSerial.h>
#include <NeoSWSerial.h>
SoftwareSerial mySerial(2,3); // RX, TX
//NeoSWSerial mySerial(2, 3);
uint32_t button_press = 1;
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.print("\nSoftwareSerial test with half-duplex:\n");
Serial.print("Ready!\n");
delay(100);
}
void loop()
{
if (mySerial.available() > 0)
{
Serial.print("\n");
int data = mySerial.read();
Serial.print(data, DEC);
button_press = 1;
}
mySerial.print("sdfsf"); //line 25
if (button_press && !mySerial.available())
{
button_press = 0;
Serial.print("\nNew button press:");
}
}
Result:
SoftwareSerial test with half-duplex:
Ready!
New button press:
0
3
0
255
255
New button press:
101
0
3
0
255
255
255
New button press:
89
64
64
New button press:
The experiment #2. Library: SoftwareSerial; Checking half-duplex: NO (comment line 25)
#include <SoftwareSerial.h>
#include <NeoSWSerial.h>
SoftwareSerial mySerial(2,3); // RX, TX
//NeoSWSerial mySerial(2, 3);
uint32_t button_press = 1;
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.print("\nSoftwareSerial test with half-duplex:\n");
Serial.print("Ready!\n");
delay(100);
}
void loop()
{
if (mySerial.available() > 0)
{
Serial.print("\n");
int data = mySerial.read();
Serial.print(data, DEC);
button_press = 1;
}
//mySerial.print("sdfsf"); //line 25
if (button_press && !mySerial.available())
{
button_press = 0;
Serial.print("\nNew button press:");
}
}
Result:
SoftwareSerial test without half-duplex:
Ready!
New button press:
101
0
3
0
255
255
255
New button press:
101
0
3
0
255
255
255
New button press:
101
0
3
0
255
255
255
New button press:
As we can see, the packets are lost during a half duplex test.
The experiment #3. Library: NeoSWSerial; Checking half-duplex: YES (line 25)
#include <SoftwareSerial.h>
#include <NeoSWSerial.h>
//SoftwareSerial mySerial(2,3); // RX, TX
NeoSWSerial mySerial(2, 3);
uint32_t button_press = 1;
void setup()
{
mySerial.begin(9600);
Serial.begin(9600);
Serial.print("\nNeoSWSerial test with half-duplex:\n");
Serial.print("Ready!\n");
delay(100);
}
void loop()
{
if (mySerial.available() > 0)
{
Serial.print("\n");
int data = mySerial.read();
Serial.print(data, DEC);
button_press = 1;
}
mySerial.print("sdfsf");
if (button_press && !mySerial.available())
{
button_press = 0;
Serial.print("\nNew button press:");
}
}
Result:
NeoSWSerial test with half-duplex:
Ready!
New button press:
101
0
3
0
-1
-1
-1
New button press:
101
0
3
0
-1
-1
-1
New button press:
101
0
3
0
-1
-1
-1
New button press:
101
0
2
0
-1
-1
-1
New button press:
The library NeoSWSerial works with half-duplex. But the last bytes (0xFF) perceives differently. I think so I didn't work display.
Thank you for attention,
Marat