Close

ATmega1284P, Marlin and I2C

I bought a few items from RS on a visit to their Hounslow branch and revived my account that had been dormant for nearly 10 years!

JST 2mm pitch 6 way connectors for running new wires to my Steppers (50 pack for £3.30)
Crimp Contact Pins for the connectors (50 pack for £1.60)
ATmega1284P-PU Microcontroller (£4.55 each)
Nylon Screw Insulator Rail bushings for my cast Prusa parts (50 pack for £3.67)

Not all parts were in stock at that branch, so I arranged for out of stock parts to be posted to me (one of the perks of an RS account is that the postage is free).

RS are often not the cheapest, but they do have hard to locate parts, like the JST connectors, and I do not need to worry about building a large order to offset postage costs of places like Rapid or Farnell.

The ATmega1284P from RS is half the price of the cheapest one I can find anywhere else – cheapest I can find is on Ebay for £7.99 with £1.20 postage.

I replaced the ATmega644P chip on my breadboard with the new 1284P chip, updated the settings in Arduino for “Mighty” and burned the bootloader and then uploaded the latest version of Marlin that actually compiles with a current version of Arduino (1.0 or 1.0.1) – all good so far.

Dowloaded the LiquidCrystal_I2C library and put the files in the relevant Arduino directory, then started splicing it into Marlin, very little to it as it happens – every file that has a reference for LiquidCrystal just needs to have an equivalent one for LiquidCrystal_I2C added.

Configuration.h

change
//LCD and SD support (Manual definitions if not using ULTIPANEL)
#define ULTRA_LCD  //general lcd support, also 16×2

to
//LCD and SD support (Manual definitions if not using ULTIPANEL)
#define I2C_LCD 0x27  // I2C LCD Panel (overrides the LiquidCrystal library with LiquidCrystal_I2C) – value is I2C Address for LCD
#define ULTRA_LCD  //general lcd support, also 16×2

ultralcd.h

change
#include <LiquidCrystal.h>

to
#ifdef I2C_LCD
  #include <LiquidCrystal_I2C.h>
#else
  #include <LiquidCrystal.h>
#endif

and
extern LiquidCrystal lcd;

to
#ifdef I2C_LCD
  extern LiquidCrystal_I2C lcd;
#else
  extern LiquidCrystal lcd;
#endif

ultralcd.ino

change
#include <LiquidCrystal.h>

to
#ifdef I2C_LCD
  #include <LiquidCrystal_I2C.h>
#else
  #include <LiquidCrystal.h>
#endif

and
LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7

to
#ifdef I2C_LCD
  LiquidCrystal_I2C lcd(I2C_LCD, LCD_WIDTH, LCD_HEIGHT);
#else
  LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7);  //RS,Enable,D4,D5,D6,D7
#endif

Then re-compile and upload to the bigger ATmega1284P chip.

Everything worked fine, except that when I connect to the chip from Printrun, the printer no longer comes online.

Now this could be because I don’t actually have a connection to an I2C chip or LCD display at this moment in time, I will have to wait until I have one to prove one way or the other.

I have a bunch of 8 bit I2C Expander chips on order (10 x PCF8574 for £3.71) but they seem to be lost in the post at present, looks like I will need to have the Ebay vendor resend them.

An alternative, but slightly more expensive option is an I2C LCD interface board.

These can be had on Ebay for as little as £2.44 each, I can wire my own for about £0.70 with the chips mentioned previously (37p for the I2C expander, 3p for the transistor, 25p for the potentiometer and a few more pennies for the pin headers and some perf board).

The main benefit of using the I2C version is that only 2 pins, SCL (D16) and SDA (D17) are required, along with a 5V and GND, and these can be spliced from any existing supply pins, compared with 6 dedicated pins for running the LCD directly.

In addition, any other I2C devices can be added with no extra pins being required as it is a bus based technology.

A unique address for each I2C device, which can be set by choosing which of the 3 Address pins are connected to 5V on the 8 bit I2C Expander:

Address pins A0, A1 and A2 make up the last 3 bits of a 7 bit binary number, so the available range is from 0100000 (32 decimal or 0x20 hex) – 0100111 (39 decimal or 0x27 hex).

Typical connectivity to an LCD panel as follows (image from Pavel Bansky’s website):

I don’t have any BC548B NPN transistors, plus they are end of life anyway, however I do have a C945 which should be a close enough substitute, but since this is only really for adjusting brightness I will probably just connect it to either a resistor or a potentiometer and adjust manually.
I also ordered some stepstick A4983 units from Ebay, these ones do 1/16 microstepping and are only £4.43 each, so nearly half the price of the previous ones I bought from Denmark and free shipping from China.

4 thoughts on “ATmega1284P, Marlin and I2C

Leave a Reply