Adding a 12864 display to Duet 2

Oct 3, 2019 min read

Update: This post made its way to the Duet3D forum. In the thread 12864 Modification, users shared this guide, and David Crocker (dc42) of Duet3D said that, now he knew such adapters existed, he would look at making 12864 support standard in the firmware. The work that followed is recorded in the long thread Logic Level shifter for 12864 display on Duet 2 Wifi, which also refers to the schematic from this post. 12864 support for the Duet 2 WiFi/Ethernet was mainlined in RepRapFirmware 3.2. If you run RRF 3.2 or later, you no longer need a custom firmware build. The display is enabled with M918, and the mainline firmware uses its own pin assignment, which is different from the one below. Follow the official Duet3D documentation for wiring and supported controllers. The rest of this post is kept as it was for older firmware versions and for reference.

The Duet 2 series of 3D printer control boards has a lot going for it, and it is one of the best boards you can buy for your printer right now. Display support has always been limited, though, so the PanelDue was the obvious choice for anyone running a Duet 2. The Duet 2 Maestro added RepRapFirmware support for the much cheaper 12864 displays, better known as the RepRapDiscount Full Graphic Smart Controller. Unfortunately, that support depends on a small piece of hardware on the Maestro, so it does not work on a Duet 2 WiFi or Ethernet out of the box. This post shows how I got the display working on a Duet 2 anyway.

Prerequisites

What you’ll need

  • 74HCT08P quad AND gate IC
  • Duet 2 WiFi or Duet 2 Ethernet
  • RepRapDiscount Full Graphic Smart Controller

To build the adapter on a breadboard (no soldering):

  • Breadboard
  • Jumper wires

To solder a permanent adapter board instead:

  • Perfboard
  • Female headers (for the connection to the Duet)
  • Male headers (for the display cables)
  • Soldering iron and solder
  • Wire

What you give up

  • Stepper driver 11 (the twelfth driver, counting from zero). Its pins are reused to drive the display.

Building the adapter

The display uses 5 V logic, but the Duet 2 uses 3.3 V logic, so the signals have to be level-shifted. The 74HCT08 does this: its inputs accept 3.3 V as a logic high, and its outputs swing to 5 V. It is wired the same way as on the Duet 2 Maestro. Make all connections as shown in this schematic. It is a bit quick and dirty, but it should be easy to follow. I used plain pin headers for the cables, and the schematic marks where the notch of each connector goes.

You can build the circuit on a breadboard or solder it onto a piece of perfboard for a permanent solution.

Modifying the firmware

First, follow the excellent build instructions for RepRapFirmware. Once you can build and flash the firmware, come back here. The firmware needs to know which pins carry which display signals, and those are defined in RepRapFirmware/src/DuetNG/Pins_DuetNG.h.

Make the following changes:

  1. Set SUPPORT_12864_LCD to 1.
  2. Reduce NumDirectDrivers and NumEndstops from 12 to 11.
  3. Remove the last entry from each of ENABLE_PINS, STEP_PINS, DIRECTION_PINS and END_STOP_PINS.
  4. Add the following pin definitions for the display and rotary encoder:
// 12864 LCD
// The ST7920 datasheet specifies minimum clock cycle time 400ns @ Vdd=4.5V, min. clock width 200ns high and 20ns low.
// This assumes that the Vih specification is met, which is 0.7 * Vcc = 3.5V @ Vcc=5V
// The Duet Maestro level shifts all 3 LCD signals to 5V, so we meet the Vih specification and can reliably run at 2MHz.
// For other electronics, there are reports that operation with 3.3V LCD signals may work if you reduce the clock frequency.
constexpr uint32_t LcdSpiClockFrequency = 2000000;		// 2.0MHz
constexpr Pin LcdCSPin = 8;
constexpr Pin LcdBeepPin = 60;
constexpr Pin EncoderPinA = 85;
constexpr Pin EncoderPinB = 25;
constexpr Pin EncoderPinSw = 7;

The full set of changes as a diff:

diff --git a/src/DuetNG/Pins_DuetNG.h b/src/DuetNG/Pins_DuetNG.h
index a9c3005..cf1a387 100644
--- a/src/DuetNG/Pins_DuetNG.h
+++ b/src/DuetNG/Pins_DuetNG.h
@@ -28,7 +28,7 @@ constexpr size_t NumFirmwareUpdateModules = 4;		// 3 modules, plus one for manua
 #define SUPPORT_IOBITS			1					// set to support P parameter in G0/G1 commands
 #define SUPPORT_DHT_SENSOR		1					// set nonzero to support DHT temperature/humidity sensors
 #define SUPPORT_WORKPLACE_COORDINATES	1			// set nonzero to support G10 L2 and G53..59
