c programming lcd raspberry pi raspberry pi c lcd raspberry pi lcd c tutorial raspberry pi wiring pi Technology wiringpi wiringpi lcd

How to Setup an LCD on the Raspberry Pi and Program it With C

Raspberry Pi LCD 8 Bit Mode Connection Diagram

Connecting an LCD show to your Raspberry Pi is certain to take your venture up a notch. They’re nice for displaying sensor readings, songs or web radio stations, and stuff from the net like tweets and inventory quotes. No matter you select to show, LCDs are a easy and cheap means to do it.

On this tutorial, I’ll present you two alternative ways to join an LCD to the Raspberry Pi with the GPIO pins. The primary means I’ll present you is in eight bit mode, which makes use of 10 GPIO pins. Then I’ll present you ways to join it in four bit mode, and that makes use of solely 6 pins. After we get the LCD attached I’ll present you ways to program it with C, utilizing Gordon Henderson’s WiringPi LCD library.

I’ll present you ways to print textual content to the show, clear the display, place the textual content, and management the cursor. You’ll additionally see how to scroll textual content, create customized characters, print knowledge from a sensor, and print the date, time and IP tackle of your Pi.

BONUS: I made a fast begin information for this tutorial which you could obtain and return to later in case you can’t set this up proper now. It covers all of the steps, diagrams, and code you want to get began.

I’ll be utilizing a 16X2 LCD show right here, however the examples under will work with any LCD that makes use of the Hitachi HD44780 driver.

In case your undertaking makes use of Python, we now have one other article that may present you ways to program the LCD in Python.

There’s one other method to join your LCD that makes use of solely two wires, referred to as I2C. To see how to do this, take a look at our tutorial How to Set Up an I2C LCD on the Raspberry Pi.

Right here’s a video you’ll be able to look ahead to a fast demonstration of the arrange and instance packages:

Connecting the LCD

Most individuals in all probability need to join their LCD in four bit mode since it makes use of much less wires. However in case you’re , I’ll present you ways to join it in eight bit mode as nicely.

Wiring the LCD in eight Bit Mode

In eight bit mode, every command or character is shipped to the LCD as a single byte (eight bits) of knowledge. The byte travels in parallel over eight knowledge wires, with every bit travelling via it’s personal wire. eight bit mode has twice the bandwidth as four bit mode, which in principle interprets to greater knowledge switch velocity. The primary draw back to eight bit mode is that it makes use of up lots of GPIO pins.

Connecting the LCD in eight bit mode requires 10 GPIO pins:

Raspberry Pi LCD 8 Bit Mode Connection Diagram

The brightness and distinction potentiometers are 10Okay Ohm, however you may as well use 1K to 3K Ohm resistors right here.

Wiring the LCD in four Bit Mode

In four bit mode, every byte of knowledge is shipped to the LCD in two units of four bits, one after the different, in what are referred to as the higher bits and decrease bits. Though eight bit mode transfers knowledge about twice as quick as four bit mode, it takes an extended time for the LCD driver to course of every byte than it takes to transmit the byte. So in actuality, there isn’t actually a noticeable distinction in velocity between four bit mode and eight bit mode.

four bit mode takes up solely 6 GPIO pins for enter/output, which makes it a well-liked selection for a lot of tasks:

Raspberry Pi LCD 4 bit modeRaspberry Pi LCD 4 bit mode

The brightness and distinction potentiometers are 10Okay Ohm, however 1K to 3K Ohm resistors will work as properly.

Programming the LCD With C

For those who’ve by no means labored with C packages on the Raspberry Pi, it’s your decision to learn our article How to Write and Run a C Program on the Raspberry Pi first. It will clarify how to write, compile, and run C packages.

Set up WiringPi

WiringPi is a C module that makes it straightforward to program the LCD. When you have already got WiringPi put in on your Pi, you’ll be able to skip this part. If not, comply with the steps under to set up it:

1. We will obtain WiringPi utilizing Git. Your Pi might have Git already put in (in that case skip this step), but when not, enter this at the command immediate:

sudo apt-get set up git-core

  • Word: When you get an error putting in Git, run sudo apt-get replace and attempt it once more.

2. Now obtain WiringPi by getting into this at the command immediate:

git clone git://git.drogon.internet/wiringPi

three. Enter this to change directories:

cd wiringPi

four. Run the set up script with:

./construct

5. Check the set up by getting into:

gpio -v

adopted by:

gpio readall

Now we’re prepared to begin programming the LCD!

Examples

All of the examples under are stand-alone C packages, which can want to be complied by getting into this at the command immediate:

gcc -o instance instance.c -lwiringPi -lwiringPiDev

Change instance and instance.c to the file identify you need to use.

