Arduino to PC communication

Hello. I'm evaluating using an Arduino board to produce an I/O board from a Linux box. I would have a Linux program running and communicating with the Arduino to read inputs and open outputs. I'm guessing this would be with a serial cable, but I'm open to suggestions.

Can someone point me to a project or sample code where the communcation has been done before? I did a search, but the results weren't specific enough to my application.

Thanks.
Jeff

The arduino has onboard USB, so that seems to me to be the most obvious choice. It's limited to 115.2k, which is less than ideal but should still work for you.

On the Arduino side, the Serial library provides access to the USB port. I'm not sure how fast it is compared to the printf() functions from avr-libc, but it is a bit easier to use.

On the Linux side, the Arduino will show up as a ttyUSB device and behaves like any other tty.

And if you are using Processing you can communicate with the Arduino easily via the ftdi usb link (see Arduino Playground - Processing).

Thanks guys (or gals)! Thats good information.

The least expensive I/O board I could find with 4 inputs and 4 outputs was $120. I hope to make a much less expensive version with more features for what I need. Of course, I'll have to assemble a board with some optoisolators and some relays.

Thanks!

Arduino is great for prototyping, I use my Arduino Mega for all sorts of stuff like driving servos, reading PWM/PPM signals, interfacing with i2c devices (WiiMote), reading from sensors, etc. It's a great 'swiss army knife' of sorts. Downside of the mega for me is that it's 5v, but whether that's a bad thing for you depends on your project.

Have you looked at Teensy USB Development Board? It uses a slightly different class of AVRs that have USB slave support. Same broad range of I/O including PWM, pin change interrupts, usart, spi, ADC, although no i2c afaicr. The form factor is fantastic, and the communication with the PC is a bit more elegant since you can design your own USB protocol/driver. Code exists to make it act like a USB serial port or HID device (mouse, keyboard). You of course won't use the Arduino language with this device but I personally never use that anyway :3

Imho, if you want something quick & easy, get an Arduino because they are dirt cheap, trivial to interface with (serial port), and will get the job done in the shortest amount of time. If you want something cool & elegant, I'd go for a teensy.

edit: teensy does support the arduino language/ide: Teensyduino - Add-on for Arduino IDE to use Teensy USB development board

I did look at the Teensy, but as far as I could tell, there isn't the developer community around to support. The Arduino appears to have more users and assistance.

Parallax has by far (IMO) the best support, but their chips don't have analog inputs built in like the Arduino.

Thanks.

For prototyping, ypu might try running Firmata.

That enables a host program to use the Arduino's I/O apparently directly (clearly there is a whole pile of code in there, but it is mostly transparent). This might not be what you eventually end up with (I've designed my own protocols), but it might be a good prototyping path.

HTH
GB

@jeff: teensy works with the Arduino language and IDE, so no problem there. If you decide to go the pure C route, there's always http://www.avrfreaks.net/.

But yeah, if you just need to hook up a couple of things Arduinos are great. Get a cheap chinese clone to save a few bucks. I got my Arduino mega on ebay for ~29 euros incl. shipping.

My knowledge of what the teensy is is very limited, and I would love a brief explanation of it. I scanned the forums here, but most of the discussions were by people that already experts and didn't do the newbie explanation.

What I deciphered from conversations (please correct me if wrong) is that the teensy is a cheaper alternative to the arduino and can use arduino code with a 'duino' add on? Oh, and it uses USB instead of serial?

Although, looking at sparkfun.com, the arduino isn't that much more expensive than teensy, so that sort of clouds that assumption.

Please educate me.

Thanks!

My knowledge of what the teensy is is very limited, and I would love a brief explanation of it

I have been using a teensy for a while now and really like it. It's tiny, inexpensive, lightning fast uploading sketches (when you make changes to your sketch code), and has more memory and pins than the standard Arduino board. Its small form factor means that you can't plug in shields but that is the only limitation I have come across so far.

So, my advice is that if you want the capability to use the wide range of plug in extension boards (called shields) than a standard Arduino is the better choice. Otherwise, the teensy is highly recommended.

Its funny you mention shields. I was just reading some posts on them such as the nuelectronics ethernet shield and the temperature measuring shield.

Dumb question though, can you still connect a shield through a breadboard or soldering? And if so, can you stack shields from the shield that was installed?

If the connections could be done, its a shame no one has produced a carrier board that the teensy plugs into, and that has the female risers that can accept a shield.

