Quantcast
Channel: Sullerton
Viewing all articles
Browse latest Browse all 12

RaspberryPi and Arduino playing nicely together.

$
0
0

After seeing Eric Maundu’s video about his aquaponics setup in Oakland, I was pretty inspired to finally try and put my arduino to good use. In the past, I had hit walls using the arduino because I failed get it setup to a wifi network, and therefore never got to the point of programming it to do anything useful for me.

This summer I grabbed a raspberryPi, which allows me to write all my code in python and has everything that comes with linux, like painless networking. Although the pi is the coolest thing since sliced bread, it has no analog inputs on its GPIO, so there is no easy way to measure inputs like temperature, only digitally (off/on). You can, however, easy communicate between the pi and the arduino serially over usb to use the arduino’s analog inputs.

Ultimately, I would like my aquaponics setup to be out in the back garage, which means a wifi connection to my raspberryPi to post data (I dont want the pi to be my SOR). Again, I struggled to get the wifi adapter setup. Below is the wpa configuration that ultimately worked to get my Edimax WiFi Adapter connected to my Cisco wifi router.

Once you have the drivers installed for the wifi adapter. Add these lines to your /etc/network/interfaces file:

auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

now you must go create or edit your wpa_supplicant.conf file, the configuration that worked for me looked like this:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="my ssid"
scan_ssid=1
key_mgmt=WPA-PSK
psk="my secret passcode"
}

replacing my ssid and my secret passcode with your routers settings. Make sure the router is broadcasting it’s ssid.

Reboot your raspberryPi and you should see the edimax light up blue and grab an ip address from your router. This now allows me to ditch the keyboard and mouse, and put my raspberryPi out in the garage to control my garden. When I need to update anything, I can ssh into the pi.

Using the Python Arduino Prototyping library, I’m able to read the analog inputs of the arduino on the pi by connecting to it via usb. I have an arduino Uno, so the arduino shows up on the pi as '/dev/ttyACM0'. If you are unsure which device is the usb, run ls /dev with the aruduino plugged in, and then again with it disconnected. Go find the device that disappeared; it probably begins with ‘tty’.

NOTE: if you are ssh’ing into the pi and using a non-root user (e.g. not the default “pi” user), make sure you add your user to the dialout group, before you will be able to access the arduino over usb. You can add yourself to the group by issueing the following command (replace “pi” with your username):
sudo usermod -a -G dialout pi
Log in again to make group changes take effect.

Now I am able to run this python code on the pi and control the arduino:
mattotodd@raspberrypi ~/garden-project $ python
Python 2.7.3rc2 (default, May 6 2012, 20:02:25)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from arduino import Arduino
>>> a = Arduino('/dev/ttyACM0')
>>> a.setHigh(7)
True

Its a very small step to make an LED light up, but I feel like I’ve moved the first brick. I hope to log more of the progress here as the project moves along.

Here’s a little demo


Viewing all articles
Browse latest Browse all 12

Trending Articles