After the program is compiled, it might be executed by getting into this at the command immediate:

WiringPi has it’s personal pin numbering system that’s totally different from the Broadcom (BCM) and RPi bodily (BOARD) pin numbering techniques. All of the packages under use the WiringPi pin numbers.

Write to the LCD in eight Bit Mode

This program exhibits the minimal code wanted to initialize the LCD and print “Hello, world!” to it:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D0 29 //Knowledge pin D0
#outline LCD_D1 28 //Knowledge pin D1
#outline LCD_D2 27 //Knowledge pin D2
#outline LCD_D3 26 //Knowledge pin D3
#outline LCD_D4 23 //Knowledge pin D4
#outline LCD_D5 22 //Knowledge pin D5
#outline LCD_D6 21 //Knowledge pin D6
#outline LCD_D7 14 //Knowledge pin D7

int most important()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, eight, LCD_RS, LCD_E, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

lcdPuts(liquid crystal display, “Hello, world!”);

To make use of totally different pins to join the LCD, change the pin numbers outlined in strains 5 to 14. You’ll want to convert the WiringPi pin numbers to the bodily pin numbers of the Raspberry Pi. See right here for a diagram you should use to convert between the totally different numbering methods.

The perform in line 20 is used to initialize the LCD:

liquid crystal display = lcdInit (ROWS, COLUMNS, BIT MODE, LCD_RS, LCD_E, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

The perform lcdPuts(liquid crystal display, “Hello, world!”) prints “Hello, world!” to the display.

Write to the LCD in four Bit Mode

To make use of the LCD in four bit mode, we’d like to set the bit mode quantity to four in the initialization perform (line 20 under). The next code prints “Hello, world!” to the display in four bit mode:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int important()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

lcdPuts(liquid crystal display, “Hello, world!”);

Place the Textual content

By default, textual content is printed to the display at the prime row, second column. To vary the place, use lcdPosition(liquid crystal display, COLUMN, ROW). On a 16×2 LCD, the rows are numbered from Zero to 1, and the columns are numbered from Zero to 15.

The next code prints “Hello, world!” to the backside row, fourth column:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int primary()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

lcdPosition(liquid crystal display, three, 1);
lcdPuts(liquid crystal display, “Hello, world!”);

Clear the Display

The perform lcdClear(liquid crystal display) clears the display and units the cursor place at the prime row, first column. This program prints “This is how you” for 2 seconds, clears the display, then prints “clear the screen” for an additional two seconds:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int principal()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

lcdPuts(liquid crystal display, “This is how you”);
sleep(2);
lcdClear(liquid crystal display);

lcdPuts(liquid crystal display, “clear the screen”);
sleep(2);
lcdClear(liquid crystal display);

Discover how the first string is printed to the prime row, second column (the default place). Then after clearing the display, the second string is printed to the prime row, first column.

Blinking Textual content

Utilizing some time loop with lcdclear() and lcdputs() creates a blinking textual content impact:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int fundamental()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

whereas(1)
lcdPosition(liquid crystal display, Zero, Zero);
lcdPuts(liquid crystal display, “Hello, world!”);
sleep(2);
lcdClear(liquid crystal display);
sleep(2);

Press Ctrl-C to exit the program.

Flip the Cursor On and Off

The cursor is turned off by default, however you will get totally different types of cursors utilizing the following features:

  • Underline non-blinking cursor: lcdCursor(liquid crystal display, 1)
  • Underline blinking cursor: lcdCursor(liquid crystal display, 1), adopted by lcdCursorBlink(liquid crystal display, 1)
  • Blinking block fashion cursor: lcdCursorBlink(liquid crystal display, 1)
  • Cursor off : lcdCursor(liquid crystal display, Zero)
#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int fundamental()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

//lcdCursor(liquid crystal display, Zero); //Cursor OFF

lcdCursor(liquid crystal display, 1); //Cursor ON, underline, not blinking
//lcdCursorBlink(liquid crystal display, 1); //Cursor ON, block, blinking

//Use each strains under to get a blinking underline/block cursor
//lcdCursor(liquid crystal display, 1);
//lcdCursorBlink(liquid crystal display, 1);

lcdPuts(liquid crystal display, “Hello, world!”);

Print the Date and Time

This program will print the present date and time to the LCD:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>
#embrace <stdio.h>
#embrace <time.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int essential()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

whereas(1)
time_t timer;
char buffer_date[26];
char buffer_time[26];
struct tm* tm_info;

time(&timer);
tm_info = localtime(&timer);

strftime(buffer_date, 26, “Date: %m:%d:%Y”, tm_info);
strftime(buffer_time, 26, “Time: %H:%M:%S”, tm_info);

lcdPosition(liquid crystal display, Zero, Zero);
lcdPuts(liquid crystal display, buffer_date);

lcdPosition(liquid crystal display, Zero, 1);
lcdPuts(liquid crystal display, buffer_time);

Print Your IP Handle

This program prints the IP tackle of your ethernet connection (eth0). To get the IP of your WiFi connection, change eth0 to wlan0 in line 30:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

#embrace <stdio.h>
#embrace <string.h>
#embrace <sys/varieties.h>
#embrace <sys/socket.h>
#embrace <sys/ioctl.h>
#embrace <netinet/in.h>
#embrace <internet/if.h>
#embrace <unistd.h>
#embrace <arpa/inet.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

int most important()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

int n;
struct ifreq ifr;
char iface[] = “eth0”; //Change this to the community of your selection (eth0, wlan0, and so forth.)

n = socket(AF_INET, SOCK_DGRAM, Zero);
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name , iface , IFNAMSIZ – 1);
ioctl(n, SIOCGIFADDR, &ifr);
shut(n);

