Saturday 19 July 2014

Duet, 20x4 LCD screen and SD card.

Although the Duet communicates over Wifi and I can connect to it with a web browser on my phone, I still get many requests for a LCD based controller. I agree that being able to use a simple controller for quick, common functions is a good idea, things like homing the printer, preheating, starting a print etc. Think3dPrint3d have been providing controllers for older electronics that do this since we started, first with the Panelolu then with the Panelolu2 so it's time to port this to the Duet.

I decided to keep it simple to start with, so rather than get the Panelolu2 working, which would require I2C and headaches with 3.3V and 5V logic, I started with the PanelOne, a very basic LCD, Encoder, SD card combination which we are using on our Kossel Mini Kits.

Using a 5V LCD with 3.3V Microprocessor

This was the first hurdle to overcome. The HD44780 standard that these character LCD displays work on states 2.7 to 5V should work fine for the logic signals, however the LCD screens incorporating these chips are a lot more restrictive: 4.8-5.2V for the logic signals. Given the conflicting information I decided to modify a PanelOne prototype board by hand and give it a go. The key is to keep the logic signals separate from the backlight voltages. The schematic is below:

The major change is the addition of the "VCC" power into pin 2 of the LCD from pin 8 of header P1. Previously this was a straight 5V, now this should be able to be either 5V or 3.3V depending on the logic of the Microprocessor we are interfacing with. I connected this up and edited the "Hello World" sketch within Arduino 1.5.7 (1.5.6 r2 works as well) to use the following pin definitions:
                            Arduino pin number  Duet Pin Name  Expansion header pin
 * LCD RS pin to digital pin D67                 PB16          (32)
 * LCD Enable pin to digital D23                 PA14          (10)
 * LCD D4 pin to digital pin D19                 PA10 RXD0     (14)
 * LCD D5 pin to digital pin D18                 PA11 TXD0     (13)
 * LCD D6 pin to digital pin D17                 PA12 RXD1     (12)
 * LCD D7 pin to digital pin D16                 PA13 TXD1     (11)
LiquidCrystal lcd(67, 23, 19, 18, 17, 16);

Happily this worked!

I tested this with two other LCDs (old generic ones off eBay) and it worked with them as well. However as it's outside the guidelines of the LCD manufacturer's datasheets there is no guarantee that all types of HD44780 character LCDS will work in the same way.

Reading an SD card over SPI

The Duet's build in SD card supports SD2.0 and uses a 4 bit HSMCI interface. However it is often convenient to use an SD card reader mounted next to the screen, so I want to support SD over SPI which is how older 3D printer electronics and hardware interface with SD cards. The Arduino environment has a simple SPI SD library that worked straight away. The only customisation required is to make sure SD.Begin() uses the correct CS pin:


For this example I used the SPI0_NPCS0 pin which is arduino digital pin 77. I combined the listfiles example sketch with the LCD display to list the first 4 files on a SD card:

The code (an adaptation of the listfiles example sketch):

#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>

File root;
// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(67, 23, 19, 18, 17, 16); //RS,E,D4,D5,D6,D7

void setup()
  lcd.begin(20, 4);
  lcd.print("Reading Files...");
  delay(2000); //delay or else the message will not be displayed

  if (!SD.begin(77)) {
   lcd.print("initialization done");
   delay(2000); //delay or else the message will not be displayed
   lcd.print("listing 4 files");
   delay(2000); //delay or else the message will not be displayed
   root ="/");
   printDirectory(root, 0);

void printDirectory(File dir, int numTabs) {
  int row=0;
   while(true) {
     if(row>3) return;
     File entry =  dir.openNextFile();
     if (! entry) {// no more files
     for (uint8_t i=0; i<numTabs; i++) {
       lcd.print(' ');
     if (entry.isDirectory()) {
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       lcd.print("  ");
       lcd.print(entry.size(), DEC);


This sketch, and the adapted Kicad schematic are all on the Think3dPrint3d github.


I will test more LCD screens and hopefully will be able to get the next batch of PanelOnes compatible with both 3.3V and 5V.

The big job will be to port and adapt the Marlin menu system to RepRap Firmware. If anyone wants to assist with this project then drop me a line and I may be able to help with some hardware (duet board + LCD screen).


  1. Having looked at the two firmwares it looks as if the best approach would be to start from scratch and generate a menu system that creates gCodes like the web server in the RepRap firmware, rather than calling functions directly as in Marlin.

    Has any one starting looking at this yet? If not I may have a tinker, it looks like a *fun* project

    1. Hi Chris

      I have just spent the afternoon trawling through the Marlin LCD implementation and I tend to agree - It would have more flexibility if the menu system used Gcodes. The majority of the functionality on the existing Marlin menu system is implemented in gcodes by RepRapFirmware.

      An additional example would be the ability to tie certain choices of the menu system into macro g-code files stored on the SD card. That would mean that the menu system could be easily modified to work with anyone's hardware by modifying the macro.


    2. Yes loading gcode macros would be an ideal way to cope with allowing for customisation to commands like preheating.

  2. If you are up for helping out then send me an email and we can discuss further!



  3. Hi,

    Planning to buy Duet boards. But, confused with the LCD controller. Now-a-days the 3d printers are not selling without LCD controllers.
    Here you have shown the connection. But, it is looking like, the pins from the flat core cable of LCD controller are split and connected to the DUET, which looks very complex.
    As you told, have you tested with some other LCD controllers? Also have you tested with adding a file and fully printed with this controller.
    Looks like this post is 1 year old, still there is no clear update.
    Can PanelDue be used? But, that is a costly option in which the price equals the board cost.

    1. Hi Selvakumaran

      This is a hardware proof of concept, which I am not currently taking further and most people are happy with using Wifi on their phone or tablet, and those who want more use the PanelDue. This issue is the firmware work required to make this a reality.




Comments are now moderated to reduce spam, please excuse the additional time this will entail.

Note: only a member of this blog may post a comment.