Saturday, 28 February 2015

Tweeting Morse Code with Raspberry Pi and Arduino

I'm stuck at home and have seized the opportunity to prepare for a workshop that will link the Shrimp and the Raspberry Pi.

I love reusing previous projects. This one combines two bits of software that I prepared earlier :)

Twitter client meets Morse Code flasher

The core idea is simple. The project listens to what's happening on Twitter, and displays selected tweets by flashing the contents in Morse Code.

You could do this using the Pi on its own, or the Arduino on its own, but the project is easier and more reliable if you combine the strengths of both platforms.

Why the Pi?

It's possible to run a Twitter client on the Arduino but you're pushing the hardware to its limits. I've found some Arduino Internet libraries to be unstable, and your application is likely to be using most or all of the Arduino's limited program and data memory.

The Pi's memory is roughly a million times larger than the Arduino's RAM, and Internet applications are very stable. There are several Python-based twitter clients on the Raspberry Pi to chose from. In an earlier project I picked tweepy, which was easy to use and well supported.

Why the Arduino?

You could write a morse code flasher on the Raspberry Pi but

  • you'd need some extra hardware to flash an LED, and
  • you couldn't easily ensure that the Morse code timings were correct.
The difficulty with timing comes from the fact that the Pi is running a multi-tasking operating system. This means that your application can be preempted by a more urgent task at any time.

If you've just turned the LED on, it will stay on until your program gets a chance to turn it off again. There's no way to predict how soon that will be.

By contrast the Arduino has no Operating System, so timing is much easier to predict and control.

Connecting the two

It's not hard to write a Morse Code flasher for the Arduino, and I use that as one of the exercises in Life after Blink. It took me a couple of minutes to install the code on an Arduino, and a few more to get the Arduino talking to the Pi over a serial connection using py-serial.

I already had the Twitter client code from my earlier project. The project filtered the stream of tweets, printing all those with a particular hashtag. I installed the script on the PI and modified it to send its data over the serial port.

Voila! As tweets are received the Python program  sends their text over a serial link to the Arduino. Then the Arduino converts the text to Morse Code and flashes out the content using the on-board LED.

What next

There are a few more things I plan to do. 
  • replace the Arduino with a Shrimp.
  • improve buffering so the project can handle very popular hashtags
  • make the script and sketch available on GitHub
I'll tweet when I've done them; follow @rareblog if you're interested.

Please comment below if you have any questions, or have ideas about how to improve the buffering!

Friday, 27 February 2015

More Arduino workshops coming soon

Shrimp and Pi
I'm excited that I've been asked to run a workshop in April at #CG3 - the next Covent Garden Jam. Contents and date to be decided, but I've had at least one request for a Shrimp and Pi session, which would be a lot of fun.

There are a couple of ways that you can connect the Shrimp to a Raspberry Pi. You can use the CP2102 USB-to-serial converter normally used to program the Shrimp, or connect the Pi's serial port on the expansion header to the header on the Shrimp.

Either way you can then
  • program the Shrimp via the Pi using the Arduino IDE, and
  • use Serial communications to send data between the Pi and the Shrimp.
I have a fun application in mind, and it should be easy to set up as it combines one of my first bits of software on the Pi with a sketch from my Life after Blink workshop (see below). I'll tell you more when I've got it running :)

Shrimping It solo!

A couple of people have lamented that they couldn't attend last Saturday's workshop at the Southend Raspberry Pi jam.

The workshops are great fun but it's perfectly possible to build the Shrimp on your own. You can buy what you need from the Shrimping It! website:
  • The basic Shrimp Kit
  • A suitable breadboard
  • A Programmer
You may already have a suitable breadboard, and you can use a 5v FTDI cable if you have one, but if not, the parts will cost under £10 + postage, which is just £1 for UK customers.

There are good instructions on the Shrimping It! website, but if you want you can splash out $1.49 (+VAT if you are in the UK) for a copy of Making the Shrimp.

That's the e-book I wrote for use on the workshops.

It's only 95% complete, since I don't yet cover making a stripboard version of the Shrimp, but if you buy books on Leanpub you get future updates free.

Life after Blink is on its way

I'm nearly ready to release another e-book on Leanpub.

Called Life after Blink, it's based on an online course I ran last year.

It's a risk-free purchase, since Leanpub offer an unconditional 45-day money-back guarantee. I'll also be releasing a sample so you can try before you buy.

Life after Blink covers a series of experiments you can do after you've uploaded your first Arduino LED-blinking sketch.

You'll learn how to
  • program an Arduino-based cookie server to dispense wisdom to your laptop
  • generate and flash Morse code signals from text you type
  • control a family of LEDs to display ripple patterns and binary numbers
  • annoy your friends and family by making sounds from inside your sketches
  • monitor light levels using an LDR sensor
You can purchase the components you'll need individually or get an inexpensive kit from SK Pang.

You'll also need an Arduino or a Shrimp.

You can register your interest here to get notified by email when the book is available.

Tuesday, 24 February 2015

Another Splendid Shrimpy Southend Raspberry Jam

Last Saturday I went to the monthly Raspberry Jam at Southend-on-Sea to run another Shrimping It! workshop. I've run several of these before but this is the first one I've run at an event that focusses on the Raspberry Pi.

Arduino and Pi

There's a growing interest in using Arduinos (or clones) in tandem with the Raspberry Pi.  Cefn Hoile, father of the Shrimp Arduino clone, has even co-authored a book on the subject.

Alex Eames, of RasPi.TV fame, has a project called RasPiO Duino on Kickstarter. Its Arduino-compatible board sits on the Raspberry Pi header, and you can program and control the AVR chip from the Raspberry Pi. The Kickstarter is still open. If you want a RasPiO Duino, back it today!

I've been keen on the approach for a while, and I use it in C3Pi.

It's not surprising that many Raspberry Jams now encourage talks and workshops on the Arduino, and that's why I was at the Southend Jam.

Making the Shrimp and other attractions

I've visited the Southend Jams several times before. They're a friendly, lively community, and this time over 400 people signed up for the event. The Making the Shrimp workshop went well but it was just one of a series of great talks and workshops, covering everything from Quadcopters to Wearable Electronics.

Want to make your own Shrimp?

If you missed the workshop and like the idea of making the Shrimp, I've written a short, low-cost e-book which tells you exactly what to do.

The book tells you where to get the components you'll need. They cost abut £10.

Coming soon

The event inspired me to resume work on a related e-book. I hope to have more news about that in the next few days.

Want a workshop at your event?

The word about Making the Shrimp is spreading, and I run workshops pretty regularly. If you'd like me to run one at your event, contact me on G+ or twitter