Hey, I just got a Teensy 3.1 because it has much more memory than Arduino. This code worked on Arduino, being able to read from any Serial port and saving it to a string. However, this crashes the Teensy. Please tell me what is wrong and give me an explanation about the memory. I tried saving to heap I tried saving to stack, but to no avail. Thanks
I keep getting Available but no output with the code below. Connected to Serial3 is GPS module which works when each byte is printed rather than saved on a string.
Please help.
char readBuffer[1024];
void setup(){
Serial.begin(9600);
Serial3.begin(9600);
}
void loop(){
if(Serial3.available()){
Serial.println("Available");
int howBig = readSerialString(Serial3);
for( int i = 0; i < howBig; i++){
Serial.print(readBuffer);
}
}
}
int readSerialString(HardwareSerial whatSerial){
memset(readBuffer, 0, strlen(readBuffer));
int theSize = 0;
while(whatSerial.available()){
readBuffer[theSize]=(char) whatSerial.read();
theSize++;
//delay(10); I tried delay to no avail.
}
readBuffer[theSize] = (char) 0;
}
I keep getting Available but no output with the code below. Connected to Serial3 is GPS module which works when each byte is printed rather than saved on a string.
Please help.
char readBuffer[1024];
void setup(){
Serial.begin(9600);
Serial3.begin(9600);
}
void loop(){
if(Serial3.available()){
Serial.println("Available");
int howBig = readSerialString(Serial3);
for( int i = 0; i < howBig; i++){
Serial.print(readBuffer);
}
}
}
int readSerialString(HardwareSerial whatSerial){
memset(readBuffer, 0, strlen(readBuffer));
int theSize = 0;
while(whatSerial.available()){
readBuffer[theSize]=(char) whatSerial.read();
theSize++;
//delay(10); I tried delay to no avail.
}
readBuffer[theSize] = (char) 0;
}