Bugdozer’s Liquid Crystal Display

Bugdozer is an autonomous mini-Sumo robot. To aid in debugging and testing, a 4-line 20-character (4x20) LCD panel can be attached to the main board.

The LCD is an Optrex #DMC 20434-CEM or PWB 20434-CEM purchased from All Electronics for $7.00 (CAT# LCD-46). The liquid crystal display has the industry standard 14-pin connection and 5 x 8 text characters.

LCD showing splash page

LCD showing splash page

The robot’s splash screen tells me what date of firmware (software) is installed in this particular MC68HC908GP32. I have a number of 6808 MCUs that float around, so this tells me if I’ve installed the latest and correct microcontroller in a particular robot.

In the lower-right corner, one custom icon represents the battery level as seen by the GP32’s built-in analog-to-digital converter. The custom character itself is reprogrammed as the battery level changes; so only one of the eight custom characters is used up.

Three resistors form a voltage divider for sampling the batteries. They’re hiding inside the microcontroller socket!

Three resistors form a voltage divider for sampling the batteries. They’re hiding inside the microcontroller socket!

To determine the battery level, Bugdozer uses an internal ADC (analog-to-digital converter) built into the microcontroller. There are a couple of tricks, though.

1. The microcontroller can’t be directly connected to the batteries, because they’re up to 18 volts. Three resistors, 4.7 kilohms + 2.2 kilohms + 2.2 kilohms, are connected between power and ground. One input pin of the ADC connects between the last 2.2 kilohms resistor and ground.

The group of three resistors forms a voltage divider. This causes the voltage entering the microcontroller to be 2.2 / (4.7 + 2.2 + 2.2) = 24% of the maximum. For 18 volts, only 4.3 volts gets to the microcontroller. If these are especially fresh batteries, perhaps 19.2 volts total, only 4.6 volts gets to the microcontroller. That’s good, because 5 volts is the limit.

2. The ADC needs some current from the source in order to get a good reading.

Greater than 10 kilohms of resistance would cause errors. In this case, only 6.9 kilohms lies between the ADC and the source.

Unfortunately, the resistors are using a milliamp or so of current, just sitting there.

3. The microcontroller ADC module gets power from a 5-volt regulator.

Because the 5-volt regulation stays constant and the full voltage drops, the ratio between them changes. This allows the ADC to see an ever-decreasing value.

If an ADC was supplied by an unregulated source and the input was also connected to the same unregulated source, the input value would always stay the same. No matter how much it dropped, the ADC module would always see the power at the maximum, because it would have nothing else to compare it to.

The other icon in the lower-right corner of the LCD is a heartbeat. It switches between a big and small heart every half of a second to indicate that the main loop is still executing. (The heartbeat purposely isn’t interrupt driven.) I got the idea for the heart icon from the Rug Warrior Pro kit I purchased from A K Peters Ltd.

Two pushbuttons

Two pushbuttons

Bugdozer’s motherboard contains two low-profile miniature pushbuttons.

The first button steps through each page of information on the LCD.

The second button either starts the combat countdown or causes some other action depending on which page is displayed (or would be displayed) on the LCD. A common action would be to reset the minimum / maximum values recorded for a set of sensors.

LCD showing phototransistor line sensors

LCD showing phototransistor line sensors

Bugdozer has five phototransistors pointed at the floor to look for the white borders of the Sumo ring. The phototransistors are individually connected to the ADC (analog-to-digital) inputs.

This page of the LCD shows the minimum, current, and maximum values read by the line sensors. The values are updated in real time as the robot is moved around the floor. In the photograph above, the two ghosted numbers on the “Cur:” line show changing values.

The values are recorded even when the page is not shown, so this page can be examined after a battle or a fall to indicate the ranges that the robot observed. Pressing the second button on the motherboard, when this page is displayed, resets the minimum and maximum values.

LCD showing 74HC251 added inputs

LCD showing 74HC251 added inputs

A pair of 74HC251 multiplexers provide 16 additional external logic pins. These pins are then debounced in software. Each line shows the current (“C”), last read (“L”), and debounced (“D”) value of each pin.

LCD showing attack status

LCD showing attack status

Normally off, the attack page automatically appears when the start button is pressed. The attack mode (off, countdown, hunt, target left, target right, reverse-twist-and-flip, and so on) is displayed, along with the amount of time (in thousandths of a second) remaining in the move.

The filtered object sensor and line sensor data is also displayed in the form of up arrows (target or line sighted) or black squares (nothing sighted).

Updated LCD

Updated LCD

Update: A description of the starting move is now listed at the top of this LCD page. Also, the timer indicates if the time for a maneuver has been reduced for higher voltage batteries (“norm” vs. “hi V”).

LCD showing battery status and range

LCD showing battery status and range

The battery icon is useful for a rough estimate. However, this page displays the exact hexadecimal values being read by the analog-to-digital port, as well as the minimum and maximum values recorded.

LCD showing general system information

LCD showing general system information

The code calculates RAM usage by subtracting the known start of RAM (a constant) from the address of a variable created immediately after all other global variables. FLASH usage is computed in a similar manner. Neither resources are running low on this GP32. (I suppose RAM and FLASH remaining would have been better values to display. This is a little like a fuel gauge telling you how much gas you’ve used so far.)

Updated RAM used and free

Updated RAM used and free

Update: The amount of used and free RAM and FLASH is now displayed. LCD starts indicates the number of attempts made to initialize the display and then confirm communication by reading characters back. In some prior projects, certain canned oscillators provided irregular start-up conditions that locked up the display. The LCD starts value also increments if the display becomes loose or disconnected. The value is retained but incremented through MCU resets, but obviously lost upon complete loss of power.

Ticks indicates (in hexadecimal) the number of thousandths of a second that have passed since power up. This is moderately fun to watch. Exercise to the readers, how long until the display rolls over?

LCD showing character set
LCD showing character set
LCD showing character set
LCD showing character set

LCD showing character set

All but eight characters are embedded in the ROM of the LCD controller. However, depending on the manufacturer or module, different characters may be available. Although most of the characters remain consistent and in the same order, some of the nicer displays add useful symbols in the places the industry standard set leaves blank. (Notice that there are a lot of blanks in this controller?)

These 14-pin industry-standard LCDs are text character based, not graphical. However, 8 characters (repeated twice in the first 16 locations in the character set) can be modified. For this robot, I chose to load two hearts, a battery, a note, a diamond, a checkmark, and up and down arrows. These characters can be modified or changed around at any time, of course, but are lost upon power down.

LCD connector

LCD connector

The LCD is too heavy, too wide, and possibly too fragile to be used during combat. A connector atop the robot’s motherboard allows for easy installation and removal. A single standoff screw hole at the bottom of the robot’s motherboard holds the LCD in place. Four screw holes (one in each corner) are provided on the LCD itself, and should be used for reliable attachment.

The LCD is operated in 4-line mode, rather than 8-line. This saves four pins without significant performance degradation. My software library can actually drive either configuration, and it can also control smaller or larger displays (fewer/more lines or characters) without the caller needing to know.

Of the 14 pins, the connections are:

  1. VSS (0 volts or GND)
  2. VCC (+5 volts DC)
  3. VEE (I’m using 0 volts, but a thermal circuit can be rigged for optimal contrast in all temperatures.)
  4. RS (+5 volts to communicate data, 0 volts to communicate commands)
  5. R/W (+5 volts to read, 0 volts to write)
  6. E (+5 transitions to +0 to clock data or command in or out)
  7. DB0(data or address to communicate. Not connected in 4-line mode. Least-significant bit.)
  8. DB1(data or address to communicate. Not connected in 4-line mode.)
  9. DB2(data or address to communicate. Not connected in 4-line mode.)
  10. DB3(data or address to communicate. Not connected in 4-line mode.)
  11. DB4(data or address to communicate.)
  12. DB5(data or address to communicate.)
  13. DB6(data or address to communicate.)
  14. DB7(data or address to communicate. Most-significant bit.)

This is a parallel, address/data multiplexed interface.

None of this matters if the robot simply drives out of the sumo ring. Let’s see how it detects the edges of the ring using reflective light sensors.