Having seen the PanelMax LCD and Encoder for RAMPS, I wanted to get a similar setup working on Sanguinololu. the first step was to get an ATmega 1284P working and load Marlin firmware which supports this sort of setup with minimal changes.
Wiring and Testing
I intended to keep using the SDSL card reader (not much point in having a screen if you have to have you computer plugged in) which left very few pins unused on the microprocessor. Conveniently these are all together on the expansion header:
The image is grabbed from the .brd eagle file - easier to show than on an actual board. There are 9 I/O pins free, one of which is within the SDSL plug footprint but is not used by SDSL. Matching them up to the requirements for a standard 20x4 LCD with a HD47780 interface, and a rotary encoder (with a built in switch) gave;
For the LCD;
RS "PWM" Digital pin 4
ENABLE "SDA" Digital Pin 17
D4 "A1" Digital Pin 30
D5 "A2" Digital Pin 29
D6 "A3" Digital Pin 28
D7 "A4" Digital Pin 27
For the Encoder;
EN1 "RX1" Digital Pin 10 (must be a hardware interrupt pin)
EN2 "TX1" Digital Pin 11 (must be hardware interrupt pin)
SW1 "SCL" Digital Pin 16 (Click switch)
Adds up to 9, just enough!
I connected the circuit up (quickly, I was impatient!) as shown in the Schematic. Note that the connection marked SCL on the Sanguinololu expansion header is plugged onto by the SDSL plug, but not used by the SDSL, I have connected onto this pin where it comes out of the plug as it is needed for the push switch in the encoder. The two variable resistors as 5K as that is what I had to hand, the one for the LCD brightness (R1) is set to around 1K, the one for the LCD contrast (R2) is set to around 4.5K Ohms.
After connecting it up I loaded the Arduino 0023 IDE, and modified the "Hello world" example program from the LiquidCrystal library. The only modifications made were to the pin assignments;
LiquidCrystal lcd(4, 17, 30, 29, 28, 27);
and define it as a 20x4 LCD
lcd.begin(20, 4);
So first step accomplished: the Sanguinololu talking to an LCD Screen.
Next I messed around with some of the examples shown on the Arduino rotary encoder page and ended up with a bit of a hybrid one that allows you to move the cursor around the screen with the encoder, with an arrow to show which way its going. Clicking the switch on the encoder resets it to the middle.
![]() |
| Left |
![]() |
| Right |
Working with Marlin
Using the modifications on tommyc's blog as a starting point I checked and modified the Marlin Configuration.h, Configuration_adv.h and pins.h as shown below:
Configuration.h
Line 34:
#define MOTHERBOARD 62
Line 190-205:
#define EEPROM_SETTINGS
//to disable EEPROM Serial.....
// please keep turned on if you can.
#define EEPROM_CHITCHAT
//LCD and SD support
//#define ULTRA_LCD //general lcd support, also 16x2
//#define SDSUPPORT // Enable SD Card Support in Hardware Console
#define ULTIPANEL
#ifdef ULTIPANEL
#define NEWPANEL //enable this if you have a clicencoder panel
#define SDSUPPORT
#define ULTRA_LCD
#define LCD_WIDTH 20
#define LCD_HEIGHT 4
//to disable EEPROM Serial.....
// please keep turned on if you can.
#define EEPROM_CHITCHAT
//LCD and SD support
//#define ULTRA_LCD //general lcd support, also 16x2
//#define SDSUPPORT // Enable SD Card Support in Hardware Console
#define ULTIPANEL
#ifdef ULTIPANEL
#define NEWPANEL //enable this if you have a clicencoder panel
#define SDSUPPORT
#define ULTRA_LCD
#define LCD_WIDTH 20
#define LCD_HEIGHT 4
Configuration_adv.h
Line 163:
//#define SDCARDDETECTINVERTED
pins.h, making sure to be within the sanguinololu pin definition part of the file. For my pins.h this was lines 557 - 657. I added the following 34 lines, copied from the RAMPS section of the pins.h
#ifdef ULTRA_LCD
#ifdef NEWPANEL
//we have no buzzer installed
#define BEEPER -1
//LCD Pins
#define LCD_PINS_RS 4
#define LCD_PINS_ENABLE 17
#define LCD_PINS_D4 30
#define LCD_PINS_D5 29
#define LCD_PINS_D6 28
#define LCD_PINS_D7 27
//The encoder and click button
#define BTN_EN1 10 //must be a hardware interrupt pin
#define BTN_EN2 11 //must be hardware interrupt pin
#define BTN_ENC 16 //the switch
//not connected to a pin
#define SDCARDDETECT -1
//from the same bit in the RAMPS Newpanel define
//encoder rotation values
#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1
#define BLEN_C 2
#define BLEN_B 1
#define BLEN_A 0
#endif //Newpanel
#endif //Ultipanel
#ifdef NEWPANEL
//we have no buzzer installed
#define BEEPER -1
//LCD Pins
#define LCD_PINS_RS 4
#define LCD_PINS_ENABLE 17
#define LCD_PINS_D4 30
#define LCD_PINS_D5 29
#define LCD_PINS_D6 28
#define LCD_PINS_D7 27
//The encoder and click button
#define BTN_EN1 10 //must be a hardware interrupt pin
#define BTN_EN2 11 //must be hardware interrupt pin
#define BTN_ENC 16 //the switch
//not connected to a pin
#define SDCARDDETECT -1
//from the same bit in the RAMPS Newpanel define
//encoder rotation values
#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1
#define BLEN_C 2
#define BLEN_B 1
#define BLEN_A 0
#endif //Newpanel
#endif //Ultipanel
Once these changes had been made, Marlin compiled to be 80k+ so definitely too big to go on the 644P. After upload the Printer status display came up:
And rotary encoder worked fine to navigate the menu system...
I selected a random GCODE file from the SD card and started printing it (or rather the Sanguinololu controller started processing the GCODE, its not connected to anything other than a 5k pot to simulate the hotend thermistor)
Once the printing starts you can use the encoder to "tune" the speed of the printer, its currently set to 200% below:
The pseudo print continued without issues. The next step will be to tidy up the wiring and get it connected up to a live printer!






