Serial communication with an Arduino over Serial?

1,345 views
Skip to first unread message

Dana Woodman

unread,
Nov 25, 2013, 6:42:11 PM11/25/13
to golan...@googlegroups.com
I'm attempting to use go to send simple messages to an Arduino via a serial connection. 

I've attempted to use about 5+ different projects I've found. All seem to be either A) Very old/abandoned B) Only work on one platform C) Are incomplete.

I come from a Ruby background, so something like http://ruby-serialport.rubyforge.org/ is what I'm after, if that helps.

Does anyone know how I could send messages to an Arduino over serial that is cross platform (at least Mac/Linux)? Is there any Golang packages that someone has gotten to work with Arduino?

Thanks for any pointers!

Erwin

unread,
Nov 25, 2013, 8:55:15 PM11/25/13
to Dana Woodman, golang-nuts
i implemented a rs232 package that i have used without problems on linux and OS X communicating with an Arduino and other serial devices. i haven't put it on github yet, but should really do it, make it open source. if you are in a hurry, i can send the source files to you as is. 

Dana Woodman

unread,
Nov 25, 2013, 8:59:02 PM11/25/13
to Erwin, golang-nuts
I actually am in a hurry :) Have to get this working in the next day or two. Could you email me the code for reference? Thanks!


- Dana W.

distributed

unread,
Nov 26, 2013, 3:23:58 PM11/26/13
to golan...@googlegroups.com, Erwin
Have you looked at:
or

goserial has worked for me and (shameless plug) I'm the author of sers. I have not changed sers since I'm successfully running it on Mac OS X, Linux and Windows and on 386, amd64 and arm. I suspect that the same applies for goserial.

The reason I wrote sers is that I wanted to be able to be set non-standard bitrates which I needed for some AVR projects. I have stolen the windows code from tarm/goserial ;)

Skip Tavakkolian

unread,
Nov 26, 2013, 3:24:40 PM11/26/13
to Dana Woodman, Erwin, golang-nuts
i don't know if this is one of the five you've already considered. came across this a while back when i was looking for a firmata package (i've not tried it):


it uses this goserial which apparently supports posix and windows.


-Skip


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tarmigan

unread,
Nov 29, 2013, 1:46:33 PM11/29/13
to distributed, golang-nuts, Erwin
I'm the author of https://github.com/tarm/goserial

It works very well for my needs and for a bunch of other people.  I haven't made many changes recently because it just works, though patches from other folks have been merged in.

There are a few unmerged forks on github adding some things like 5bit support, non-standard baud rates, and serial timeouts (note that goserial is blocking until at least 1 byte is received, but non-blocking otherwise), but I would prefer to keep things portable and the interface clean.

In short, old does not mean abandoned, just stable.  goserial works for communicating with an arduino and should also work for you.  Shout if you have trouble with it!

Thanks,
Tarm



--

Vasiliy Tolstov

unread,
Dec 1, 2013, 7:17:26 AM12/1/13
to Tarmigan, distributed, golang-nuts, Erwin
I'm try to use this package (goserial) to communicate with
virtio-serial (https://fedoraproject.org/wiki/Features/VirtioSerial)


But get error:
2013/12/01 16:15:36 File is not a tty

code:
package main

import (
serial "github.com/tarm/goserial"
"log"
)

func main() {
conf := new(serial.Config)
conf.Name = "/dev/virtio-ports/org.mighost.agent.0"
conf.Baud = 115200

sc, err := serial.OpenPort(conf)
if err != nil {
log.Fatal(err)
}

buf := make([]byte, 4096)

for {
n, err := sc.Read(buf)
if err != nil {
log.Fatal(err)
}
log.Printf("%s\n", buf[:n])
}
}

file:
ls -alo /dev/vport0p2
crw-rw-rw- 1 root 251, 2 Dec 1 16:02 /dev/vport0p2

2013/11/29 Tarmigan <tarmig...@gmail.com>:
--
Vasiliy Tolstov,
e-mail: v.to...@selfip.ru
jabber: va...@selfip.ru

Tarmigan

unread,
Dec 1, 2013, 2:49:52 PM12/1/13
to Vasiliy Tolstov, distributed, golang-nuts, Erwin
Hi Vasiliy,

The intention with goserial was to communicate with hardware serial ports rather than virtual ones.  That said, I don't see why it shouldn't work.  Does your go program want to connect to /dev/vport0p2 instead of /dev/virtio-ports/org.mighost.agent.0?

On the wiki page you pointed to, there are testing instructions for the serial port:
do those instructions work for you?

Does screen work for you?
screen /dev/virtio-ports/org.mighost.agent.0 115200

Thanks,
Tarm

Vasiliy Tolstov

unread,
Dec 1, 2013, 3:30:08 PM12/1/13
to Tarmigan, distributed, golang-nuts, Erwin
2013/12/1 Tarmigan <tarmig...@gmail.com>:
> Hi Vasiliy,
>
> The intention with goserial was to communicate with hardware serial ports
> rather than virtual ones. That said, I don't see why it shouldn't work.
> Does your go program want to connect to /dev/vport0p2 instead of
> /dev/virtio-ports/org.mighost.agent.0?
>
/dev/vport0p2 is symlink to /dev/virtio-ports/org.mighost.agent.0

> On the wiki page you pointed to, there are testing instructions for the
> serial port:
> https://fedoraproject.org/wiki/Features/VirtioSerial#Testing_console_IO
> do those instructions work for you?
>
yes it works fine

> Does screen work for you?
> screen /dev/virtio-ports/org.mighost.agent.0 115200

No. screen says that it not tty.

Vasiliy Tolstov

unread,
Dec 1, 2013, 3:30:45 PM12/1/13
to Tarmigan, distributed, golang-nuts, Erwin
2013/12/1 Tarmigan <tarmig...@gmail.com>:
> Hi Vasiliy,
>
> The intention with goserial was to communicate with hardware serial ports
> rather than virtual ones. That said, I don't see why it shouldn't work.
> Does your go program want to connect to /dev/vport0p2 instead of
> /dev/virtio-ports/org.mighost.agent.0?
>
> On the wiki page you pointed to, there are testing instructions for the
> serial port:
> https://fedoraproject.org/wiki/Features/VirtioSerial#Testing_console_IO
> do those instructions work for you?
>
> Does screen work for you?
> screen /dev/virtio-ports/org.mighost.agent.0 115200
>
> Thanks,
> Tarm


I think that main problem, that it not tty, but need read/write like
ordinary file.
Reply all
Reply to author
Forward
0 new messages