Uncategorized

Mixology Bot: Talking to Arduino ||

The Arduino Playground taught me that linux treats serial connections as a file. That means they can be read like a file and written to like a file, with a little massaging. Here’s how to work out the knots:

[code]stty -F /dev/ttyACM0 cs8 57600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts[/code]

Honestly? I don’t understand it. It’s deep magic that I don’t have time to get into. Something about what the serial connection should and should not deliver.

Anyways, once that’s done I told the raspberry pi to send any new data straight to my screen like this:

[code]tail -f /dev/ttyACM0 &[/code]

tail is a command to display the end of a file. The & tells it “do this in the background so I can get on with my work.”
It now shows me every message coming from the arduino, right on the command line. The very first thing I see is

[code]Mixologybot 1[/code]

1 is the firmware version. I could then echo a command to the arduino like this

[code]echo "help;" > /dev/ttyACM0[/code]

and it responded correctly, but only the first time. Looking closer at the output I realized there was a mysterious newline (the code for the return key) added after every command. My first Google hit for “echo without newline” taught me that raspberry pi needs one extra command. Now I use

[code]echo "help;\c" > /dev/ttyACM0[/code]

The \c removes the newline automatically inserted by bash and makes all communications work as expected. Hooray!

This means I can now have the RPI and the Arduino talking together. The next step is to set up a bash script that pipes commands from PHP to the arduino and back. That way a user can see that the drink robot is ready to pour and tell it what drink to make. Anyone know how to make that happen? Write me, please.