Pages

Saturday, 28 September 2013

Text LCDs and the Raspberry Pi

One project I'm hoping to complete in the next day or so is an I2C-based Text LCD for use with the Raspberry Pi.

Why bother? After all, the Pi has an HDMI output, and it's easy to connect the Pi via Ethernet or wireless.

The problem is that there are situations where you really need a stand-alone display.

Stand-alone Pi Projects

If you're building a battery-powered  stand alone project you may need an output mechanism that's a bit more informative that a few flashing LEDs,  your power budget may not run to WiFi, and you may want to use what you're making in an environment where a network-based solution is not practical.

Another application: running a physical computing course

It may be hard to connect to the Pi because you don't know its IP address.

Earlier this year I helped to run a couple of workshops covering physical computing on the Pi. Practical considerations meant that we couldn't use monitors for each Pi, and we had to connect to the local network using DHCP.

It would have been really helpful if we'd had a text LCD for each Pi displaying its assigned IP address.

3 popular ways to link the Pi to a text LCD

There are plenty of articles on the web explaining how a Pi can drive a text LCD. I've listed a few at the end of this post.

They fall into three main groups.

  1. Some drive the LCD via the Pi's GPIO pins
  2. Some use I2C with a port expander like the PCF8547 or MCP23008
  3. Some commercial products use I2C with a slave micro-controller which then drives the LCD

No-one is prefect

Each approach has some disadvantages.
  1. The main problem with using the GPIO pins is that there are only eight of them (not counting the special-purpose pins which may already be in use). Driving the LCD display will use at least six of them. For many projects, that's not acceptable. It certainly wouldn't work for our courses where several of the labs involve driving things via GPIO.
  2. I've used the port expander approach in past projects. It works, but it requires a lot of traffic on the I2C bus; you need to send multiple bytes over the bus in order to display a single character. For some applications this causes an unacceptable bottleneck on the I2C bus.
  3. I like this approach, but it's not cheap. Most I2C-based LCD displays cost almost as much as a Raspberry Pi!

My preferred approach: hacking the veroduino

The approach I'm trying was suggested by my first experiment with the teensy 3.0. I'm going to build a simple veroduino (see below) which I will control over I2C. On the software side, I'm going to merge the standard Arduino I2C slave example with the LiquidCrystalFast library, adding some simple control code.

I'll publish diagrams and code when they are ready.

Web resources



One good example of a port-expander based approach is the Adafruit LCD backpack, and there's a tutorial in the Adafruit learning system.


I did a very short write-up of a good commercial micro-controller based I2C LCD product.






Friday, 27 September 2013

The Arduino Yún just keeps on going

The Arduino Yún has been running for a couple of days now.

Nothing earth-shattering about that, you might think:  one of my Linux boxes got rebooted  just four times in a decade, twice for house moves, once for a power cut, and once for a kernel upgrade.

However,  my Arduino Ethernet board crashes repeatedly after a few hours of air-time. I don't know whether that is due to software problems with the Ethernet stack or a hardware issue, but the Yún seems much more reliable.

Thursday, 26 September 2013

Driving text LCDs with the teensy 3.0

A few days ago I started exploring the teensy 3.0. I'm keen to see if we should consider using the teensy for C3Pi, so I want to get more familiar with the teensy hardware and the development environment.

When you install teensy's extensions to the Arduino IDE you are given a chance to install a number of additional libraries that have been tested on the teensy family. One of them - LiquidCrystalFast - caught my eye and I decided to explore it in more detail.

The LiquidCrystalFast library

LiquidCrystalFast is yet another library for driving text LCDs based on the ubiquitous Hitachi HD44780. I love these displays, and so do many hobbyists; a old post about an Arduino DVM with LCD display is one of the most visited pages on this blog.

The standard Arduino LiquidCrystal library works pretty well, but suffers from two minor issues.

The first is that it doesn't work as it should for 4-row 16-column displays. (It's fine for 2 row displays and for the 4-row 20-column variety).

The other issue is that it relies on precise timing of the signals it sends to the LCD.

Two LCD Driver designs

Displays based on the HD44780 can be driven uni-directionally or bi-directionally. The standard Arduino library uses them uni-directionally, which means that the code contains delays to make sure that the display has time to process each command.

The LiquidCrystalFast library uses the data lines bi-directionally, and as a result it runs significantly faster. Display speed is not usually a problem, but using up too much of the Arduino's processing power can be. If you're trying to do lots of other work on the 8-bit micro, a slow LCD driver isn't ideal.

The library also fixes the bug with 4-row 16-column displays.

Don't fry your teensy!

The LiquidCrystalFast library is a little harder to use on the teensy 3.0 because of voltage incompatibility. Like most ARM-based systems, the teensy accepts inputs between 0 and 3.3 volts; most LCDs use 5 volt signals. If you're using the data lines uni-directionally, that's not a problem, as most displays work fine with 3.3 volt inputs. If you use it bi-directionally the display's 5 volt outputs could damage the teensy.

All this is clearly explained on the teensy website, along with a simple solution. You just insert four 1k ohm resistors between the data pins on the LCD and the GPIO pins on the teensy.

Don't get spaghetti on the Breadboard

The only downside of the hardware layout on the teeny website is that the wiring is a bit spaghetti-like. Neater layouts are easier to check.

Fortunately the library allows you to change the pin assignments on the teensy, and it's possible to do so in a way that lets you create really neat connections.

Here's a Fritzing diagram of the layout I ended up with. It was really easy to wire it up, and it worked right away.


The only thing you need to change in the provided LiquidCrystalFast sketch example is the statement that creates the lcd object, which should read

