Serial Graphic LCD Hookup
Firmware Overview
Before we dive into hooking up the LCD to an Arduino, let's discuss the firmware for a minute. The firmware is the code that resides on the backpack. It serves as a bridge, or translator, between the LCD and whichever microcontroller you use to communicate with it. On top of the firmware, we've written an Arduino library to make using the backpack even easier.
Backpack Firmware
We've revamped the firmware that ships with the backpack. It runs smoother than ever to give any project an awesome graphical display. Pending you don't need anything too fancy, you should be able to use the default firmware for all your LCD needs. But that doesn't mean that it's not worth understanding. To see the firmware, head on over to the Serial Graphic LCD Backpack GitHub repository. You can either download the zip file, clone the repo to your computer, or just navigate with GitHub's default editor.
Inside the Firmware folder you'll see a lot of .c and .h files. These are the files that tell the backpack how to interact with the LCD based upon the input received. Since modifying the source code is beyond the scope of this tutorial, we'll leave it here. Just know that if there is some internal functionality that you'd like to add, delete, or modify, this is the place to do it.
Do note that you'll need a programmer to change the firmware on the backpack. It is not Arduino compatible, even though the IC on board is an ATmega328, the same IC found on many Arduino boards. Check out the Troubleshooting section for more info on how to reflash the firmware to your backpack.
Arduino Library
To make using the Serial Graphic LCD Backpack as easy as possible, we've written an Arduino library. The library can be found on the GitHub repository. This library basically creates function for each of the commands listed on the previous ASCII commands page. The example sketch that comes with the library demonstrates each function and shows you how to implement them for a full range of purposes on the LCD. If you need a refresher on installing an Arduino Library, please visit our Installing a Library tutorial.
Each function will be listed here and given a short description. However, these functions build upon the commands listed in the ASCII Commands section. For more details on each function, please refer to that section or read the comments provided in the library files.
Print Commands
printStr(char Str[78])
- Prints a string to the LCD. The buffer is set to 78 by default but can be changed in the header file.printNum(int num)
- Prints a single number to the LCD.nextLine()
- Acts as a newline for text.
These three function exist because the instance of the Software Serial library is declared within the library files to communicate with the backpack. Therefore, using the typical serial.print()
commands won't work to send text to the LCD while using this library.
LCD Functionality
clearScreen()
- Clears the LCD of any and all pixels.toggleReverseMode()
- Toggles reverse mode -- blue on white for the 160x128 display and green on black for the 128x64 display.toggleSplash()
- Turns the SparkFun splash screen on or off. Note that the one second delay on startup remains with or without the splash screen enabled.setBacklight(byte duty)
- Set the brightness of the backlight. Takes a single int as a parameter. The range is 0-100, where 0 is OFF and 100 is full brightness. Anything higher than 100 will still result in a max value of 100.setBaud(byte baud)
- Set the baud rate of the backpack. Takes a single int as a parameter with a range of 49-54.restoreDefaultBaud()
- Restores the LCD back to the default baud rate of 115200bps.
Cursor Positioning
setX()
- Sets the x position of where text will appear on the screen.setY()
- Sets the y position of where text will appear on the screen.setHome()
- Sets poth x and y back to position 0,0.
Drawing
setPixel(byte x, byte y, byte set)
- Set or reset (revert back to the background color) any pixel on the LCD.drawLine(byte x1, byte y1, byte x2, byte y2, byte set)
- Draws a line between two x,y coordinates.drawBox(byte x1, byte y1, byte x2, byte y2, byte set)
- Draws a box between two x,y coordinates.drawCircle(byte x, byte y, byte rad, byte set)
- Draws a circle with the center point starting at the given x,y coordinate and then extends out to the given radius.eraseBlock(byte x1, byte y1, byte x2, byte y2)
- Erases the block spanning from the two given x,y coordinates.demo()
- Initiates an internal demo built into the firwmare.