Level 2Unit B · Session 8
8

Unit B · Things that move, things that show

A screen of your own

What we are making: a screen with your own words on it. From today onwards, your machines can tell you things without a laptop attached.

Why this matters more than it looks

Everything you have built so far has talked to you through the Serial Monitor — which means it only talks when a laptop is plugged into it. A machine with a screen is a machine you can unplug, carry to the front of the room, and hand to somebody.

This screen has sixteen characters across and two lines down. That is not many. Deciding what deserves to be on it is a real design decision, and you will make it in every project from here.

New words
LCDLiquid Crystal Display. The kind of screen in a microwave or a calculator.
I2CA way for the board to talk to a module over just two wires.
AddressWhich module you are talking to. Usually 0x27, sometimes 0x3F.
setCursor()Choosing where on the screen the next words will appear.
Arduino UnoUSB to the laptop5VGNDA4A5LCD1602 I2Cthe little board on the backVCCGNDSDASCLSDASCLA4 and A5 are the only two pins that can do this. They are not a choice.
The screen. Four wires, and two of them are power.
Hello, screen
1#include <LiquidCrystal_I2C.h>
2 
3LiquidCrystal_I2C screen(0x27, 16, 2); // address, 16 columns, 2 rows
4 
5void setup() {
6 screen.init();
7 screen.backlight();
8 screen.setCursor(0, 0); // column 0, row 0 - the top line
9 screen.print("Averroes");
10 screen.setCursor(0, 1); // row 1 - the bottom line
11 screen.print("Robotics");
12}
13 
14void loop() {
15 // nothing here. The screen keeps showing what setup() put there.
16}

Do it

  1. Wire it up. SDA to A4 and SCL to A5 — those two are not negotiable.
  2. Install the LiquidCrystal_I2C library, if your teacher has not already.
  3. Upload. You should see two lines of text.
  4. If you see a lit screen with no words, turn the little blue screw on the back with a screwdriver until the letters appear. That is the contrast.

Change it

  1. Put your own name on the top line.
  2. Count the letters. What happens if you print more than sixteen?
  3. Move something to column 5 instead of column 0 with setCursor(5, 0).
💡 Tip
If nothing appears, the address is the first thing to suspect. Most of these modules are 0x27, but a good number are 0x3F. Change the one number and upload again — it costs ten seconds and it is the answer about half the time.
What you seeWhyWhat to do
Backlight on, no textContrast is turned right down.Turn the little blue screw on the back until letters appear.
Nothing at all, not even lightNo power reaching the module.Check VCC and GND before suspecting anything cleverer.
Blocks of solid squaresThe I2C address is wrong.Change 0x27 to 0x3F and upload again.
Text appears then vanishesIt is being redrawn constantly.You are printing inside loop() with no delay. Move it to setup().

What you learned

  • Two wires — SDA and SCL — can carry a whole conversation.
  • A screen is what makes a machine independent of a laptop.
  • Sixteen characters is a constraint, and constraints are a design problem.
Challenge optional — only if you finish early
  • Make the screen scroll a message longer than sixteen characters.
7. An angle you can command