I am sending about 100 characters of data from my Arduino to an Imp Shield (has level shifters) using Software Serial and Serial.print commands. The Imp only seems to be able to read the first 79 characters and then loses the rest. Here is some of the code from both
Arduino Code:
#include <SoftwareSerial.h>
SoftwareSerial impSerial(8, 9); // RX on 8, TX on 9
void setup() {
impSerial.begin(9600);
}
void loop() {
// Output to Imp
impSerial.print(“W,”); //Start Character: There is never a W character in the data.
impSerial.print(Data1);
impSerial.print(",");
impSerial.print(Data2, 1);
…
impSerial.print(“X”); //Stop character: There is never an X character in the data.
Imp Device Code:
hardware.uart57.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS);
function pollUart()
{
//Tried lots of values for the polling rate. This is really slow. Don’t care about blocking other code
imp.wakeup(2.00, pollUart.bindenv(this));
local bcnt = 0;
local s = “”;
local byte = hardware.uart57.read(); // read the UART buffer
// This will return -1 if there is no data to be read.
while (byte != -1) // otherwise, we keep reading until there is no data to be read.
{
s+=byte.tochar(); // Add byte to string s
bcnt++; // add 1 to byte count
byte = hardware.uart57.read(); // read from the UART buffer again (not sure if it’s a valid character yet)
}
if (bcnt > 0){
local len = s.len();
server.log(s); //Print out the string for debugging - shows lost characters when longer than 79 characters
if (s[0].tochar() == "W" && s[len-1].tochar() == "X") {
server.log("String received Good W and X");
local sp = [“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”];
local pr = [“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”,“0”];
sp = split(s,",");
}
pollUart(); // start the UART polling, this function continues to call itself