Go Back
No Bridge Library on Arduino Yun
07th, May
Arduino Yun – TCP/IP to Serial1 redirect

!! Code available on my GitHub toskyRocker account !!

Many of us, Arduino lovers, want to get rid of the Bridge library, due to its lame performance, it’s slow and heavy.
A simple way to avoid this problem is to replace the Bridge library (Atmega side) with a python script (Atheros side) that redirects the TCP/IP stream to the Serial1 .

1. First of all replace inittab (using copy over SSH) on OpenWrt with the one given in my GitHub account.

>>scp inittab root@192.168.240.1:/etc/

This step makes Serial1 available on startup.
NOTE: Arduino Yun’s IP is usually 192.168.240.1

2. Copy tcp_serial_redirect.py in the right place on OpenWrt.

>>scp tcp_serial_redirect.py root@192.168.240.1:/root/

3. Copy pyserial-2.7 folder on OpenWrt

>>scp -r pyserial-2.7/ root@192.168.240.1:/root/

4. Install pyserial on OpenWrt

>>ssh root@192.168.240.1
>>cd pyserial-2.7
>>python setup.py install

5. In order to enable the redirect type this command in the OpenWrt terminal:

>>python tcp_serial_redirect.py -p /dev/ttyATH0 -b 115200 -P 8888 

115200 is the baudrate selected.
8888 the port for the connection.

6. You’re ready to use the serial1 communication on Atmega32u4. You can write something like this to test your connection:

void setup() {
  Serial1.begin(115200);
}

void loop() {
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.print(inByte, BYTE); 
  }
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.print(inByte, BYTE); 
  }
}

Don’t forget to use the same baudrate for both the python script and Arduino sketch

December 16th, 2015 at 20:58 by Todd

Reply



Very nice, this fixed my stability problem trying to use Console.
I considered doing a C version, clever to use pyserial.

December 17th, 2015 at 21:05 by Todd

Reply



So I am a fan, but there are some issues – rebooting the Yun is a real
issue, as the Atmega application I am running spews data into the USB console. I can only control a bit by unplugging my sampling device, wait for the YUN to connect/network, then unblock the atmega app at startup.

while(Serial1!); is not enough!

any other workarounds?

December 17th, 2015 at 23:16 by AndrewTosky

Reply



Thank you for appreciating my work 🙂

Do you need the script running on Yun startup?

September 19th, 2017 at 13:32 by Eduardo

Reply



Interesting post, I will test with project because I have strange problems with bridge library.