GLad to see this work going on. Let me know when you have an LCD working Sanguinololu and I"ll probably order it. Do you know if Marlin will work with Sanguinololu 1.1? That is what I have. I just ordered a 1284p from you guys in anticipation.
ReplyDeleteI don't have a Sanguinololu 1.1 but Marlin should work. As for the LCD screen + click encoder, that will also work however the 1.1 has a slightly different expansion header. the different header will mean wiring the connector we intend supplying with our kits in a slightly different way.
DeleteI have just finished the same project (Sanguinololu 1284P with Marlin 1) but I ended up using Lady Ada's LCD BackPack ( http://www.adafruit.com/products/292 )to save and extra 3 pins (for the fan and buzzer). With time you could actually run the LCD on the same SPI interface as the SD and save 6 pins but I run out of patience.
ReplyDeleteI also could not find the solution you got to with avrdude config file, so I went brute force and changed the resonator for a crystal and corresponding caps.
I also found out that the D12 (PWM) pin on the header (as you can see in the picture and in the board)is actually connected to D4.
Yeah I have been paying with I2C extensions for some time but nothing solid yet. I did not want to use an LCD backpack (played around with this one from hobbytronics http://www.hobbytronics.co.uk/i2clcd-backpack) because I felt (at the time) that if I went to I2C I wanted to have everything (click encoder, LCD, fans, buzzer etc) on the I2C bus so it was easily portable to RAMPS, Gen 7 etc.
DeleteAfter pouring a huge amount of time into developing an atmega328p based I2C extender I got frustrated with integration at a software level. I want to offload the UI to the 328P and use GCode to send commands to the main board - its a project on the back burner right now but I am interested in a common, open, bus - based, extension to reprap electronics that would allow me to add bits to a standard board cheaply. That way when we all change to something like a Smoothieboard (http://smoothieware.org/smoothieboard) or start printing with 3 or more colours then the upgrade path should be easy.
As far as the D4/D12 pin is concerned its labelling error on the board, I relied heavily on the Sanguinololu schematic which is labelled correctly.
I actually left the hardware SPI for the SD reader and implemented a software SPI for the LCD (no need for MISO for the LCD). I tried to get both on the same bus but I am not that versed nor patient. The PINS.H relevant section looks like this:
ReplyDelete#define SDSS 26
#define SDCARDDETECT 17
#define LCD_PINS_DATA 28
#define LCD_PINS_CLOCK 27
#define LCD_PINS_LATCH 25
#define BTN_EN1 10
#define BTN_EN2 11
#define BTN_ENC 16 //the click
I have also encountered problems getting the fan to work on pin D29. It stops all Z movement when it goes high.
By the way thank you very much for posting your implementation. It is really helpful, well presented and would have saved me days of trials getting the boards to communicate.
is it possible to asign a Fan to the board aswell or are all free pins used by the LCD and SDCard
ReplyDeleteThe way I describe above uses all the free pins from the ATmega. Bluemetal's method (in previous comments) using an 12C LCD backpack leaves you with more free pins - enough to have a fan and a few spares.
ReplyDeleteThanks a lot!!! I spent many hours to understand compile problem. And now with your description its compiled well!!!
ReplyDeleteThank you!