-#define SUPPORT_12864_LCD		0					// set nonzero to support 12864 LCD and rotary encoder
+#define SUPPORT_12864_LCD		1					// set nonzero to support 12864 LCD and rotary encoder
 #define SUPPORT_OBJECT_MODEL	1
 #define SUPPORT_FTP				1
 #define SUPPORT_TELNET			1
@@ -37,11 +37,11 @@ constexpr size_t NumFirmwareUpdateModules = 4;		// 3 modules, plus one for manua
 
 // The physical capabilities of the machine
 
-constexpr size_t NumDirectDrivers = 12;				// The maximum number of drives supported directly by the electronics
+constexpr size_t NumDirectDrivers = 11;				// The maximum number of drives supported directly by the electronics
 constexpr size_t MaxTotalDrivers = NumDirectDrivers; // The maximum number of drives including CAN expansion
 constexpr size_t MaxSmartDrivers = 10;				// The maximum number of smart drivers
 
-constexpr size_t NumEndstops = 12;					// The number of inputs we have for endstops, filament sensors etc.
+constexpr size_t NumEndstops = 11;					// The number of inputs we have for endstops, filament sensors etc.
 constexpr size_t NumHeaters = 8;					// The number of heaters in the machine
 constexpr size_t NumExtraHeaterProtections = 8;		// The number of extra heater protection instances
 constexpr size_t NumThermistorInputs = 8;
@@ -72,9 +72,22 @@ constexpr Pin AdditionalIoExpansionStart = 220;		// Pin numbers 220-235 are on t
 
 // DRIVES
 constexpr Pin GlobalTmc2660EnablePin = 38;			// The pin that drives ENN of all TMC2660 drivers on production boards (on pre-production boards they are grounded)
-constexpr Pin ENABLE_PINS[NumDirectDrivers] = { 78, 41, 42, 49, 57, 87, 88, 89, 90, 31, 82, 60 };
-constexpr Pin STEP_PINS[NumDirectDrivers] = { 70, 71, 72, 69, 68, 66, 65, 64, 67, 91, 84, 85 };
-constexpr Pin DIRECTION_PINS[NumDirectDrivers] = { 75, 76, 77, 01, 73, 92, 86, 80, 81, 32, 83, 25 };
+constexpr Pin ENABLE_PINS[NumDirectDrivers] = { 78, 41, 42, 49, 57, 87, 88, 89, 90, 31, 82};
+constexpr Pin STEP_PINS[NumDirectDrivers] = { 70, 71, 72, 69, 68, 66, 65, 64, 67, 91, 84};
+constexpr Pin DIRECTION_PINS[NumDirectDrivers] = { 75, 76, 77, 01, 73, 92, 86, 80, 81, 32, 83};
+
+// 12864 LCD
+// The ST7920 datasheet specifies minimum clock cycle time 400ns @ Vdd=4.5V, min. clock width 200ns high and 20ns low.
+// This assumes that the Vih specification is met, which is 0.7 * Vcc = 3.5V @ Vcc=5V
+// The Duet Maestro level shifts all 3 LCD signals to 5V, so we meet the Vih specification and can reliably run at 2MHz.
+// For other electronics, there are reports that operation with 3.3V LCD signals may work if you reduce the clock frequency.
+constexpr uint32_t LcdSpiClockFrequency = 2000000;		// 2.0MHz
+constexpr Pin LcdCSPin = 8;
+constexpr Pin LcdBeepPin = 60;
+constexpr Pin EncoderPinA = 85;
+constexpr Pin EncoderPinB = 25;
+constexpr Pin EncoderPinSw = 7;
+
 
 // Pin assignments etc. using USART1 in SPI mode
 Usart * const USART_TMC2660 = USART1;
@@ -92,7 +105,7 @@ constexpr Pin DueX_INT = 17;						// DueX interrupt pin = PA17 (was E6_STOP)
 // Endstops
 // RepRapFirmware only has a single endstop per axis.
 // Gcode defines if it is a max ("high end") or min ("low end") endstop and sets if it is active HIGH or LOW.
-constexpr Pin END_STOP_PINS[NumEndstops] = { 46, 02, 93, 74, 48, 96, 97, 98, 99, 17, 39, 8 };
+constexpr Pin END_STOP_PINS[NumEndstops] = { 46, 02, 93, 74, 48, 96, 97, 98, 99, 17, 39};
 constexpr Pin DUEX_END_STOP_PINS[5] = { 200, 203, 202, 201, 213 };				// these replace endstops 5-9 if a DueX is present
 
 // HEATERS

Then build the firmware and flash it to your Duet as usual.

If you have questions or suggestions, leave a comment or email me at blog@mscheck.de.

Further reading