Adding a 12864 display to Duet 2

Submitted by Markus Scheck on Thu, 03.10.2019 - 20:12

Adding a 12864 display to Duet 2

The Duet 2-Series of control boards for 3D-Printers brings a lot of desirable features to the table and are one of the best boards to get for your printer right now - but display support was always sparse and thus the PanelDue was the screen to go with when using a Duet 2. With the Duet Maestro, support for the much cheaper 12864-Displays (better known as the RepRapDiscount full graphics smart controller) was added to RepRapFirmware. Sadly, this required a simple hardware modification and thus isn't directly compatible with Duet 2. In this article, I'll document my journey on getting the display to work on Duet 2.

Prerequisites

What you'll need

  • 74HCT08P Quad-AND-Gate chip
  • Duet 2 Wifi or Ethernet
  • RepRapDiscount full graphics smart controller

If you want to use a breadboard to avoid soldering

  • Breadboard
  • Jumper wires

If you want to solder an adapter board instead

  • Perfboard
  • Female headers (for the connections to Duet)
  • Male headers (For the display wiring)
  • Soldering iron + solder
  • Wires

What will stop working

  • Stepper driver channel 11 (The pins are needed for driving the screen)

Creating the adapter

The display uses 5V logic, while the Duet 2 uses 3V logic - therefore we need to shift the levels of the signals, which is where the Quad-AND-Gate IC comes in handy. It will be connected in the same manner as on the Duet Maestro. All connections should occur as shown in the following schematic (It's a bit quick and dirty but should be understandable. I used regular pin headers for the cables, but have indicated where the notch on the connector should go).

You can do this on a breadboard or more permanently solder everything to a piece of perfboard.

TODO: add images

Modifying the Firmware

First, follow the excellent instructions on how to build RepRapFirmware on their website. When you are familiar with the build and update process, return here. For the firmware to know which pins correspond to which functions, we need to change the pin definitions in RepRapFirmware/src/DuetNG/Pins_DuetNG.h.

Reduce NumDirectDrivers and NumEndstops to 11, remove the last number from ENABLE_PINS[NumDirectDrivers] , STEP_PINS[NumDirectDrivers], DIRECTION_PINS[NumDirectDrivers] and END_STOP_PINS[NumEndstops]. Afterwards, add the following block to the firmware and set SUPPORT_12864_LCD to 1:

// 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;

To better illustrate the code changes, here is a patchdiff.

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

If you have any questions or suggestions leave a comment or write me an email to blog@mscheck.de.

TODO: add diff, patch and bin.

interesting / helpful links

https://forum.duet3d.com/topic/6449/making-the-lcd-12864-work-on-the-duetwifi-please-advise/7