Thanks to Brian Hines for sending in his write up! View more here.
I’ve spent good bit of time over the last month experimenting with messaging queues as a way to remotely control the GPIO pins on a Raspberry Pi. It’s turned out to be a nice strategy, so I published a couple of Python libraries (Pi-Control-Service & Pi-Control-Client) to make it easy for others to use this approach as well. After sharing these libraries on a couple sites, it was brought to my attention that not every Raspberry Pi owner may be familiar with some of components I was using, like RabbitMQ. To help out, I’ve put together a small example explaining how to get started.
We are going to remotely control a single LED connected to a GPIO pin on a Raspberry Pi. We will be able to turn it on and off, as well as read its current state at any given moment without being directly connected to the Raspberry Pi. The example may be a bit contrived, but once you see how easy it is you’ll come up with something more interesting to control than an LED.
Before diving into the code, we need to get a few things setup:
- Wire an LED to pin 18 on your Raspberry Pi. To do that you will need not only an LED, but a 330 ohm – 1000 ohm resistor. If you’re not familiar with how to do this, the Wire LEDs page from this Adafruit Learning System tutorial has great step-by-step instructions with photos: https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds/wire-leds.
- Connect the Raspberry Pi to the Internet. If you’ve never done that before, the easiest way is to use an Ethernet cable, as outlined on this page: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/using-a-wired-network. If you have a compatible USB WiFi adapter, you can also follow the instructions here to connect wirelessly: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-3-network-setup/setting-up-wifi-with-occidentalis.
- Launch a RabbitMQ server. CloudAMQP makes this really simple by offering hosted RabbitMQ servers you can fire up with the push of a button, no configuration necessary. Sign up for an account and launch one of their free tier servers called: Little Lemur. After launch, you should see the console page below. The only thing you will need here is the connection URL. Copy that and save it for later
Each Friday is PiDay here at Adafruit! Be sure to check out our posts, tutorials and new Raspberry Pi related products. Adafruit has the largest and best selection of Raspberry Pi accessories and all the code & tutorials to get you up and running in no time!
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Maker Business — How Authority and Decision-Making Differ Across Cultures
Wearables — Brightness know-how
Electronics — Tactile Confusion?
Biohacking — Eight Health Leaders Explain How The Medical Industry Could Be Changed
No comments yet.
Sorry, the comment form is closed at this time.