I have an Arduino Uno. It's role is to echo back what it receives.
But if I send it a stream of ascii characters it starts to error after the first one. Occasionally it gets the second character correct but often not.
If I delay each character then it works ok. I couldn't see this limitation mentioned in the SoftwareSerial library: https://www.arduino.cc/en/Reference/SoftwareSerial
The Arduino is running the following code:
#define BT_RX_PIN 16 // A2
#define BT_TX_PIN 17 // A3
#include <SoftwareSerial.h>
SoftwareSerial OtherSerial(BT_RX_PIN, BT_TX_PIN);
void setup()
{
Serial.begin(9600); // not used
OtherSerial.begin(9600);
}
void loop()
{
if (OtherSerial.available()) {
char value = OtherSerial.read();
String stri = "Received: ";
stri += value;
OtherSerial.println(stri);
}
}
The limitations do say "If using multiple software serial ports, only one can receive data at a time.". I don't have multiple software serial ports though I do have an instance of the "normal" serial port but I'm not sending any data to it... but perhaps even just initialising it is enough to disrupt seamless communication with the SoftwareSerial port?
Using the following test code for serial communication from a Raspberry Pi (using logic level conversion to go from 5V -> 3.3V and visa versa):
import time
def write(msg, delay):
for char in msg:
with open("/dev/ttyAMA0", "w") as f:
f.write(char)
time.sleep(delay)
write("hello", 0.01)
I got the following results (repeated 10 times at each delay time and averaged):
Delay (ms) | Success rate
10 | 100 %
9 | 100 %
8 | 0 %
5 | 0 %
1 | 0 %
A delay of 9 ms between each character means the communication rate falls from ~ 960 characters per second (9600 baud / 10 bits per 7 bit character) to ~ 100 characters per second (1 / (1 / 960 characters per second + 9ms)). Is this right? Perhaps I'm doing something else wrong / set it up wrong in software / hardware?
with
line before thefor
line?