Posted on Leave a comment

RaspberryPi – 16×02 LCD Display in Python

If you want details from the source, the library we are using here is fully documented at https://rplcd.readthedocs.io/en/stable/

The Bare Minimum to get a message on Screen

Wire the Components

The Wiring for the Python version of code is the same as the NodeRED version. Follow the wiring section on that post and return here for the code.

Get The Library

$ sudo pip install RPLCD

Coding Python

The beauty of coding for hardware like an LCD on the Raspberry Pi is that the code is already present where it will be executing. There is no need to compile and upload for a Python Script.

If you prefer to code on your desktop it as simple as copying the resulting Python file to your Raspberry Pi.

For this activity we will be coding in the bash shell via an ssh connection.

ssh pi@192.168.13.14
nano pi_lcd.py

Define the pins that will be used

We will use simple variables to define each of the pins connecting the LCD to the Pi. They could be more abbreviated but to help with clarity we will use longer names.

ENABLE = 31
REGISTER_SELECT = 29
DATA_PIN_D7 = 26
DATA_PIN_D6 = 24
DATA_PIN_D5 = 21
DATA_PIN_D4 = 19

Let’s create any LCD Object using the VAriables we setup above. The RPLCD library does all the hard work all we need to do is import the library and then create an “instance”.

First import the Library

from RPLCD.gpio import CharLCD

Now using the variables we set up earlier we will create the LCD object. The CharLCD class uses keyword args for input. So each argument is a keyword and the value being assigned.

my_lcd = CharLCD(cols=16, rows=2, pin_rs=REGISTER_SELECT, pin_e=ENABLE, pins_data=[DATA_PIN_D7,DATA_PIN_D6,DATA_PIN_D5,DATA_PIN_D4]

That’s all we need, add a line with what text you want to display and you are good to go.

my_lcd.write(u'Message of Hope')

Posted on Leave a comment

RaspberryPi – 16×02 LCD Display on NodeRED

Materials

  • Raspberry Pi 3
  • 16×2 LCD
  • Breadboard
  • Hookup Wire
  • Trimmer / Potentiometer

Use the Pallete manager to install node-red-contrib-lcd

https://flows.nodered.org/node/node-red-contrib-lcd

Flows

Add the LCD Node to your flow.

The LCD node requires a string indiacting whcih pins of the LCD are connected to which pins of the pi. The format is shown when you double click the node to configure it.

The “Pins, Type” field will give you the format \: RS, EN, D7, D6, D5, D4, ROW, COL

The pin numbering using Board numbering is 6,5,10,9,8,7,2,16

Add the pin numbering and click done.

Board Numbering: 6,5,10,9,8,7,2,16

GPIO Numbering : 31,29, 26,24,21,19, 2,16

Board numbering is simply sequential with even numbers from 2 on the outer row and odd numbers from 1 on the inner row.

Add an inject node:

Connect the inject node to the LCD node.

Double click the inject node and add a string to,

That’s all there is on the NodeRED end, you can deploy now or wait until after wiring.

If you don’t want to wire up the Flow you can just copy in this:

Wiring

The Full Fritzing Diagram is on TeachersPayTeachers.com

Let’s wire up our Pi and LCD as follows. Some color coding can help but the colors are not important.

Connect a Wire from “PIN 2” on the RaspberryPI to the Lower rail ( Red ) on your breadboard. This is +5volts and will be used to power the LCD and the LCD Backlight

Connect a second wire from PIN 6 to the Blue Rail on the Breadboard, this will provide the GRound or NEG for the LCD.

Connect the DATA Lines

We can connect the four Data lines from the LCD to any GPIO Pins on the RaspberryPi. In this example, GPIO 7,8,9,10 were selected for visual location and consecutive numbering. As shown we will be using Blue and White wires for the DATA lines but any color can be used.

Connect GPIO10 to the Breadboard directly below the LCD Pin As Shown. It will be the third pin from the left and likely labelled D8, Pin 14 or sometimes DB7.

Connect GPIO 9 to D7 ( DB6 )

Connect GPIO 8 to D6 ( DB5 )

Connect GPIO 7 to D6 ( DB5 )

Connect the Control Lines

There are only two lines that will be used to control the LCD. Enable and Command Mode. The enable line is basically the on/off switch for the LCD connected to the PI and the Command Mode or “Register Select” informs the LCD if it will be receiving a command to act upon or letters to display.

Connect GPIO5 to the Breadboard colum directly beneath the E pin on the LCD.

Connect GPIO6 to the Breadboard colum directly beneath the RS Pin on the LCD

Wire the Contrast Knob

Trimmer/PotentiometerPotentiometer ) to the LCD VO ( Contrast ). Make sure you coonect the “Wiper” the cneter in this case to the column directly beneath the VO

Connect the Dimmer s( Trimmer/Potentiometer ) legs CW and CCW to +5v and Ground, the polarity of these two determine whether the contrast is increased with a Clockwise turn or a Counter-Clockwise turn.

Deploy the Node and Try a Message

Posted on Leave a comment

Raspberry Pi – NodeRED Button

This simple experiment will demonstrate using a push button to light a LED.

Adding a Push-Button to an LED in Raspberry Pi doesn’t get much easier than with NodeRED, two nodes, and you are done.

The Fritzing Diagram is availble for download

Wire the LED and Button as shown in the Diagram

  • Pin 1 – Left side of button
  • Pin 11 – Right side of button
  • Pin 6 – Led Cathode ( Short Wire / Flat Side )
  • Pin 7 – Led Anode ( Long Wire )

If you simply want to try this Flow, you can import this:

[{"id":"60410dd4.757164","type":"rpi-gpio out","z":"308cfa1.ad68d06","name":"","pin":"7","set":true,"level":"0","freq":"","out":"out","x":253.4615135192871,"y":348.46156311035156,"wires":[]}]

To run this experiment we will use only two nodes rpi-gpio In and rpi-gpio out. Drag one of each onto the Flow edit pane.

When you drop the Nodes the Labeling is updated to reflect the configuration. The two Nodes before wiring will look like this. There has been nothing done to them other than dropping them onto the flow.

Wire the Nodes together

Configure the Input Node

  1. Double Click the rpi-gio In ( it is marked PIN:tri ).
  2. Set the Pin to 11
  3. set the resistor to pull-down
  4. Click Done

The node Should change to PIN 11

Configure the Output Node

  1. Double Click the rpi-gio out ( it is marked PIN: ).
  2. Set the Pin to 7
  3. Check “Initial pin state?”
  4. Select “initial level of pin -low(0)
  5. Click Done

The Output Node should now be labelled PIN: 7

Deploy the Flow

If you have done everything correctly you should now be able to press the button and the LED will light.