To get the IP of your WiFi connection, change eth0 to wlan0 in line 30: #include Ĭhar iface = "eth0" //Change this to the network of your choice (eth0, wlan0, etc.) This program prints the IP address of your ethernet connection (eth0). This program will print the current date and time to the LCD: #include Use both lines below to get a blinking underline/block cursor lcdCursorBlink(lcd, 1) //Cursor ON, block, blinking LcdCursor(lcd, 1) //Cursor ON, underline, not blinking
The cursor is turned off by default, but you can get different styles of cursors using the following functions: Using a while loop with lcdclear() and lcdputs() creates a blinking text effect: #include Then after clearing the screen, the second string is printed to the top row, first column. Notice how the first string is printed to the top row, second column (the default position). The function lcdClear(lcd) clears the screen and sets the cursor position at the top row, first column. This program prints “This is how you” for two seconds, clears the screen, then prints “clear the screen” for another two seconds: #include The following code prints “Hello, world!” to the bottom row, fourth column: #include On a 16×2 LCD, the rows are numbered from 0 to 1, and the columns are numbered from 0 to 15. To change the position, use lcdPosition(lcd, COLUMN, ROW). Lcd = lcdInit (2, 16, 4, LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7, 0, 0, 0, 0) īy default, text is printed to the screen at the top row, second column. The following code prints “Hello, world!” to the screen in 4 bit mode: #include To use the LCD in 4 bit mode, we need to set the bit mode number to 4 in the initialization function (line 20 below). The function lcdPuts(lcd, "Hello, world!") prints “Hello, world!” to the screen. Lcd = 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 function in line 20 is used to initialize the LCD: You’ll need to convert the WiringPi pin numbers to the physical pin numbers of the Raspberry Pi. See here for a diagram you can use to convert between the different numbering systems. To use different pins to connect the LCD, change the pin numbers defined in lines 5 to 14. This program is the minimum code needed to initialize the LCD and print “Hello, world!” to it: #include All of the programs below use the WiringPi pin numbers.
WiringPi has it’s own pin numbering system that’s different from the Broadcom (BCM) and RPi physical (BOARD) pin numbering systems. Gcc -o example example.c -lwiringPi -lwiringPiDevĬhange example and example.c to the file name you want to use.Īfter the program is compiled, it can be executed by entering this at the command prompt: Now we’re ready to start programming the LCD! ExamplesĪll of the examples below are stand-alone C programs, which will need to be complied by entering this at the command prompt:
Now download WiringPi by entering this at the command prompt:
If not, follow the steps below to install it:ġ. If you already have WiringPi installed on your Pi, you can skip this section. WiringPi is a C module that makes it easy to program the LCD.
It will explain how to write, compile, and run C programs. If you’ve never worked with C programs on the Raspberry Pi, you may want to read our article How to Write and Run a C Program on the Raspberry Pi first. However, if it's of sufficient interest for you (or other forum users) to act as alpha/beta testers please send me a PM and then either a "download" can be arranged or I can e-mail a tarball.The brightness and contrast potentiometers are 10K Ohm, but 1K to 3K Ohm resistors will work as well. and, as yet, is perhaps not yet mature enough for "formal" release. This "work" is in parallel with my trying out/building various "basic" test-circuits etc. Code: Select all void C2S_i2cdetect(int chan,Ĭase PI_B1: strcat(i2c_command, " 0") break ĭefault: strcat(i2c_command, " 1") break