Monday, August 26, 2013

I2C display and rotary encoder on Melzi

Recently, I built a Reprappro Huxley 3d-printer, and I wrote a summary about the build-process in this post. One of the modifications I have done on the printer is to add a display and a rotary encoder.

My 20x4 display and rotary encoder in a Panelolu casing

The very best solution to make a display work with the printer would be of the Reprappro version of Marlin could support I2C displays directly. However, it does not, and all my attempts to add the necessary display-code to their version failed. Thanks to the guide at Think3dPrint3d I managed to make the display and the rotary encoder work by using the T3P3-version of Marlin instead of the Reprappro version.

Display

I chose a simple I2C-display from dx.com (Deal Extreme). It comes with a PCA8574-compatible I2C-port expander. Luckily, the RA_CONTROL_PANEL, which is supported by the firmware, uses the same expander. All you have to do to make the dx.com display work is to define the RA_CONTROL_PANEL in Configuration.h in Marlin as such:


#define RA_CONTROL_PANEL

#if defined(RA_CONTROL_PANEL)
 #define ULTIPANEL
 #define NEWPANEL
 #define LCD_I2C_TYPE_PCA8574
 #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
#endif


It is pretty straightforward to connect the Display to Melzi:
  • GND connects to a free GND pin
  • VCC connects to a free VCC pin
  • SDA connects to SDA
  • SCL connects to SCL

Rotary Encoder

The rotary encoder I use is also from Deal Extreme. In order to make it work I had to define which pins to use in Pins.h. Look for the definitions for the Melzi-board (number 63) in the file.

//The encoder and click button
     #define BTN_EN1 11 
     #define BTN_EN2 10
     #define BTN_ENC 29

In addition i had to move the connection for the heated bed Mosfet to make the encoder work.

#define HEATER_BED_PIN     30 

I think, but I am not quite sure, that the rotary encoder must use Interrupt pins 10 and 11 in order to work. I tried different configurations without moving the heated bed connection, but the above is the only configuration which made sense (and worked).

To connect the rotary encoder to Melzi:
  • A connects to TX1
  • B connects to RX1
  • SW connects to A2
  • VCC connects to VCC
  • GND connects to GND
Thats it. The panelolu2-case is great by itself, but it is not superduper for the Huxley. If you find or create a display casing that fits above the Melzi board or fits the Huxley better, please spread the word below.




10 comments:

  1. i can't found any suport for RA_CONTROL_PANEL in T3P3-version version of marlin .What fimware you use?Premek

    ReplyDelete
    Replies
    1. Hi. RA_CONTROL_PANEL is defined in Erik Zalms version of Marlin.
      https://github.com/ErikZalm/Marlin
      My Firmware is a mix of T3P3 Marlin and some lines from the Erik Zalm version. It all depends on which i2C expander your display is using. If you have the Panelolu2 I2C encoder, all you need is T3P3. Which I2C encoder do you have?

      Delete
    2. thanks.i make it work with Erick Zalms version of Marlin and have to use LCD_I2C_SAINSMART_YWROBOT definebecouse i have diferent chip on that ic2 encoder.Thanks for help.Premek

      Delete
  2. please
    How do I configure the mapping LCD_I2C_TYPE_PCA8574?
    thank you

    ReplyDelete
    Replies
    1. Hi. I forgot to mention that. You need the file ultralcd_implementation_hitachi_HD44780.h from Eric Zalms version of Marlin. The definition is in there. Tell me your progress and I will update the blogpost for future reference.
      (https://github.com/ErikZalm/Marlin/blob/Marlin_v1/Marlin/ultralcd_implementation_hitachi_HD44780.h)

      Delete
    2. Thank you for the answer

      Plus I had already tried that library, and found How do I configure the mapping LCD_I2C_TYPE_PCA8574?
      The problem in reality is that I can not do the work with i2c LCD

      The LCD turns on and activates the buzzer, however nothing happens

      Observed with a oscilloscope is possible to see the operation of I2C

      Thank you for your help, have been of utmost importance your blog

      Delete
    3. I'm trying to do this operation with an gen7

      Delete
    4. Have you checked that the I2C address selected in the code is the one used by the chip? If you have a buzzer connected to the PCA8574 and it beeps on command, it should be correct, but I would have double checked this.

      Delete
  3. Thanks for getting me motivated to try this. I got the same rotary encoder and a similar display. I didn't wanted to move around printer parameters between firmwares so i gave the RepRapPro Source a try and i managed to get it to work... even if it took the whole weekend.

    https://github.com/ornotermes/Marlin
    http://slashhome.se/p/gallery/?g2_itemId=8385#g2

    ReplyDelete
    Replies
    1. Hi Rikard. I am glad you to hear that you made it work with the RepRapPro firmware. Your display-casing sure looks professional. Bra jobbat!

      Delete