lcdPosition(liquid crystal display, Zero, Zero);
lcdPrintf(liquid crystal display, “IP Address: “);

lcdPosition(liquid crystal display, Zero, 1);
lcdPrintf(liquid crystal display, (“%s – %sn” , iface , inet_ntoa(( (struct sockaddr_in *)&ifr.ifr_addr )->sin_addr)));
return Zero;

Customized Characters

Every LCD character is a 5×eight array of pixels. You possibly can create any sample you need and show it on the LCD as a customized character. Up to eight customized characters might be saved in the LCD reminiscence at a time. This web site has a pleasant visible means to generate the bit array used to outline customized characters.

Printing a Single Customized Character

To print a single customized character, first outline the character. For an instance of this see strains 12 to 19 under. Then use the perform lcdCharDef(liquid crystal display, 2, omega) to retailer the character in the LCD’s reminiscence. The quantity 2 on this instance is considered one of the eight places in the LCD’s character reminiscence. The eight places are numbered Zero-7. Then, print the character to the show with lcdPutchar(liquid crystal display, 2), the place the quantity 2 is the character saved in reminiscence location 2.

This program prints the Greek letter Omega to the LCD:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

char omega[8] = 0b00000,
0b01110,
0b10001,
0b10001,
0b10001,
0b01010,
0b11011,
0b00000;

void customChar(void);
int liquid crystal display;

int fundamental()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

customChar();

void customChar(void)

lcdCharDef(liquid crystal display, 2, omega);

lcdClear(liquid crystal display);
lcdPutchar(liquid crystal display, 2);
sleep(three);

Printing A number of Customized Characters

Right here’s an instance of utilizing a number of customized characters that prints the Greek letters omega, pi, and mu, plus thermometer and water drop symbols for temperature and humidity:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

char omega[8] = 0b00000,
0b01110,
0b10001,
0b10001,
0b10001,
0b01010,
0b11011,
0b00000;

char pi[8] = 0b00000,
0b00000,
0b11111,
0b01010,
0b01010,
0b01010,
0b10011,
0b00000;

char mu[8] = 0b00000,
0b10010,
0b10010,
0b10010,
0b10010,
0b11101,
0b10000,
0b10000;

char drop[8] = 0b00100,
0b00100,
0b01010,
0b01010,
0b10001,
0b10001,
0b10001,
0b01110;

char temp[8] = 0b00100,
0b01010,
0b01010,
0b01110,
0b01110,
0b11111,
0b11111,
0b01110;

void customChar(void);
int liquid crystal display;

int fundamental()

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

customChar();

void customChar(void)

lcdCharDef(liquid crystal display, 10, omega);
lcdCharDef(liquid crystal display, 11, pi);
lcdCharDef(liquid crystal display, 12, mu);
lcdCharDef(liquid crystal display, 13, drop);
lcdCharDef(liquid crystal display, 14, temp);

lcdClear(liquid crystal display);

lcdPutchar(liquid crystal display, 10);
lcdPutchar(liquid crystal display, 11);
lcdPutchar(liquid crystal display, 12);
lcdPutchar(liquid crystal display, 13);
lcdPutchar(liquid crystal display, 14);

sleep(three);

Scrolling Textual content

Scroll Proper to Left

This program will scroll textual content onto the show from proper to left, then pause, clear the display, and loop again to the starting:

#embrace <stdio.h>
#embrace <wiringPi.h>
#embrace <liquid crystal display.h>
#embrace <string.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

void scrollText(void);
char message[] = “Hello, world!”;
int rely = Zero;
int j = Zero;
int liquid crystal display;

int important()

wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);
whereas(1)
scrollText();

void scrollText(void)

