grmnygrmny
Posts: 6
Joined: Mon Nov 28, 2011 6:31 pm

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 2:16 pm

I'm working on a project that will involve a Raspberry Pi talking with an Arduino over a USB-Serial adapter.  I'm fairly certain the USB-Serial adapter will work with the default kernel drivers, but I'm not sure which language I should program in to access the port.

Python and Java definitely have libraries for communicating over serial but the likelihood that I could successfully compile a library for ARM is... minimal.

Does anyone have any experience with this, in Linux specifically?  What's the best way to do this?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 2:55 pm

I think the best way to do this, is to use whatever language you're most comfortable with. In python or Java it's the same as on your current PC (whatever OS).

C and C++ programs will work if you compile the source code on the raspberry pi itself. The tools are the same. You will surprise yourself.

Edit: In stead of connecting to "com1", you'll connect to "/dev/ttyUSB0". That's the main difference.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

davidgoodenough
Posts: 74
Joined: Wed Sep 21, 2011 11:55 am

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 3:01 pm

librxtx-java (which is the Debian package for serial comms for java) is available on both ARM flavours (armel and armhf).  Not quite sure which of the two is right for Raspberry-Pi, but armhf is right for the BeagleBone so it is likely to be right here too.

Don't know about Python, but my guess is that its serial library is also available.

As I said in another reply on another thread, go for a distribution that already builds for multiple architectures (librxtx-java is available for 18 different architectures as are most Debian packages) and you will find that the problem is already solved for you.

grmnygrmny
Posts: 6
Joined: Mon Nov 28, 2011 6:31 pm

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 3:19 pm

davidgoodenough said:


librxtx-java (which is the Debian package for serial comms for java) is available on both ARM flavours (armel and armhf).  Not quite sure which of the two is right for Raspberry-Pi, but armhf is right for the BeagleBone so it is likely to be right here too.

Don't know about Python, but my guess is that its serial library is also available.

As I said in another reply on another thread, go for a distribution that already builds for multiple architectures (librxtx-java is available for 18 different architectures as are most Debian packages) and you will find that the problem is already solved for you.


That's... amazing.  I was hoping this would be the case, currently setting up a QEMU environment to test and was hoping Debian would have some packages on hand.

grmnygrmny
Posts: 6
Joined: Mon Nov 28, 2011 6:31 pm

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 3:20 pm

panik said:


I think the best way to do this, is to use whatever language you"re most comfortable with. In python or Java it"s the same as on your current PC (whatever OS).

C and C++ programs will work if you compile the source code on the raspberry pi itself. The tools are the same. You will surprise yourself.

Edit: In stead of connecting to "com1", you'll connect to "/dev/ttyUSB0". That's the main difference.



I currently do some stuff in Java, I only asked because I was concerned that the libraries I was using may have been hard-coded for x86.  I see now that this is not the case, and I'm thrilled.

Svartalf
Posts: 596
Joined: Fri Jul 29, 2011 6:50 pm

Re: best language for R-Pi serial communication

Fri Jan 13, 2012 11:41 pm

grmnygrmny said:

I currently do some stuff in Java, I only asked because I was concerned that the libraries I was using may have been hard-coded for x86.  I see now that this is not the case, and I'm thrilled.

Nope.  Should be able to do it in Java, Python, or C/C++ (There's a few good thin shim libraries that make your serial stuff cross-platform and cross-arch in C.)

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: best language for R-Pi serial communication

Sat Jan 14, 2012 12:10 am

Hi,

I found this useful article complete with C code for communicating with Arduino from bash

http://todbot.com/blog/2006/12.....o-arduino/

I tested it on SuSE 12.1 and works flawlessly for sending serial to an Arduino – if you are after a way to communicate via a web server on the Pi you can always run it as CGI

As it's C it should compile on the Rasberry Pi – build instructions are included in the code.

Hope this helps!

Return to “Other projects”