GyroGearloose
Member
Without much background in Ethernet protocols I am sending data packages between two T4.1. (finally got the Ethernet-Kit)
My first steps I followed this tutorial with two Arduino UNOs https://www.youtube.com/watch?v=9lrAvw9TObs
He is using a Ethernet Switch to connect the two board. Everything works fine, and I can use either the Switch or a cross-over cable.
When I ported the setup over to the T4.1s it does not work with the Ethernet Switch anymore. It only works with the cross-over cable.
If I use a IP-address in my PC network such as 192.168.1.105 then I can connect it via my WLAN switch.
This is my sender code:
and this is my receiver code:
I am just trying to understand the difference between the Arduino and Teensy behavior - and what should be done to use the switch with the T4.1.
My first steps I followed this tutorial with two Arduino UNOs https://www.youtube.com/watch?v=9lrAvw9TObs
He is using a Ethernet Switch to connect the two board. Everything works fine, and I can use either the Switch or a cross-over cable.
When I ported the setup over to the T4.1s it does not work with the Ethernet Switch anymore. It only works with the cross-over cable.
If I use a IP-address in my PC network such as 192.168.1.105 then I can connect it via my WLAN switch.
This is my sender code:
Code:
/* UDP Sender on Teensy 4.1 with NativeEthernet on board.
* Sends out a packet of ARRAY_SIZE bytes to destinationIP
*
* For some reason the communication between 2 Teensys only works with an crossover cable.
* Different as with the UNOs we cannot use an ethernet switch. (?)
*
*/
#include <SPI.h>
//#include <SD.h>
#include <NativeEthernet.h> // for Teensy 4.1
#include <NativeEthernetUdp.h>
//#define ARRAY_SIZE 32 // max 700 with Arduino UNO
#define ARRAY_SIZE 318 // real Audio Data
uint8_t data1[ARRAY_SIZE]; // write vector
byte mac[] = { 0x04, 0xE9, 0xE5, 0x0B, 0xFC, 0xCD }; // com 9
//byte mac[] = { 0x04, 0xE9, 0xE5, 0x0B, 0xFC, 0xD1 }; // com 6 (the other board)
IPAddress myIP(111, 111, 111, 111);
//IPAddress myIP(192, 168, 1, 105); // for use in my Ethernet
IPAddress destinationIP(111, 111, 111, 222);
//IPAddress destinationIP(192, 168, 1, 102);
unsigned int myPort = 8000;
unsigned int destinationPort = 8002;
EthernetUDP Udp; // create an instance 'Udp'
elapsedMicros transmissionTime;
void get_Data1() {
for (int i = 0; i < ARRAY_SIZE; i++) { // fill the Array with data
data1[i] = i;
//Serial.println(i);
}
}
void send_Data() {
transmissionTime = 0; // only needed if we want to report the time
Udp.beginPacket(destinationIP, destinationPort);
// Udp.write(0xF0); // this will be the Startbit
Udp.write(data1, ARRAY_SIZE);
Udp.endPacket();
// delay(10); // make sure somewhere is at least 10 millisec delay
//for (int i = 0; i < ARRAY_SIZE; i++) { // for debugging print data
// Serial.println(i); }
}
void report_Time() {
Serial.print(transmissionTime);
Serial.print(" Microseconds to send ");
Serial.print(ARRAY_SIZE);
Serial.println(" Bytes");
}
void setup() {
Ethernet.begin(mac,myIP);
Udp.begin(myPort);
Serial.print("Sender with IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
get_Data1();
send_Data();
report_Time();
delay(1000);
}
and this is my receiver code:
Code:
/* UDP Receiver on Teensy 4.1 with NativeEthernet on board.
* Reads packet of ARRAY_SIZE bytes from sendingIP
*
* For some reason the communication between 2 Teensys only works with an crossover cable.
* Different as with the UNOs we cannot use an ethernet switch. (?)
*
*/
#include <SPI.h>
//#include <SD.h>
#include <NativeEthernet.h> // for Teensy 4.1
#include <NativeEthernetUdp.h>
//#define ARRAY_SIZE 32 // max 700 with Arduino UNO
#define ARRAY_SIZE 318 // real Audio Data
uint8_t data2[ARRAY_SIZE]; // read vector
byte mac[] = { 0x04, 0xE9, 0xE5, 0x0B, 0xFC, 0xD1 }; // com 6
//byte mac[] = { 0x04, 0xE9, 0xE5, 0x0B, 0xFC, 0xCD }; // com 9 (the other board)
IPAddress myIP(111, 111, 111, 222);
//IPAddress myIP(192, 168, 1, 102); // for use in my Ethernet
IPAddress sendingIP(111, 111, 111, 111);
//IPAddress sendingIP(192, 168, 1, 105);
unsigned int myPort = 8002;
unsigned int sendingPort = 8000;
EthernetUDP Udp;
elapsedMicros transmissionTime;
void setup() {
Ethernet.begin(mac,myIP);
Udp.begin(myPort);
Serial.print("Receiver with IP address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
//Serial.print("."); delay(500); // just show activity
// receive Data
transmissionTime = 0;
int packetSize = Udp.parsePacket(); // analyse the data packet
if(packetSize) { // if there is something in the packet
Serial.print(transmissionTime);
Serial.print(" Microseconds to parse ");
Serial.println();
Serial.print("Received packet size ");
Serial.print(packetSize);
Serial.print(" Bytes from ");
IPAddress remote = Udp.remoteIP();
for (int i = 0; i < 4; i++ ) {
Serial.print(remote[i], DEC);
if (i < 3) { Serial.print("."); }
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into the packet buffer
transmissionTime = 0;
Udp.read(data2, ARRAY_SIZE);
/*
// print data
Serial.println("Content: ");
for (int i = 0; i < ARRAY_SIZE; i++) {
Serial.print(" ");
Serial.print(data2[i]);
} // end print received data
*/
// Serial.println();
Serial.print(transmissionTime);
Serial.print(" Microseconds to receive ");
Serial.print(ARRAY_SIZE);
Serial.println(" Bytes");
Serial.print("");
data2[0]++;
Serial.println(); Serial.println();
} // end analyse data packet
delay(10);
}
I am just trying to understand the difference between the Arduino and Teensy behavior - and what should be done to use the switch with the T4.1.