Using Serial over USB with Ubuntu (+other linux?)

All,

This is how I got Serial working over USB on my Ubuntu 12.10 PC, at least for receiving data (I have not cracked sending data yet).

I was hoping, correctly, that the spark would show up as a device of some kind such as /dev/ttyXYZ123

With the Spark unplugged, I typed the following into a terminal session:

ls /dev/ > ~/before.txt

Then I plugged the Spark in, waited for the cyan breathing, then typed:

ls /dev/ > ~/after.txt

This captured the list of all devices before and then after plugging in. So what differences were there?

sdiff ~/before.txt ~/after.txt

The above command compares the 2 files and lists them line-by-line, side-by-side and indicates where there are differences. I found two new devices, one simply called “serial” (not sure about that), the other called “ttyACM0” (more like what I was expecting).

Next, I knew I needed to set the baud rate for the device to the same rate set with the Serial.Begin() command in my firmware:

stty -F /dev/ttyACM0 9600

Finally, I could view the data arriving over the USB with the command:

cat /dev/ttyACM0

This continues to echo data until you press ctrl-C.

Home this helps someone!

Paul

@PaulRB If you want two-way communications, you should be able to do the following command:

screen /dev/ttyACM0

to open a connection.

You can set the baud with screen as well, so you don’t have to mess with stty. man screen for command keys. :smiley:

1 Like

Thanks @zach and @timb! That works great (not tested sending data to the core yet, but certainly receiving it OK).

I have been getting alot of messages like this:

stty: /dev/ttyACM0: Device or resource busy

Happens with screen too. Wait long enough and the problem goes away, so I think there must be a timeout. Any idea how to avoid this problem?

Hmm, not sure - how much data are you sending, and at what speed? You could potentially increase the baud rate

I haven’t recieved my core yet, so I cannot verify this, but when I was trying something similar with another device using Ubuntu I ran into a similar sounding problem. It turns out the modem manager was periodically openning /dev/ttyACM0. It gave intermittent failures. A little searching pointed me to this link.

http://askubuntu.com/questions/216114/how-can-i-remove-modem-manager-from-boot

It seemed to cure my problem with my other Arduino like device.

Only a few characters, once per second, 9600 baud.

If I attempt to use cat or screen just after flashing or resetting the core, I get the message. Wait a minute and it works. If I then ctrl-C out of cat or ctrl-a d out of screen, then immediately try those commands again, I get the message. Wait a minute and they work ok again.

I’ll try a higher baud rate.

Thanks @jonchilds, I’ll have a look at that link.

Paul

So I tried @PaulRB’s diff method for discovering the device my core was listening on, and I see absolutely nothing. I tried connecting the core on every usb slot on my pc to no avail. I didn’t find any topics associated to a device not being recognized via usb, at least not for linux. So does anyone here have any idea why my device isn’t showing up in ubuntu?

Thank you! this was most helpful with my Yun :slight_smile: