I have been waiting for an excuse to use a Nyan Cat in a blog post and the ‘ST7565 Negative LCD Display’ released by Adafruit being equipped with RGB LED backlights was the perfect occasion. After all, RGB LEDs can create a ‘rainbow’, right? All that’s needed is a cat to go with it and Voila!
Since Nyan Cat needed some friends, Hello Kitty and a Space Invader joined in. Eventually, Darth Vader was called in to scare the Nyan Cat away. But I digress…
Connecting the Adafruit ST7565 to the Netduino
The breakout board supporting the LCD display won’t accommodate a standard 0.1″ header unfortunately, so I had to build my own adapter to use it on a breadboard. No big deal but it’s time consuming.
No, really, this is not a squid.
The back of the connector.
The ST7565 is hooked up to the Netduino, ready for development.
The length of the wires that I used for this test were a bit long and limited the communication on the SPI bus to 22 MHz. With shorter connections, this display is capable of supporting much higher speeds, even though the LCD refresh rate can’t keep up at such high speeds and creates ghosting effects between frames.
Pin Connection Map
Here’s the pin mapping I chose from the LCD connector to the Netduino:
- LCD B-: Netduino D5 (PWM) (LED Blue)
- LCD G-: Netduino D6 (PWM) (LED Green)
- LCD A+: Netduino 3.3v (LED anode)
- LCD R-: Netduino D9 (PWM) (LED Red)
- LCD GND: Netduino GND
- LCD VDD: Netduino 3.3v
- LCD SID: Netduino D11 (SPI MOSI)
- LCD SCLK: Netduino D13 (SPI CLK)
- LCD A0: Netduino D7 (Data / Command)
- LCD /RST: Netduino D4
- LCD /CS: Netduino D10 (SPI CS) or us Netduino D8 if D10 used for the SD card CS pin
Using the Netduino’s PWM pins is not a requirement: the B-, G- and R- LCD pins can just be connected to the Netduino’s GND pin instead, which results in a bright white backlight.
The C# driver
According to the datasheet, the Display Memory Map is divided into 8 pages of 128 bytes each, laid out like this:
There are 2 implications of this memory organization on the Netduino:
- The page that needs to be updated must be selected prior to sending a block of 128 bytes over SPI. This requires switching the LCD A0 pin between Command and Data mode constantly, which is limited to ~8.1KHz on the Netduino.
- In addition, because SPI.Write() only takes a byte or a ushort argument, it is necessary to copy the 128 bytes of the page to an intermediate buffer usable by SPI from the buffer actually storing the 128×64 image bitmap. It would be very useful to add relative buffer addressing capability to SPI.Write() in a future version of the .Net MF to avoid shuffling data around like this.
As it turned out, the display frames still get refreshed quickly.
Sex, Lies and Datasheets
In practice, the Display Memory Map pages are not organized as the datasheet describes. Instead, this is how the pages are actually organized:
- Line zero is in the middle of the display, where page zero starts
- The image wraps at the bottom of page 3 and continues displaying from the top in page 4
Re-using the Netduino SSD1306 driver code
- PowerSaveMode(): which places the display in a mode where its current draw is minimal. It is recommended in the datasheet to enter power save mode before switching the display’s power off. A call to Initialize() is required to get out of the power save mode.
- SetContrast(): adjusts the contrasts of the LCD display.
- The driver provides three constants to set the contrast to High, Medium and Low
- Medium is the default
Controlling the backlight
In order to manage the RGB backlight easily, a new RGBLed class was also added to the netduino helpers library. It can be configured to work with RGB LEDs that have a common anode or common cathode configuration as indicated in the constructor of the RGBLed class. To use it, simply call SetColor() with a hex RGB value and an optional delay expressed in milliseconds before the function returns. The class also defines 12 handy common color constants, which is particularly useful in ‘Nyan Cat Animation’ scenarios 😉
The Adafruit ST7565 is a beautiful, crisp, graphic display with pixels large enough to be seen without a magnifying glass (I’m looking at you, SSD1306…) and small enough to display images or multiple lines of text. The built-in RGB LED backlight makes for an effective method of communicating application status conditions at a glance and from a good distance, without having to read text. The screen appears to be made out of thin glass and is fragile, so be sure to handle the display with care: I inadvertently put a small dent in mine while soldering the connector and did not notice it until I turned the display on. My only wish is for the breakout board to support the common 0.1″ header pitch. Finally, because it only takes ~1.1KB to manage the display buffer, it is very usable for Netduino Plus applications without jumping through hoops.