Go Down

Topic: Tty for serial port to Arduino from Linino (Read 66990 times) previous topic - next topic


What do you exactly mean by you disabled tty?
Thought tty is required for Bridge.


  I use the Linino to handle REST Web Services, and JSON data. These services talk to an API layer, which maps the JSON data to "device level" calls, which my Arduino understands. (Eg replace Timers for Monday, read all timers, etc.)

This API layer takes a sequence of bytes (A private command or the Arduino API), wraps it in a frame (SOM BYTE, frame datalen, DATA, EOM, and Checksum) and sends it to the Arduino over the serial port.

I have a C++ class (YUNListener) on the Arduino which waits for SOM, parses the data, ensures there's an EOM, and validates the Checksum. So ant comms errors, or other unwanted / unexpected incoming data on the serial bridge are discarded. The C++ class has 2 Virtual methods, which do nothing in the base class, but are designed to be over-ridden in real subclasses. (Eg TimerListener : YUNListener)

The methods are:
1. handleCommand( data ) which you can implement, and will be given a correct byte array from incoming commands.
2. debug( data ) which will be called at various points in the command parsing process. I use this method to check for an input pin being pulled high, and if it is, I output serial debugging info to an output pin . So I have a cable that connects the output pin to a serial terminal, and straps the other pin high. So I automatically get debug output when I connect the cable to my laptop.

Happy to supply the code if anyone is interested.

Sounds promising.
Anything to share?


Maybe someone following this thread can help me regarding my problem posted over there: http://forum.arduino.cc/index.php?topic=194934.msg1470401#msg1470401


What do you exactly mean by you disabled tty?
Thought tty is required for Bridge.

Sorry about the confusion... let me clarify.

I'm attempting to get real time data from an I2C sensor that I want to send to a computer over Wi-Fi. I attempted to use the Console class to send data from the microcontroller to the Linino processor. It was reliable and all, but it was WAY too slow (it sent only 2 or 3 samples per second). I then decided to bypass bridge altogether and write a very simple Serial to TCP Bridge using pyserial. Without bridge enabled, I could send values to the linux processor via Serial1 (at 250k baud) to the shell quite quickly, but there were many issues with dropped characters because of the high UART speed. I disabled the tty in inittab so I could set my own baud rate for communications, after which the transmission worked great.

To everybody else:

Does anyone know how to change the tty baud rate at boot time? The speed appears to be coded into the kernel args. Do I have to build my own kernel to change the speed? Is there a file somewhere I can edit?

Also, I would love it if future releases of Linino adopt a 115k baud TTY speed as it appears to be MUCH more stable.

Anyways, thanks for all the help!



Thanks for the clarification.
Could you share your python code?

BTW: Does it count whether one connects Yun via USB and uses TTY from IDE or WiFi only? Looks like when doing Serial1.println() Serial Monitor throws back something from BuysBox:
Code: [Select]
oot@ arduino:/# ->test=[[1,2],[3,4]]
sh: -: not found

Where "->test=[[1,2],[3,4]]" is my data.


Hi Wayoda,
   when you say a BAUD rate of 250000 fails - do you get characters from Serial, or nothing at all?

The python script writes 32 chars to the ATmega and then reads 32 bytes with a five second timeout.
When used with baudrates above 115200 the read returns unexpected characters and also too few of them.

I can confirm this. At 250k, characters are sent, but it drops characters pretty often. At 115200 and below, it works great.



Hello everybody!

Just in case anybody might find this useful, here is the simple, fast python script I've been working on to send anything written to Serial1 to a TCP port for access over the network. It doesn't do any receiving, but it should be relatively trivial to add that functionality. As many mathematics journals say, "its left as an exercise to the reader." :)

Note: make sure to install pyserial via opkg

Hope this helps someone....


Code: [Select]

import serial
import socket

TCP_IP = ""
TCP_PORT = 5454

serial_conn = serial.Serial("/dev/ttyATH0", 115200, timeout=1)

server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_sock.bind((TCP_IP, TCP_PORT))

while True:

print "Waiting for connection..."
conn, addr = server_sock.accept()

print "Client " + str(addr) + " connected."
while True:
text = serial_conn.readline()
print "Sending: " + text
except socket.error as e:
print e


Sorry for my ignorance, but I have some very basic questions:

- why do you need to disable the Console to get this to work?
- why is the Linino sending characters over that link whilst booting?

It would be great if I could threat the Arduino-Linino connection as a very simple object like (hopefully) a Serial.


Newline, are you referring to the /etc/inittab modifications?
If yes, I had to do this or a connection to ttyATH0 would result in a login which could not be done by my server process. But to be honest, I would like to see more detailed information and documentation how this all works together.

Another thing I had to do in my sketch is wait until Linino is done with its boot process and after that change connection speed to 115200. It looks like that Linino starts using 250000 on Serial1 and you can only change to a different connection speed after the boot sequence completed.


As far as the boot process, Openwrt (linino) goes through a few steps while booting up. The console is attached to the serial port to allow interaction in case bad things happen so you can fix them, without this you could end up "bricked" with no way to "unbrick".

Specifically first there is an opportunity to stop uboot so you can flash/boot if the image is bad. Next is failsafe mode which allows you to fix things that are messed up in the linux system configuration, next is the console started in inittab which allows you access if you lose network connectivity. While you could run for years without needing these things they are nice to have, kinda like airbags in a car, if you need them you are VERY glad you had them.

I believe the only way to disable the first two early stages would be to compile an image after appropriate changes have been made to uboot and kernel parameters. 


super clear explanation noblepepper and I love the airbag metaphor. It would be nice to have a "yun boot up explained" paragraph on the playground, do you mind pasting your post there?


I like the explanation too.
And I do not feel very comfortable about changing inittab and removing the tty entry.
But what is a better solution if I want to attach to Serial1 and listen for incoming data?


So I'm not sure after reading through the posts if I definitively understand the process.

1) Does the tty HAVE to be disabled in inittab for the connection between the two sides to work?  If not, do I correctly understand that once the boot process is finished you then must reset the baud rate?

2) Can the Bridge app be left alone or should it be disabled from starting as well?


1)a No, definitely not true, the bridge operates fine with this enabled. I haven't studied it enough to tell you exactly how it does this, but this is where I would start. I believe Federico said that the bridge filters out some "chatter" that the kernel will send to the console from time to time.
1)b There are some that say 250,000 is too fast but the bridge seems to operate there fine.

2) I think if you want to use this connection without going through the bridge you will need to disable the bridge since it is using it. You will lose all the functionality of the bridge if you do.


@noblepepper Thanks for comments.  I realize I wasn't clear on 1) I was asking this question with regard to establishing a serial connection from Python, not using the Bridge.

Go Up