Category Archives: Raspberry Pi

Bleeding edge: Arduino on Raspberry Pi

Well, Arduino doesn’t “just work” even with the instructions I gave in my last post. If you don’t “prepare”  your distro carefully, you’ll run into the comm problems I did (and thanks to Mark Amos, for pointers and encouragement!).

First, make sure you have a good power supply both for your Pi, and for your USB hub.

My belkin hub (one would think it would be good) would drop the mouse as soon as the Arduino IDE started up.

I ended up using a Staples hub (I can’t find it on their website, must be older.) powered off a 2 port Belkin USB power supply. I’m using a separate high amp Griffin USB power supply for the Pi.

I was having a problem in which I could download programs via AVRdude, but the Arduino IDE would have communication problems, and then the ports would be locked after Arduino was exited.

I believe the problem was due to me not setting the timezone, and date on the Pi. I think it didn’t like living in 1969.  I don’t know if this was a problem for the software install, or the port handling by Arduino, but once I properly prepared, everything worked!

I’ve rebuilt the system several times and here are a few tips.

I’m using debian squeeze from the Raspberry pi site, and it defaults to a British keyboard layout. That’s fine if you’re there, but some of the following edits will be painful unless you change:

[code]sudo dpkg-reconfigure keyboard-configuration
sudo dpkg-reconfigure tzdata[/code]

reboot

Before getting any of the other packages:

[code]sudo apt-get update[/code]

and again:

[code]sudo apt-get update[/code]

FTDI Arduinos work fine with the driver loaded in the last post, but the UNO isn’t recognized right away. This is because the IDE only looks for certain names (/dev/ttyUSB1, /dev/ttyS0 etc.)

Once again the RaspberryPi@homelabs blog comes through:

GarretT says:

[code]

There’s a little hack you have to do to make the IDE work with UNO. I think it stems from the way the code checks for serial devices.

1) Before running the Arduino IDE, plug in your Arudino UNO.
2) Observe that there is now the device /dev/ttyACM0 writable by the dialout group of which pi is a member.
3) Make a hard link ttyS0 to that device. It’s a little easier if you cd to /dev.

cd /dev
sudo ln ttyACM0 ttyS0

4) Start the Arduino IDE and load a sketch.
5) Under Tools->Serial Port select /dev/ttyS0
6) Upload your sketch. Sweet!

[/code]

Likewise you can link the internal UART:

[code]
sudo ln /dev/ttyAMA0 /dev/ttyS1

[/code]

I hooked up an Arduino Pro 3.3v, and by holding down the reset until the IDE says “downloading” I was successfully able to download to it via the GPIO mino UART

Important Note: Those hard links go away with each boot, so you have to make them again each time you reboot before running the IDE.

 

 

Preparing for à la mode: Raspberry Pi and Arduino

Well, I got my Raspberry Pi, and preparations are well underway to make an Arduino compatible clone that fits right on top.

Anool Mahidaria has completed an initial circuit design, and I’ve gotten some of the software set up. Lots of information out there that helped me figure out what to do, so I thought I’d compile it here in one place.

à la mode will connect via the uart on the GPIO, so we need to figure out how to enable serial communications, and get the Arduino environment installed.

Serial port: An embarrassment of riches?

The Pi’s Broadcom brain has a very rich set of peripherals, unfortunately it was hard for the Pi’s designers to route them all out to a connector. There’s a limited functionality min-uart that is very well supported, and at least in the debian image I’ve tried has drivers.

It doesn’t have hardware handshaking or DTR (needed for auto reset on the Arduino) but is supported at this stage so I think that’s what we’ll go with. There’s also a fully featured UART, and most of it’s compatible pins are brought out to the GPIO connector, but as far as I can tell, it’s not fully supported in the distributions generally available for the Pi.

The GPIO connector is well documented on the Pi’s wiki:

But I found this blog post most helpful: http://lavalink.com/2012/03/raspberry-pi-serial-interfacing/ from which I get this useful illustration.

