We love the LCD screen. Really. It is one of our favorite tools. Here’s a more technical run-down of the uses that the girls mention in their STEM Educational Video that they entered this week in the REC Foundation’s 2017 Online Challenge.
First, you need to buy yourself an LCD screen, and a Serial Y Cable. NOTE: the cable does not come with the screen, even though it seems like it should. You must buy it separately. You can use up to 2 LCD screens on your robot at one time, though honestly I’ve never seen anyone use 2.
Plug the 4-prong end of the Y-cable into either UART1 or UART2 on the Cortex (remember which one you use; convenient to always use UART1, unless you have a specific reason not to). This plug is over on one corner of the Cortex, near where motor encoders get plugged in. You’ll plug the other wires into the LCD screen. We have a little mnemonic to remember which wires go into which plug: whiTe goes into TX (over-emphasize the “T” when you say “white”), and yell-ER goes into RX (pronouncing “yellow” with a southern drawl). If they are plugged in backward, it will not work.
When you are plugged in, and the robot is on, you will get the wonderfully informative “but 0 0 0” message on lines 1 and 2 of the screen.
Make sure your kids install the LCD on the robot (a) where it’s easily accessible to read the screen and press the buttons, and (b) also protected from being struck by game elements or other robots.
Displaying a Message
(Much of this programming information is in easyC, because that’s what we used at the time of this writing. The exact function names used in RobotC can be found on the RobotC help page, under Command Library – VEX Cortex / ROBOTC / LCD Display.
As a first test to make sure your screen is working, include in your program (autonomous, joystick, or competition) a line of code that just displays a message, and does nothing else. You’ll need to initialize the LCD screen at the start of the program, and somewhere before you have the message display, it’s helpful to make the back-light turn on.
In EasyC, you need to use one LCD display block for each line of the LCD screen that you want to use. Drag over a block and enter the text for your Line 1 message, and leave all of the other stuff blank (the stuff related to variables, etc.); do the same for Line 2 if you’re using it. NOTE: If you put a message on Line 2, and later in your program display a different message, but only use Line 1 at that time, the Line 2 text will remain on the screen unless you specifically drag over a block and tell Line 2 to display a blank line.
Make sure that you can display a static message with the back light on first, before you move on to anything more dynamic.
Displaying Sensor or Variable Values
If your robot is tethered to your computer, you can use the print-to-screen function to display sensor (or variable) values, but that covers about 1% of the situations where you want to know what a sensor value is. Most of the time, you’re in a joystick/competition program, or your robot is moving around the field, and you cannot be tethered to the computer, or it’s just not realistic.
Enter the LCD screen! You can put somewhere in your Main() loop a get command to get the latest sensor value and then an LCD command to display it on the screen. If it’s a variable you’re after, just make sure that the LCD display command is somewhere after the variable is being calculated.
The following screen shot shows getting the potentiometer value and then displaying it on the LCD.
But These Sensor Values Make No Sense!
Beware! Each line of the LCD screen can only hold 16 characters. If you give it text that’s 14 characters, plus a 3-digit sensor value, the LCD will show you the first 2 digits of your sensor value, and will just cut off/not display the 3rd digit. So you may think that you’re getting sensor data just fine, but at some point it will look like the numbers wrap around and restart their numbering at 0 again. It will look like it has wrapped around to, say, “11”, when the sensor value is really 110.
Beware some more (RobotC users)! When displaying sensor values on the screen—especially in a while loop—be sure to clear the existing text before displaying the sensor’s value. We were trying to calibrate our gyro sensor recently, and when we turned the robot around 360º, the value in RobotC is supposed to reset to 0, but on our robot, once we passed 3599 (the gyro reports values in tenths-of-a-degree, so 360º = 3600), it would jump to 1599, and then if we kept turning it, the values got ridiculously huge—3299, 9099, etc. Whaaaaa??? After half of a meeting devoted to this problem, we realized that once we passed 0, it was in fact displaying the new degree values, starting in the left-most position on top of what was already there, so what we were reading as 1599 was really a sensor value of 15, written on top of the previous value of 3599. So we added a line of code inside the while loop to clear the first line of the LCD display and then write the sensor value. (This appears to be only a RobotC problem; easyC is fine with the blocks of code shown above, without an extra block for clearing the line.)
Why Isn’t this Joystick Button Working?!?
One other use where we find the LCD to be valuable is debugging our programs. There are many times when a program is not working, and you just can’t figure out what is actually executing in the code. You’ve got some code that seems like it should be doing the right thing, but nothing is happening.
Enter the LCD screen! In addition to displaying a sensor value or variable as described above, you could throw up a message to let you know that a certain block of code is executing. It might be that the code that seems like it should be doing the right thing is never actually being executed at all; there is some up-stream logic that’s preventing it from ever happening.
You could put different messages in different sections of your code, but be aware that a joystick program is looping through rapidly, and if you have Message1 display when x happens, and then Message2 display when y happens, Message1 may display for a tiny fraction of a second, and then be over-written by Message2. It’s good to stick with at most 2 non-exclusive messages, each of which occupies one line of the LCD screen (so that they can both display at the same time if necessary).
Autonomous Program Selector
Our FAVORITE use of the LCD is as a little menu-selector to choose an autonomous program during a competition. If you’ve got an autonomous program that involves moving left or right, you’ve undoubtedly got 2 of them, depending on what square your robot starts in. In one scenario it’ll need to move left, but if it starts in the other colored starting square for that alliance team, it’ll need to move right.
Without the LCD screen, your team needs to find their alliance partner, decide who’s going to start where (and communicate clearly what they mean by “start on the left square,” for example), and then go back to the pits and load the correct program onto the robot. Let me tell you how many times I have seen this result in the wrong program on the robot—20% of the time, maybe? Your team could lose a match without those autonomous points, and it’s incredibly frustrating for the kids to have their perfect code work backward when the clock starts. So why not remove 99% of human error and have a little menu selector on the robot itself! That way your team never has to load a program on the robot all day long at a competition. We even include our programming skills challenge code as one of the menu items, so we rarely have to open up the computer at a tournament.
You can download EasyC code (or pseudo-code) on our downloads page that will get you started creating your own menu (full credit goes Ephemeral_Being from the VEX forum for writing this code). Important notes, as the girls mention in their video:
- You must have all of your autonomous code combined into one big competition program, with the separate autonomous patterns set up as user functions.
- The menu selector code needs to be in the Initialize (easyC) or Pre-Autonomous (RobotC) section of your competition program (if you’re like me, I bet you didn’t know there was any use for this section!).
- The robot must be plugged into field control (either plugged into a competition field, or plugged into a competition switch), and the field control must be set to “disabled.”
Edit 7/2/18: Here’s a very clear and helpful YouTube tutorial on programming your own auton menu selector in easyC. There are many RobotC examples of this type of code on the VEX Forum; a simple search will find some for you. You can also read my detailed post that walks you through how Ephemeral Being’s code works.
(Side note: If your team does not own a competition switch, buy one. Hold a bake sale if you have to, it’s only $20, and it’s UNBELIEVABLY useful.)
There are of course many other uses for the LCD. Get creative! As the girls mention in their video, other uses:
- a pneumatics deployment counter – have the LCD display how many times the pneumatics have been used
- displaying motor power
- flashing backlight when an event occurs, such as 10 seconds left in a match
- displaying battery voltage (as well as power-expander battery voltage)
- anything else you can think of!
How Do *You* Use the LCD Screen?
Do you have another use for the LCD screen not listed here? We’d love to know! Please email us, and we’ll add an addendum to this post!