Using teensyduinio 1.20 rc2 - testing serial event
Reference system - Official UNO
Test system Teensy 3.1
Tested on UNO using default USB connection as serial port in both cases (teensy 3.1 and UNO) - UNO it works - teensy does not
further testing to be done to confirm if faulty on hardware ports as well or just USB port
Current work around:
1. rename serialEvent() function to getSerial()
2. add into void loop()
Reference system - Official UNO
Test system Teensy 3.1
Code:
char tempBuffer[100] = {0};
const int MaxInput = 10;
long prevMillis = 0;
int loopDelay = 1000;
// ---------------------------------------------------------------------------
void setup()
// ---------------------------------------------------------------------------
{
Serial.begin(115200);
while (!Serial); // wait for connection to terminal emulator
Serial.println("Enter something");
}
// ---------------------------------------------------------------------------
void loop()
// ---------------------------------------------------------------------------
{
if (millis() > prevMillis + loopDelay)
{
prevMillis = millis(); // reset count
Serial.println(".");
}
}
// ---------------------------------------------------------------------------
void serialEvent()
// ---------------------------------------------------------------------------
{
static unsigned int input_pos = 0;
//Serial.println("+"); // debug so we know this has been called
while (Serial.available())
{
char inByte = (char)Serial.read();
switch (inByte)
{
case '\n': // end of text
tempBuffer [input_pos] = 0; // terminating null byte
Serial.println(tempBuffer);
input_pos = 0;
break;
default:
// only allow alphabet and punctuation chrs
if (inByte >= 32 && inByte <= 126)
{
// keep adding if not full ... allow for terminating null byte
if (input_pos < (MaxInput - 1)) tempBuffer[input_pos++] = inByte;
} // end if((inByte ....
break;
}
}
}
Tested on UNO using default USB connection as serial port in both cases (teensy 3.1 and UNO) - UNO it works - teensy does not
further testing to be done to confirm if faulty on hardware ports as well or just USB port
Current work around:
1. rename serialEvent() function to getSerial()
2. add into void loop()
Code:
if (serial.available()) getSerial();