Displaying text on a 16x2 LCD screen with a Raspberry Pi

Wiring the screen

To wire the display up, you'll need at least 9 gpio cables, but more than likely 13 for the full 8 bit mode operation. You'll also have to check the Raspberry Pi pinout numbers for the Pi4J library to see where to wire the screen up to, but essentially you can connect it to any gpio headers as long as they're not set up to be used with something else. Some peoples blog posts mention using the serial port gpio headers, but since my project already made use of those to control an SSC32 servo controller, I had to use other ports and it didn't seem to cause any issues.

As per the scren side of things, you'll need to read up on the screens Winstar techsheet or this other version for that, but essentially the pinout is as follows:

1: Ground
2: +5V
3: Not connected
4: RS
5: R/W
6: Strobe/Enable
7: Data1
8: Data2
9: Data3
10: Data4
11: Data5
12: Data6
13: Data7
14: Data8
15: Not connected
16: Not connected

Should end up something like this:

16x2 LCD screen wiring to Raspberry Pi

So I've used the following setup, note GPIO numbers refer the the Pi4J pin numbers, not the actual Raspberry Pi pin numbers, see the WiringPi documentation for reference:

Ground   = VSS
Ground   = RW
+5V       = VDD
GPIO_08 = Strobe/Enable
GPIO_09 = RS
GPIO_29 = Data1
GPIO_28 = Data2
GPIO_27 = Data3
GPIO_26 = Data4
GPIO_25 = Data5
GPIO_24 = Data6
GPIO_23 = Data7
GPIO_22 = Data8

By sending RW to ground, we ensure that the screen/display is always set to read only mode and thus making sure that it does not attempt to send data to the Pi using a 5v data connection over the Pi's 3.3v IO pins and potentially cause damage.

Setting up the software

To use Pi4J you call install it into your project just by importing the jar files, but you'll also need WiringPi which for older versions of Pi4J, comes as part of the jar package but with more recent versions such as the most recent snapshot build, it has to be installed separately onto the Pi itself. The people behind the Pi4J project decided this was the best option because you'll be able to take advantage of newer WiringPi builds without having to upgrade the Pi4J libraries.

The main reason why you'd use the the snapshot version over the standard release build is because the latest release build doesn't have built in support for the BMC2835 chip as per this issue that's been posted on GitHub, it's an issue with the Raspberry Pi 3, model B, you'll get a message such as this:

Unable to determine hardware version. I see: Hardware : BCM2835
expecting BCM2708 or BCM2709.
If this is a genuine Raspberry Pi then please report this
to projects@drogon.net. If this is not a Raspberry Pi then you
are on your own as wiringPi is designed to support the
Raspberry Pi ONLY

You must have WiringPi installed on your system as per the Pi4J release notes. You can install WiringPi using GIT or download and compile yourself. According to the WiringPi website you can install GIT using a simple 'apt-get install git-core' command but that probaby isn't going to work since it'll more than likely not find it. So if it's not available you'll have to download it from the website. That's Plan B on the download page where it explains you need to download the latest snapshot from here: https://git.drogon.net/?p=wiringPi;a=summary 

The following instructions are from the WiringPi website, but I've duplicated here for redundancy and ease of use.

'This will download a tar.gz file with a name like wiringPi-98bcb20.tar.gz. Note that the numbers and letters after wiringPi (98bcb20 in this case) will probably be different – they’re a unique identifier for each release.

You then need to do this to install:'

$ cd
$ tar xfz wiringPi-98bcb20.tar.gz
$ cd wiringPi-98bcb20
$ ./build

Once that's done you can test the installation using these commands:

$ gpio -v
$ gpio readall

Now you can get back to focusing on using Pi4J and the benefits that the latest snapshot build has to offer.

The Java code

And for some example code, you should be able to use this class in your Java project as is and reference it straight away wothout any change as long a syou wire the screen up the same, if not, you'll have to make sure you update the GPIO numbers within the constructor.

package Utils;

import System.Aimie;
import com.pi4j.component.lcd.impl.GpioLcdDisplay;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.RaspiPin;

public class Display {
    public final static int LCD_ROW_1 = 0;
    public final static int LCD_ROW_2 = 1;
    public final GpioLcdDisplay lcd;
    private final GpioController gpio;