Edit: forgot to say thanks. Thanks!

Yes you could connect the shield pins to the correct pins on a teensy and I would expect it to work. Unfortunately, the pin spacing on a standard Arduino board and shield is not breadboard compatible so it's not something that would plug straight in, but if wired up correctly it should be ok.

There are breadboard friendly alternatives to shields that you can use, for example, this is how I connected Ethernet to my Teensy.

The chip is the same as used on the Arduino shield so the Arduino Ethernet library works with this. (the Ethernet board shown is from here: http://www.nkcelectronics.com/wiznet-wiz812mj-tcpip-network-mod812.html)

My knowledge of what the teensy is is very limited, and I would love a brief explanation of it.

mem has done a great job, but I'd like to emphasis the thing that makes Teensy interesting to me.

IMHO the killer benefit of the Teensy is the Atmel microcontroller has the USB on the chip, whereas the Arduino uses a separate FTDI USB to serial chip. This means the Teensy is cheaper and smaller than an Arduino, but that's not the best part.

The Arduino needs the FTDI drivers installed, and always looks like an FTDI thing.

The Teensy runs the USB interface code itself, and you can program it to implement a range of USB devices. Dean Camera's LUFA (Lightweight USB Framework for AVRs) implements a range of USB devices (have a look, it's a long list) and is available under a nice MIT Open Source license.

The upshot of implementing USB on the Teensy is you can make almost any USB device you want, but more importantly, you can avoid the need for the FTDI driver. Your Teensy-based device can look like a keyboard, or a flash drive, or a serial device, and use the Operating Systems pre-installed USB device driver support. You could walk upto any reasonable computer and just plug it in.

Because the device can look like different USB devices, the talented Mr Camera's LUFA has several bootloaders. Some Operating Systems support DFU (Device Firmware Update), so you can bootload with nothing else. No avrdude, no driver, nothing. At worst it can be booted directly with an Open Source program called dfu-programmer, again without drivers.

The AT90USBKEY can also run LUFA.
[edit]It has a AT90USB1287, which Atmel says is:

128KB self-programming Flash Program Memory, 8KB SRAM, 4096-Byte EEPROM, USB 2.0 Low speed and Full Speed On-The-Go (OTG) Host/Device

for a similar price to an Arduino (in my experience Atmel do a low cost initial price to get interest, then push up the price later)[/edit]
If only Atmel made this stuff in through-hole DIL packages like PICs (are you reading this Atmel?). It would be near perfect; a breadboard friendly USB slave, able to implement many USB devices, with no need for device driver installation, and with DFU pre-installed, so no need for a ICSP programmer. This would let us breadboard a working USB machine for under £5.

Sorry, I got carried away. I bet you can guess what I want for my brithday? Yes a DIL package ATmega32U4!

HTH
GB

Thanks GB, thats great information. Being able to make it a USB device easily is a real advantage.

How hard do you think it would be to make a USB device that you plug into a digital camera (with a usb cable) and have it wirelessly (Xbee?) download your pictures to your harddrive on your server in the house? That would be cool. WAY beyond what I could do, but if any of you are thinking about inventing it, I'd buy it.

I guess the answer depends somewhat on your camera.
If it is happy being controlled with USB On-The-Go(OTG), then the hardware is straightforward, and that AT90USBKEY would be sufficient.

[edit]I don't know enough about cameras to be definitive, but you could probably make your life easier by using a Canon camera and installing CHDK. That gives more flexibility to interact with the camera features, and may let you put a bit of intelligence in the camera to help, like a little script.[/edit]

If it needs a 'proper' USB host, I'll have to go looking for a chip. I've only interested in USB slaves, or USB OTG for small devices, and look to ARM for hosts.

If the hardware is okay, then next problem would be accessing the camera. Does it look like a flash drive? I believe there is code for implementing a flash drive in LUFA, so there is a start.

I think the wireless comms. could be WiFi, Zigbee, Bluetooth, or something simpler. Depends on the power available on the camera side, and what you have at the other end (i.e. is it a pull by the remote side, or a push, and is there an Arduino in the house).

If you want to stimulate this, maybe post a new thread to collect together ideas?

HTH
GB

Yeah, it is a bit off topic, and not something I'd be interested in building anyway. I was just thinking about USB possibilities.

There is something I want to eventually build that I have questions on. I'll post it on a different thread.

Thanks. :slight_smile: