Lab 6: Connect and use an LCD

In this project you are going to connect an LCD to your board and write a short message on it.

What you need

  • One Raspberry Pi connected to Wyliodrin STUDIO;
  • One 16×2 LCD;
  • One breadboard;
  • Jumper wires;

The Setup

The LCD in the kit is connected to a port expander (MCP23008). This allows the LCD to be controlled via the I2C protocol, thus reducing the number of pins you need to connect the LCD to. In this case, you just need to connect the expander to GND, 5V, SCL and SDA pins, according to the indicators on the expander. You can find the appropriate pins in the Pin Layout tab. You just need to connect the SDA port on the port expander with the SDA pin on the board and so on.

The Code

You go to the Wyliodrin Applications page and create a new application. You name it and select Streams as programming language. Once created, you click on the new application's name to open it.

First of all, you need to initialise the LCD. For this, you drag the run node and select Fire once at start so you make sure that once you run the application a first message is sent. This is only required to trigger the init LCD node, so you can assure there is no other message being sent again. For this, drag the trigger node and double click on it.

You need to set this node to wait until reset. This will make the node to send the first message and then wait until it receives a message containing the property reset, which will never happen. Next, the init LCD node initializes the LCD.

First of all, you need to require the wyliodrin module, which exposes some simple functions in order to control the LCD. Otherwise you would need to implement the protocol in order to control it.

Once you have the wyliodrin variable, call the LiquidCrystal constructor in order to obtain a LiquidCrystal object. The constructer receives 0 as parameter.

Why is the value 0 the parameter of the contructor? This type of LCD communicates with the Raspberry Pi board via that I2C protocol. Taking into account how the I2C protocol behaves, you would need to mention the bus specific to the LCD, that usually is 32. However, in order to be able to connect multiple LCDs at once, they have three jumpers which can be connected in order to represent values from 0 to 7, thus being able to identify eight different LCDs. This is the value you need to pass to the constructor, in this case, no jumper is connected so we passed the value 0.

What is new at the code presented above is the structure. You need to use this because you want the lcd variable to be available from other nodes also (Display on LCD node) and is a variable accessible to all the nodes, so you just set the lcd property and you will be able to use it from any other node.

The display LCD node is another function node which first clears the LCD, then prints a string on it. Notice that the global lcd variable is used.


  1. Use a temperature sensor and display the temperature on the LCD.
iot/labs/06.txt ยท Last modified: 2017/09/11 09:39 by alexandru.radovici
CC Attribution-Share Alike 3.0 Unported Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0