    public Display() {
        // create gpio controller
        gpio = GpioFactory.getInstance();

        lcd = new GpioLcdDisplay(
                2,                  // number of row supported by LCD
                16,                 // number of columns supported by LCD
                RaspiPin.GPIO_09,  // LCD RS pin
                RaspiPin.GPIO_08,  // LCD strobe pin
                RaspiPin.GPIO_29,  // LCD data bit D0
                RaspiPin.GPIO_28,  // LCD data bit D1
                RaspiPin.GPIO_27,  // LCD data bit D2
                RaspiPin.GPIO_26,  // LCD data bit D3
                RaspiPin.GPIO_25,  // LCD data bit D4
                RaspiPin.GPIO_24,  // LCD data bit D5
                RaspiPin.GPIO_23,  // LCD data bit D6
                RaspiPin.GPIO_22); // LCD data bit D7
    }
    
    public void shutdown()
    {
        lcd.clear();
        lcd.setCursorHome();
        gpio.shutdown();
        Aimie.display = null;
    }
    
    public void write(String value)
    {
        clear();
        lcd.write(LCD_ROW_1, value);
    }
    
    public void write(int lineNumber, String value)
    {
        clear();
        lcd.write(lineNumber, value);
    }
    
    public void writeln(String value)
    {
        clear();
        lcd.writeln(LCD_ROW_1, value);
    }
    
    public void writeln(int lineNumber, String value)
    {
        clearln(lineNumber);
        lcd.writeln(lineNumber, value);
    }
    
    public void clear()
    {
        lcd.clear();
    }
    
    public void clearln(int lineNumber)
    {
        lcd.clear(lineNumber);
    }
}

As you can see the code is pretty simple.

Potential issues

You might find that your screen displays random text/characters/gibberish as per the image below, I didn't find a software fix for this, because although I had the four data cables connected for 4 bit opperation, it was seemingly still trying to run in 8 bit mode, so my fix for this was to just connect the other 4 cables. I mean, it's not like the Pi doesn't have enough IO ports. 

16x2 LCD Screen random/gibberish text

Once you've connected all 8 data cables, you might have to completely shut down the Pi and turn off power to both the screen and the Pi, then turn it on again, or it might continue to display rubbish on screen.


Published at

Tags: Java,Robot,Raspberry Pi,Pi4J

Luke Alderton

Comments

