Summer Robotics Project #4 – LCD Display

As mentioned in yesterday’s blog post, due to difficulties we faced with the Banebot wheel kit, we were unable to mount the wheels onto the motor shaft, and, as a result, we’re currently unable to test the motors properly.

Whilst waiting for replacement screws for the Banebot wheel hubs, we decided to test the LCD display and the compass module. We started with the 16×2 LCD display which we purchase from On the webpage itself, we found a quick start guide which contained a wiring guide (below), that we used to wire up the LCD to the Arduino.

Circuit Guide

The connections were fairly straight forward, and running the LCD was even more simple. The Arduino IDE comes with a few example sketches under LiquidCrystal, making it easy to test the LCD display. The sketches are quite straight forward, with comments to help you along the way, and can also be easily modified.

After successfully running the LCD display off the Arduino UNO, we wanted to try this on the Raspberry Pi as well, after which we would decide which platform to connect the LCD too on the robot. Shortly after receiving our Raspberry Pi Model 2 kits from Vilros (about £57), we configured the OS and also tried out Blink. This sketch which is easy to put together on Arduino, proved to be a bit more difficult on the Raspberry Pi. The code itself was quite straightforward, similar to that of the Arduino sketch, and so was the circuit. However running the code we used seemed to crop up some errors, which we troubleshooted using websites such as Stack Overflow. As you can see below, the code to turn on the LED is written as:

import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
GPIO.output(7,True) ## Turn on GPIO pin 7

Instead, we used try: except:, which seemed to get us out of, what seemed like, a never-ending loop of errors. We then continued to modify the code in Python to make the LED blink.

Due to finding Blink difficult to run on the Raspberry Pi, and also due to our lack of experience with the micro-computer, we were a bit skeptical about connecting the LCD display to the Pi. Regardless, we tried it out anyway. The connections were very similar to that of the Arduino, so connecting up the LCD display to the Pi was easily done, and we used a diagram showing the different pins on the Pi to help. The code was a bit more complicated this time round. However, we were able to download it directly through the Pi and should have been able to run them through the terminal. But this was easier said than done. The sudo command would not work, and we weren’t able to run the code directly off Python either. We tried a different code, and this time it would run but various connection errors would be shown on the Python Shell. After trying a few times, we decided that we wouldn’t linger on this much longer, and that we would connect the LCD to the Arduino instead.

Our next step was to get the LCD to serial print values from external components. We first tried out the HCSR04 ultrasonic sensor. We first connected the ultrasonic sensor, and ran Ping, on the Arduino IDE, to test the output on the serial monitor. Once we were satisfied with the output, we inserted the following parts from the LiquidCrystal > HelloWorld code into Ping:

// include the library code:
  #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");

We then proceeded to change all the Serial.println() functions in the Ping sketch to lcd.print(). (The LiquidCrystal library doesn’t seem to have a .println() function). We ran the code and successfully got the LCD display to display the values being read by the sensor.

But, on second thoughts, we realised that, though this may be useful for testing the accuracy of the sensor, it may be more useful to print values from the compass module instead. As this post is starting to get quite long, I will talk more about this in tomorrow’s blog post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s