Hi all,
i try to transmitt data from a teensy 3.6 to a arduino duemilanove via a Serial connection using SoftwareSerial for the arduino and Serial4 on teensy's side. The Teensys TX is connected to arduinos RX, nothing else is connected.
This is my code for the teensy:
int ledPin = 0;
int baudRate = 9600;
int testArray[] = {1,2,3,4,5,6,7,8,9,10};
void setup() {
pinMode(ledPin,OUTPUT);
Serial4.begin(baudRate);
}
void loop() {
for(int i=0; i<10; i++){
Serial4.write(testArray[i]);
delay(10);
}
digitalWrite(ledPin,HIGH);
delay(10000);
digitalWrite(ledPin,LOW);
}
and this for the receving side, the arduino:
#include <SoftwareSerial.h>
const int pinRX = 3;
const int pinTX = 4;
const int baudRate = 9600;
const int numberBytes = 10;
unsigned long max_delay = 1000;
unsigned long starttime;
int receivedBytes[numberBytes];
bool filled = false;
SoftwareSerial mySerial(pinRX,pinTX);
void setup() {
pinMode(pinTX,OUTPUT);
pinMode(pinRX,INPUT);
Serial.begin(baudRate);
mySerial.begin(baudRate);
}
void loop() {
if(mySerial.available()>0){
starttime = millis();
filled=false;
while(mySerial.available() < numberBytes && (millis()-starttime < max_delay));
if(mySerial.available()<numberBytes){
//error handling
}else{
for(int i=0; i<numberBytes; i++){
receivedBytes[i]=mySerial.read();
}
filled=true;
}
}
if(filled){
Serial.print("Recived: \n");
Serial.print("[");
for(int i=0; i<numberBytes-1; i++){
Serial.print(receivedBytes[i]);
Serial.print(",");
}
Serial.print(receivedBytes[numberBytes-1]);
Serial.println("]");
filled=false;
}
delay(2000);
}
the seriell monitor display smth. like this:
Recived:
[1,2,3,4,5,6,7,8,9,10]
Recived:
[255,255,254,1,2,3,4,5,6,7]
Recived:
[8,9,10,255,255,1,2,3,4,5]
Recived:
[6,7,8,9,10,255,255,255,1,2]
I dont get why i get these "255" and "254", which i want to understand, cause i need a reliable datatransmission between these controllers for my projekt.
Thanks for your time