Ocepa89
https://frases-status-amor.tumblr.com https://blarsonx.tumblr.com https://rainhaursa.tumblr.com https://babyggirl98.tumblr.com https://avecesfrancisca.tumblr.com https://alexandra-brl.tumblr.com https://cayden420.tumblr.com https://2310-3110.tumblr.com https://lydiafama.tumblr.com https://7h01.tumblr.com
01/12/2018
Ozana21
http://shamrockballerz.ning.com/profiles/blogs/comprar-nimodipine-30-mg-sin-receta-con-seguridad-nimodipine-30 http://augasthya-plus.ning.com/profiles/blogs/site-seguro-para-comprar-gen-rico-zyad-mais-barato-brasil http://thehiphophub.ning.com/profiles/blogs/purchase-cheap-diserec-25mg-branded-diserec-for-cheap http://thecorner.ning.com/profiles/blogs/virainhi-comprar-en-farmacia-online-comprar-virainhi-200-soft http://neikasworld.ning.com/profiles/blogs/buy-methocarbamol-online-methocarbamol-tablet-buy-uk http://borrowmyburrito.ning.com/profiles/blogs/buy-nateglinide-safely-where-to-buy-starlix-guaranteed-delivery http://whazzup-u.com/profiles/blogs/o-acheter-juvena-sildenafil-citrate-200-mg-en-ligne-juvena-en http://amusecandy.com/blogs/post/438420 http://whazzup-u.com/profiles/blogs/order-dynafil-200-mg-online-where-to-buy-sildenafil-citrate http://webclub.allpix.net.ee/groupware/blogs/post/29588 http://neikasworld.ning.com/profiles/blogs/comprar-gen-rico-do-tantrix-sildenafil-citrate-200mg-pre-o http://153.126.169.73/GaijinConcierge/index.php?qa=20996&qa_1=alopurinol-farmacia-confirmación http://staind-italy.ning.com/profiles/blogs/order-placidum-130mg-cheap-placidum-buyer-usa http://jaktlumaczyc.pl/69973/order-alivher-sale-order-sildenafil-citrate-safely-online http://bricolocal.com/profiles/blogs/order-frumil-5mg-safely-can-i-purchase-amiloride-and-furosemide http://flutes.ning.com/profiles/blogs/ceftinex-300-mg-donde-comprar-online http://sallieanncooks.ning.com/profiles/blogs/acheter-vrai-viagra-25mg-acheter-viagra-par-telephone http://tnfdjs.ning.com/profiles/blogs/comprar-sollevare-sildenafil-citrate-gen-rico-com-garantia http://whazzup-u.com/profiles/blogs/comprar-h-for-envio-rapido-pela-internet-brasil http://www.onfeetnation.com/profiles/blogs/tretinoin-05-mg-donde-comprar-sin-receta-fiable-espa-a http://cqa.aaua.edu.ng/index.php?qa=21615&qa_1=vioses-order-without-prescription-where-authentic-vioses
06/12/2018
Agobi81
http://network-marketing.ning.com/profiles/blogs/comprar-ciavor-diario-gen-rico-de-forma-segura-online-rep-blica http://writeskills.ning.com/profiles/blogs/forcigra-order-without-prescription-forcigra-buying-mexico https://www.olliesmusic.com/blog/22172/dapoxetine-oР“в„–-acheter-bon-marche-acheter-dapoxetine-en-pharmacie-forum/ http://ssbsavannah.ning.com/profiles/blogs/site-seguro-para-comprar-tada-diario-tadalafil-10mg-gen-rico http://whazzup-u.com/profiles/blogs/farmacia-online-donde-comprar-acarbosa-urgente-espa-a http://crosstv.ning.com/profiles/blogs/farmacia-online-donde-comprar-tadafil-tadalafil-urgente-costa http://lydlabs.ning.com/profiles/blogs/celecoxib-100mg-achat-celebrex-pas-cher-paiement-bitcoin http://whozwholive.ning.com/profiles/blogs/order-erotadil-20mg-low-price-where-can-i-purchase-tadalafil-no http://korsika.ning.com/profiles/blogs/vigoril-sildenafil-citrate-200mg-livraison-gratuit-pas-cher http://dctechnology.ning.com/profiles/blogs/ampicilline-250mg-en-ligne-bas-prix-commander-acheter-du http://sn.ras.ru/index.php/blogs/1108/51428/farmacia-en-linea-donde-comprar http://fotoathena.ning.com/profiles/blogs/discount-smadol-200mg-order-online-can-i-order-ibuprofen-quick http://destinosexotico.com/blogs/post/31171 http://newsmediaimages.ning.com/profiles/blogs/site-fiable-pour-acheter-defil-sildenafil-citrate-acheter https://bemysoul.com/blogs/post/13194 http://facebookhitlist.com/profiles/blogs/como-comprar-adapaleno-differin-15-mg-gen-rico-com-frete-gr-tis http://tnfdjs.ning.com/profiles/blogs/donde-para-ordenar-dali-40mg-sin-receta-online-estados-unidos http://property.ning.com/profiles/blogs/acheter-du-vrai-cialis-tadalafil-10mg-moins-cher-livraison-72h http://bobford.ning.com/profiles/blogs/cialis-20mg-comprar-sem-prescri-o-na-internet-brasil http://question.hamrahmorabi.ir/index.php?qa=175779&qa_1=generique-sildenafil-citrate-acheter-sildenafil-ordonnance http://professoratciutatvella.ning.com/profiles/blogs/farmacia-en-linea-donde-comprar-imipramina-75-mg-sin-receta-de http://sallieanncooks.ning.com/profiles/blogs/farmacia-online-donde-comprar-contalax-5mg-sin-receta-fiable http://smssaff.sagada.org/profiles/blogs/achat-securise-sildamax-sildenafil-citrate-200mg-acheter http://higgs-tours.ning.com/profiles/blogs/farmacia-online-donde-comprar-generico-tagil-10mg-de-confianza http://football.ning.com/profiles/blogs/como-fa-o-pra-comprar-sildara-gen-rico-de-forma-segura
07/12/2018
Acohi32
http://dmoney.ru/39272/generico-sildenafil-citrate-seguridad-plurinacional-bolivia http://shamrockballerz.ning.com/profiles/blogs/sparfloxacin-200mg-order-how-can-i-order-zagam-no-need-rx http://europe-ecologie-aube.ning.com/profiles/blogs/dali-60-mg-como-comprar-sin-receta-con-garantia-argentina http://borrowmyburrito.ning.com/profiles/blogs/griseofulvin-order-without-prescription-how-can-i-buy-grifulvin http://summerschooldns.ning.com/profiles/blogs/ibuprofene-bon-prix-securise-site-de-vente-de-ibuprofene-fiable http://neikasworld.ning.com/profiles/blogs/comprar-ropinirol-1mg-por-internet-dominicana http://sallieanncooks.ning.com/profiles/blogs/buy-extadil-10mg-on-sale-can-i-purchase-tadalafil-no-prescription http://dmoney.ru/39314/où-acheter-en-ligne-silderec-baisse-prix-silderec-pas-chere http://viatorfroshreligion.ning.com/profiles/blogs/acheter-du-vrai-en-ligne-depakote-moins-cher-rapide-forum http://whozwholive.ning.com/profiles/blogs/puis-je-acheter-du-dapoxetine-priligy-generique-au-canada http://fotoathena.ning.com/profiles/blogs/comprar-virineo-150mg-gen-rico-via-internet-brasil http://kasabovart.ning.com/profiles/blogs/order-meclizine-hydrochloride-25-mg-cheap-meclizine-hydrochloride http://www.godry.co.uk/profiles/blogs/discount-ciavor-40mg-buy-online-online-ciavor-bitcoin-canada http://whazzup-u.com/profiles/blogs/amoxicilina-250-mg-comprar-barato-pela-internet-comprar-amoxil http://cdloga78.ning.com/profiles/blogs/buy-olvion-olvion-discounts-2018-australia http://cdloga78.ning.com/profiles/blogs/o-acheter-betapace-sotalol-en-ligne-baisse-prix-sans-ordonnance http://dmoney.ru/38508/farmacia-online-comprar-generico-comprar-generico-internet http://summerschooldns.ning.com/profiles/blogs/zyad-tadalafil-20-mg-generique-achat-livraison-express-comment http://bricolocal.com/profiles/blogs/site-seguro-para-comprar-gen-rico-adcirca-tadalafil-com-desconto http://www.collabzo.com/pwrportal/blogs/57/12018/inventum-sildenafil-citrate-en-l http://staind-italy.ning.com/profiles/blogs/comprar-vimax-en-farmacia-online-us-comprar-sildenafil-citrate http://destinosexotico.com/blogs/post/41887 http://www.facecool.com/profiles/blogs/buy-generic-enafilzil-200mg-online-how-to-buy-sildenafil-citrate http://borrowmyburrito.ning.com/profiles/blogs/farmacia-online-donde-comprar-sildora-sin-receta-buen-precio-espa http://borrowmyburrito.ning.com/profiles/blogs/neogra-130-mg-como-puedo-comprar-con-garantia-chile-precio-neogra http://howidoit.ning.com/profiles/blogs/enthusia-120-mg-como-comprar-sin-receta-de-forma-segura-espa-a
08/12/2018
Otutu90
http://facebookhitlist.com/profiles/blogs/farmacia-online-donde-comprar-silnor-sildenafil-citrate-sin http://www.sobgamers.com/gamer/blogs/post/94009 http://korsika.ning.com/profiles/blogs/farmacia-online-donde-comprar-katora-130mg-entrega-r-pida-bolivia http://sallieanncooks.ning.com/profiles/blogs/buy-viripotens-150mg-no-rx-cheapest-viripotens-tablets http://lorealprofessionnelbest.ning.com/profiles/blogs/order-erecta-erecta-brand-buy http://fotoathena.ning.com/profiles/blogs/comprar-generico-amoxapina-50mg-sin-receta-con-garantia-chile http://viatorfroshreligion.ning.com/profiles/blogs/addos-30mg-en-ligne-baisse-prix-acheter-avec-visa-acheter http://digitalguerillas.ning.com/profiles/blogs/comprar-dali-tadalafil-10-mg-gen-rico-com-desconto-online-rep http://www.godry.co.uk/profiles/blogs/adcirca-tadalafil-40mg-comprar-barato-online-rep-blica-federativa http://newyorkundergroundradio.ning.com/profiles/blogs/farmacia-online-donde-comprar-tadasure-tadalafil-con-garantia http://howidoit.ning.com/profiles/blogs/onde-posso-comprar-tada-diario-de-forma-segura-on-line-brasil http://crosstv.ning.com/profiles/blogs/trouver-du-erecsil-sildenafil-citrate-100-mg-tarif-du-erecsil-20 https://www.mysocialpeople.com/blogs/2139/11944/onde-comprar-escitan-130-mg-generico-envio-urgente-republica-fe
09/12/2018
Apabu19
http://summerschooldns.ning.com/profiles/blogs/o-commander-du-silagress-150-mg-acheter-sildenafil-citrate http://kasabovart.ning.com/profiles/blogs/panagra-sildenafil-citrate-en-ligne-baisse-prix-achat-acheter http://jawbite.ning.com/profiles/blogs/onde-comprar-budesonide-rhinocort-0-1-mg-gen-rico-entrega-r-pida http://weebattledotcom.ning.com/profiles/blogs/inderal-la-donde-comprar-con-seguridad-usa-propranolol-cual http://adrenalineprovinggrounds.ning.com/profiles/blogs/site-seguro-para-comprar-ciavor-diario-tadalafil-gen-rico-rep http://wu-world.com/profiles/blogs/latanoprost-comprar-en-farmacia-en-linea-todo-en-medicinas http://fotoathena.ning.com/profiles/blogs/speeden-200mg-achat-achat-speeden-pharmacie-suisse http://cdloga78.ning.com/profiles/blogs/dynamico-130mg-comprar-sin-receta-con-visa-espa-a-comprar http://laugarnecaravans.ning.com/profiles/blogs/order-ambigra-cheap-buy-ambigra-internet-online-legally http://www.libertyxchange.com/blogs/post/83274 http://recampus.ning.com/profiles/blogs/buy-alfin-100mg-cheap-alfin-cost-in-canada http://ggwadvice.com//index.php?qa=54208&qa_1=buy-tacrolimus-5mg-no-rx-where-to-order-prograf-safely-online http://vocal-buzz.ning.com/profiles/blogs/verdafil-sildenafil-citrate-150-mg-moins-cher-sur-internet http://millionairex3.ning.com/profiles/blogs/citalopram-buy-online-cheap-citalopram-order-online-singapore http://thecorner.ning.com/profiles/blogs/site-seguro-para-comprar-finasteride-finpecia-1mg-de-forma-segura http://techwarriorteam.ning.com/profiles/blogs/buy-vigorex-200mg-online-buy-canadian-vigorex-online http://wu-world.com/profiles/blogs/comprar-virineo-130mg-gen-rico-barato-pela-internet-brasil http://divasunlimited.ning.com/profiles/blogs/commander-rabeprazole-20-mg-bon-prix-acheter-rabeprazole-20 http://writeskills.ning.com/profiles/blogs/discount-zithromax-250mg-order-online-buy-zithromax-pills-com http://whazzup-u.com/profiles/blogs/sildehexal-25-mg-como-comprar-sin-receta-de-calidad-espa-a http://europe-ecologie-aube.ning.com/profiles/blogs/commander-du-virnagza-fort-tadalafil-virnagza-fort-prix-de-vente http://bygda.traktor.no/profiles/blogs/cheap-juan-130mg-order-online-buy-juan-brisbane http://crossroadshob.ning.com/profiles/blogs/quetiapine-300mg-comprar-en-una-farmacia-en-linea-confirmaci-n-r http://tnfdjs.ning.com/profiles/blogs/comprar-zyad-10-mg-gen-rico-entrega-r-pida-pela-net-rep-blica http://jaktlumaczyc.pl/70329/buy-androz-where-can-order-sildenafil-citrate-safely-online http://www.facecool.com/profiles/blogs/seler-sildenafil-citrate-100mg-comprar-fiable-chile-comprar-seler
13/12/2018
Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By Ecake68 on MVC forms in Umbraco
16 Dec 2018, 16:11 PM
By Wowob43 on Restrict Umbraco Back Office by IP
16 Dec 2018, 10:21 AM
By Rosax69 on How does DNS work? For dummies!
15 Dec 2018, 16:44 PM
By Aroli61 on Using SQL DataTables to speed up database performance
15 Dec 2018, 09:02 AM
By Xasus39 on MVC forms in Umbraco
14 Dec 2018, 20:04 PM
By Shane on Xamarin Forms multiple instances of same app open
14 Dec 2018, 05:33 AM
By Apabu19 on Displaying text on a 16x2 LCD screen with a Raspberry Pi
13 Dec 2018, 18:26 PM
By Anuri66 on Using SQL DataTables to speed up database performance
13 Dec 2018, 13:52 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development