int i, n;
int h;
int tempSpace = Zero;
char scrollPadding[] = ” “;
int messageLength = strlen(scrollPadding) + strlen(message);
for (n = Zero; n < messageLength; n++)h = 16; usleep(300000); printf(“x1B[2J”); if (j > messageLength)
j = Zero;

for (i = Zero; i < j ; i++)
scrollPadding[h – j] = message[i];
h++;

lcdPosition(liquid crystal display, Zero, Zero);
lcdClear(liquid crystal display);
lcdPrintf(liquid crystal display, “%s”, scrollPadding);
j++;

Scroll Left to Proper

This program scrolls textual content in from left to proper, then pauses, clears the display, and loops again to the starting:

#embrace <stdio.h>
#embrace <wiringPi.h>
#embrace <liquid crystal display.h>
#embrace <string.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7

void scrollText(void);
char message[] = “Hello, world!”;
int rely = Zero;
int j = Zero;
int liquid crystal display;

int fundamental()

wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);
whereas(1)
scrollText();

void scrollText(void)

int i, n;
int h;
int tempSpace = Zero;
char scrollPadding[] = ” “;
int messageLength = strlen(scrollPadding) + strlen(message);
for (n = Zero; n < messageLength; n++)h = 16; usleep(300000); printf(“x1B[2J”); if (j > messageLength)
j = Zero;

for (i = strlen(message); i >= Zero; i–)
scrollPadding[j – h] = message[i];
h++;

lcdPosition(liquid crystal display, Zero, Zero);
lcdClear(liquid crystal display);
lcdPrintf(liquid crystal display, “%s”, scrollPadding);
j++;

Print Knowledge From a Sensor

As an instance to present you ways to show readings from a sensor, this program prints temperature and humidity readings to the LCD utilizing a DHT11 temperature and humidity sensor. To see how to arrange the DHT11 on the Raspberry Pi, see our article How to Set Up the DHT11 Humidity Sensor on the Raspberry Pi.

The sign pin of the DHT11 is related to bodily pin 7 of the Raspberry Pi:

#embrace <wiringPi.h>
#embrace <liquid crystal display.h>
#embrace <stdio.h>
#embrace <stdlib.h>
#embrace <stdint.h>

//USE WIRINGPI PIN NUMBERS
#outline LCD_RS 25 //Register choose pin
#outline LCD_E 24 //Allow Pin
#outline LCD_D4 23 //Knowledge pin four
#outline LCD_D5 22 //Knowledge pin 5
#outline LCD_D6 21 //Knowledge pin 6
#outline LCD_D7 14 //Knowledge pin 7
#outline MAXTIMINGS 85
#outline DHTPIN 7

int liquid crystal display;
int dht11_dat[5] = Zero, Zero, Zero, Zero, Zero;

void read_dht11_dat()

uint8_t laststate = HIGH;
uint8_t counter = Zero;
uint8_t j = Zero, i;
float f;

dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = Zero;

pinMode(DHTPIN, OUTPUT);
digitalWrite(DHTPIN, LOW);
delay(18);

digitalWrite(DHTPIN, HIGH);
delayMicroseconds(40);

pinMode(DHTPIN, INPUT);

for (i = Zero; i < MAXTIMINGS; i++)

counter = Zero;
whereas (digitalRead(DHTPIN) == laststate)

counter++;
delayMicroseconds(1);
if (counter == 255)

break;

laststate = digitalRead(DHTPIN);

if (counter == 255)
break;

if ((i >= four) && (i % 2 == Zero))
= 1;
j++;

if ((j >= 40) && (dht11_dat[4] == ((dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF)))

f = dht11_dat[2] * 9. / 5. + 32;

lcdPosition(liquid crystal display, Zero, Zero);
lcdPrintf(liquid crystal display, “Humidity: %d.%d %%n”, dht11_dat[0], dht11_dat[1]);

lcdPosition(liquid crystal display, Zero, 1);
//lcdPrintf(liquid crystal display, “Temp: %d.0 C”, dht11_dat[2]); //Uncomment for Celsius
lcdPrintf(liquid crystal display, “Temp: %.1f F”, f); //Remark out for Celsius

int important(void)

int liquid crystal display;
wiringPiSetup();
liquid crystal display = lcdInit (2, 16, four, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, Zero, Zero, Zero, Zero);

whereas (1)

read_dht11_dat();
delay(1000);

return(Zero);

For temperature in Celsius, un-comment line 72, then remark out line 73.

Hopefully this helped you get your LCD up and operating on your Raspberry Pi. The packages above are simply primary examples, so attempt combining them to create fascinating results and animations.

In case you have any issues or questions on putting in the LCD or programming it, simply depart a remark under. And don’t overlook to subscribe to get an e mail once we publish new articles. Speak to you subsequent time!

Recent Comments

    Archives

    Categories