That’s great, but it turns out that the Serial port is a little too well supported. (Caveat, I’m talking about the recommended Debian Squeeze image) You can log into it as a console! This, of course, prevents you from opening the port in a program (such as Arduino), so we need to disable logins on this port, as well as logging messages that go out. This post explains how to disable both.

I’ll repeat the instructions here, in case the link goes away:

First, disable logging messages:

Edit /boot/cmdline.txt

From:

[code]dwc_otg.lpm_enable=0 rpitestmode=1 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait[/code]

to:

[code]dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait[/code]

deleting the two parameters involving the serial port /dev/ttyAM0

You also have to edit /etc/innitab to remove the login (getty)

comment out:

[code]2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100[/code]

then reboot.

Arduino IDE:

The Homelabs raspberry pi blog has good concise instructions for installing the Arduino IDE. The IDE is written in Java (based on Processing) and while Oracle doesn’t have an official Java for the ARM core in the Pi, the Open JDK has been ported. It doesn’t have a JIT (Just In Time Compiler) so it’s a little slower, but it works.

First grab the Arduino IDE code. (you can change the url if you want the latest)

[code]wget http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz
tar zxvf arduino-1.0-linux64.tgz[/code]

The Arduino IDE is written in Java, but there are native parts to do compilation for the atmega328p  microcontroller. Fortunately those have also been ported:

[code]
sudo apt-get install avr-libc
sudo apt-get install libftdi1
sudo apt-get install avrdude

[/code]
Java:

[code]sudo apt-get install openjdk-6-jre[/code]

Serial support:
[code]sudo apt-get install librxtx-java[/code]

And then copy the native stuff into the Arduino directory:

[code]
cd arduino-1.0
for i in $(find . -name “librxtxSerial.so”) ; do cp /usr/lib/jni/librxtxSerial.so $i ; done
for i in $(find . -name “RXTXcomm.jar”) ; do cp /usr/share/java/RXTXcomm.jar $i ; done
cp /usr/bin/avrdude /home/pi/arduino-1.0/hardware/tools/avrdude
cp /etc/avrdude.conf /home/pi/arduino-1.0/hardware/tools/avrdude.conf

[/code]

After this, you can attach an Arduino to one of the USB ports, or (carefully) a 3.3 v clone to the GPIO pins.

More to come!

 

 

Raspbery Pi à la mode ?

Lot’s of people are excited about the Raspberry Pi®, a complete computer for $25 (or $35 with ethernet).
The initial shipment is entirely sold out, and there are 200,000 more on order. Lots of people have been saying that this is the end of the Arduino, as it’s about the same cost, a full linux system with keyboard, mouse, and hdmi video output.

I think this is an oversimplification. Arduino is fantastic at interfacing to the physical world in a way that no linux (or Windows) PC could hope to approach at any cost.

The Pi does have a GPIO connector, but it pales in comparison to the humble Arduino. No built in PWM (servos anyone?) and no Analog to digital conversion.

Why throw the baby out with the bathwater? How about some delicious ice cream with your Raspberry Pi?
As a member of the amazing Open Source Hardare collective Wyolum.com,  I’m working with Justin Shaw and  Anool Mahidharia on “à la mode”: an Arduino clone specifically for the Raspberry Pi (That rendering above is courtesy of our  fabulous  EE  Anool) . You can of course connect an Arduino to a Pi USB port, but when you want a turnkey solution, how about an Arduino compatible “plate” (what the Pi folks call shields) that fits right on top of the Raspberry Pi.

You can plug your existing shields right in,  and you can even run the Arduino IDE on the Pi. Since the Pi’s core mission is to provide equal access to computing to all children, this will also give the kids the opportunity to mix it up “Arduino-style” with real world hardware.

We couldn’t have a vanilla add-on, so we added:

  • A battery backed real time clock: RTC: DS3231 (same as ChronoDot)
  • uSD card for logging
  • Socketed Atmel Atmega 328p in case you make a wiring mistake and need to replace it.

We’re sending off for prototype boards soon, so if you have feedback, let us know! Join the conversation at the Wyolum.com forums.

Raspberry Pi® is a trademark of the Raspberry Pi Foundation.