Teensy 3.1 serialevent

shanevanj

Member
Using teensyduinio 1.20 rc2 - testing serial event

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();
 
I just tried it on a Teensy 3.1 using 1.20-rc2. I just copied your code to Arduino, uploaded to a Teensy 3.1, then I selected its serial port and opened the Arduino Serial Monitor. I typed "test123" and "testtest" and clicked Send for each.

test.png

Is it supposed to do something more than this?
 
Odd - you get the output - I dont ...... let me check again .... I definitely get the "." but it ignores my input totally?

Curiouser and Curiouser....now Arduino IDE has hung up after entering a few test text items....

I have used an alternate tty emulator and it has the same issues - "." outputs but no input from keyboard etc
 
Last edited:
I did the same as Paul did and it works for me as well...

Other things I would check include: what is your USB type set to in the tools menu. I tried with my normal setting of "Serial", which worked. I also tried with "keyboard+mouse+joystick" and in Arduino IDE it said the serial port was emulated. Still worked.

keyboard layout? I used US English

CPU speed: I used 120
 
So, we have:
teensy 3.1 board (purchased last week in Germany) (2 used for testing)
Windows 8.1 (running in Parallels)

Deleted and reinstalled...
Arduino 1.05
Teensydunio 1.20rc2

Settings
Board Teensy 3.1
Serial Port...
Usb type : Serial
Kbd US English

CPU: mine does not show 120 ...? - set to 96

compile, upload and it works! (windows)

Try same thing with Macosx 10.9.4
.....and it now works! ... so perhaps some remnants from the install over previous code version
 
Back
Top