LiquidCrystalFast lcd(2, 3, 4, 9, 10, 11, 12);
        // LCD pins:  RS RW EN D4 D5  D6  D7

My next task is to modify the breadboarding and the sketch to use a stripboard-based arduino clone which I can drive via I2C; it's an enhanced version of an old project and I plan to use it with the Raspberry Pi and the Quick2Wire interface board.

Wednesday, 25 September 2013

Arduino Yún - first impressions

The Arduino Yún is the latest addition to the Arduino range, and it looks very exciting.

In this post I'm assuming that you are familiar with the Arduino and with Linux; I may write a beginner's introduction later.



The Yún combines the features of a traditional Arduino with a tightly-coupled Linux System-on-a-chip (SoC). The two are seamlessly connected via SPI using a Bridge class on the Arduino and some Python code on the Soc.

Easy internet connectivity

The Yún's Linux SoC makes it easy to integrate physical computing projects with the Internet. Previously you'd have needed an Ethernet shield or an Ethernet Arduino, using a fairly limited API which was not  always reliable. The Yún gives you many different ways to connect you applications to the internet. Some are useful but very simple; some will take longer to master but look extremely flexible.

Shield Compatibility

The Yún follows the form factor of its predecessors, so you can use it with many existing shields, or breadboard it as you would a traditional Arduino prototype. To develop software for the Yún you'll need a compatible version of the Arduino development environment. At the time of writing that's version 1.5.4, described as a beta though it's worked well so far in my limited experiments.

Connecting to the on-board Linux SoC

There's quite a bit of information about using the Yún on the Arduino website, including a getting started guide. I leapt in without following its process; I connected the Yún to its micro-USB cable, plugged in an Ethernet cable, and fired up the Arduino IDE. When I looked at the ports menu of the IDE, I could see an entry for an Arduino Yún at IP address 192.168.1.69. I connected to it as root using ssh and was rewarded with the logon screen of the embedded Linux processor:


Connecting to the network Console

Next I tried a quick code example from the Arduino website which uses the bridge to connect to the network-based console. It worked perfectly. The example lets you turn a LED on or off via a remote connection, and suggests a whole range of potential applications.

Connecting to Temboo

Encouraged by that, I tried the new temboo interface. Temboo offers a simple RESTful API that can access hundreds of different services from different vendors. Among them is an API that can access Google's geocoding service, which converts a Postcode into Latitude and Longitude.

It takes under a minute to sign up for a free account with temboo; once you have done so, you can use their API from a browser, from a program on your desktop computer, from a phone or tablet, or from your Arduino Yún.

When I tried the example I got confused by the fact that the Yún has two serial consoles available. One is USB-based, the other is telnet-based, and the temboo sample code uses the USB version. Once I'd got that sorted out, I could see my Yún connecting via temboo to Gooogle's geocoding API and correctly displaying my geocoded postcode.

Much more to explore

There's a huge amount of functionality available for the Yún, and it's going to take a while to explore it all. I have two other projects on the go at the moment, but I suspect I won't be able to resist the lure of the Yún for long!


Sunday, 22 September 2013

Three reasons why I like teensy 3.0

I've just been experimenting with the Teensy 3.0, and it's fantastic.



The teensy 3.0 is the latest member of Paul Stoffregen's teensy family. The teensy boards are USB-based micro-controller development environments, like the Arduino but teensy :)

Three reasons why I like teensy 3.0
  • ARM Hardware
  • Arduino Software
  • It's breadboard-friendly
ARM Hardware with lots of extra functionality

Early versions of the teensy used Atmel AVR chips, like the Arduino, but the teensy 3.0 uses an ARM processor.

The  teensy 3.0's CPU is a 32-bit MK20DX128 Cortex-M4 from Freescale. You can run it at up to 96 MHz. That's six times faster than the clock on a typical Arduino, and the speed is matched by plenty of memory for program and data. There's space for 128K bytes of program in flash and 16K bytes of data in RAM. As an added bonus, teensy 3.0 has plenty of pins, both general-purpose and specialised: 34 general-purpose GPIO pins, of which 12 can be used as analogue inputs.

The teensy 3.0 has too many pins to connect to its headers; the extras are brought out to solder pads on the underside of the board.



Arduino Software

These days it's easy to find inexpensive ARM-based development boards with their own development environments, but the teensy 3.0 is different: you develop software for it using the Arduino IDE. Almost  all the Arduino libraries are supported, as are many third-party libraries. I've had a quick play with the LiquidCrystalFast library, which is an improved version of the standard Arduino Text LCD driver; it works really well, and I'll write up the experiment next week.

Teensy Tips

I've found the teensy easy to work with, but I did hit a couple of minor snags which you'll want to avoid.

The first was entirely my fault. By default the teensy comes without header pins. I soldered mine in at an angle, and when I tried to repair my mistake I managed to make a solder bridge between the pins of the processor which was fiddly to remove.  The small form factor of the teensy means that you need to be very careful when soldering the headers.

The second problem was easy to fix. I'm running the Arduino software on a workstation with Linux Mint 15. I'd installed the Arduino environment from the appropriate repository, and had difficulty  in installing the teensy enhancements.

I might have been OK if I had run the installer as root, but instead I decided to remove the sightly outdated version of the Arduino environment and install an up-to-date zip file downloaded form the Arduino website. Once I'd done that, the teensy software installer worked perfectly and I had no trouble programming the device.

Overall the teensy 3.0, like its predecessors, is a well-thought-out product that's great value.

If you're looking for a product that combines the processing power of an ARM CPU with Arduino's ease of use, the teensy 3.0 is a great buy.

You can get it for $19 from Paul Stoffregen's PJRC store; UK customers can buy it for around £19.80 including VAT from a range of local sources, including SK Pang.