{"id":40,"date":"2012-10-07T17:54:00","date_gmt":"2012-10-07T16:54:00","guid":{"rendered":"https:\/\/blog.hslracing.com\/3dprinters\/2012\/10\/07\/atmega1284p-marlin-and-i2c\/"},"modified":"2012-10-07T17:54:00","modified_gmt":"2012-10-07T16:54:00","slug":"marlin-and-atmega1284p-and-i2c","status":"publish","type":"post","link":"https:\/\/blog.hslracing.com\/3dprinters\/2012\/10\/marlin-and-atmega1284p-and-i2c.html","title":{"rendered":"ATmega1284P, Marlin and I2C"},"content":{"rendered":"<p>I bought a few items from <a href=\"http:\/\/uk.rs-online.com\/web\/\">RS<\/a>&nbsp;on a visit to their Hounslow branch and revived my account that had been dormant for nearly 10 years!<\/p>\n<p><a href=\"http:\/\/uk.rs-online.com\/web\/p\/products\/3531349\/\">JST 2mm pitch 6 way connectors<\/a>&nbsp;for running new wires to my Steppers (50 pack for \u00a33.30)<br \/><a href=\"http:\/\/uk.rs-online.com\/web\/p\/accessories\/3531276\">Crimp Contact Pins<\/a> for the connectors (50 pack for \u00a31.60)<br \/><a href=\"http:\/\/uk.rs-online.com\/web\/p\/microcontrollers\/7193932\">ATmega1284P-PU<\/a>&nbsp;Microcontroller (\u00a34.55 each)<br \/><a href=\"http:\/\/uk.rs-online.com\/web\/p\/screw-insulators\/0178894\">Nylon Screw Insulator<\/a>&nbsp;Rail bushings for my cast Prusa parts (50 pack for \u00a33.67)<\/p>\n<p>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&nbsp;<a href=\"http:\/\/uk.rs-online.com\/web\/\">RS<\/a>&nbsp;account is that the postage is free).<\/p>\n<p><a href=\"http:\/\/uk.rs-online.com\/web\/\">RS<\/a>&nbsp;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 <a href=\"http:\/\/www.rapidonline.com\/\">Rapid<\/a> or <a href=\"http:\/\/uk.farnell.com\/\">Farnell<\/a>.<\/p>\n<p>The ATmega1284P from&nbsp;<a href=\"http:\/\/uk.rs-online.com\/web\/\">RS<\/a>&nbsp;is half the price of the cheapest one I can find anywhere else &#8211; cheapest I can find is on&nbsp;<a href=\"http:\/\/www.ebay.co.uk\/\">Ebay<\/a>&nbsp;for \u00a37.99 with \u00a31.20 postage.<\/p>\n<p>I replaced the ATmega644P chip on my breadboard with the new 1284P chip, updated the settings in <a href=\"http:\/\/arduino.cc\/\">Arduino<\/a> for &#8220;Mighty&#8221; and burned the bootloader and then uploaded the latest version of&nbsp;<a href=\"http:\/\/reprap.org\/wiki\/Marlin\">Marlin<\/a>&nbsp;that actually compiles with a current version of&nbsp;<a href=\"http:\/\/arduino.cc\/\">Arduino<\/a>&nbsp;(1.0 or 1.0.1)&nbsp;&#8211; all good so far.<\/p>\n<p>Dowloaded the <a href=\"http:\/\/hmario.home.xs4all.nl\/arduino\/LiquidCrystal_I2C\/\">LiquidCrystal_I2C<\/a>&nbsp;library and put the files in the relevant&nbsp;<a href=\"http:\/\/arduino.cc\/\">Arduino&nbsp;<\/a>directory, then&nbsp;started splicing it into <a href=\"http:\/\/reprap.org\/wiki\/Marlin\">Marlin<\/a>, very little to it as it happens &#8211; every file that has a reference for LiquidCrystal just needs to have an equivalent one for LiquidCrystal_I2C added.<\/p>\n<p><u>Configuration.h<\/u><\/p>\n<p>change<br \/>\/\/LCD and SD support (Manual definitions if not using ULTIPANEL)<br \/>#define ULTRA_LCD &nbsp;\/\/general lcd support, also 16&#215;2<\/p>\n<div><\/div>\n<div>to<\/div>\n<div>\n<div>\/\/LCD and SD support (Manual definitions if not using ULTIPANEL)<\/div>\n<div>#define I2C_LCD 0x27 &nbsp;\/\/ I2C LCD Panel (overrides the LiquidCrystal library with LiquidCrystal_I2C) &#8211; value is I2C Address for LCD<\/div>\n<div>#define ULTRA_LCD &nbsp;\/\/general lcd support, also 16&#215;2<\/div>\n<\/div>\n<div><\/div>\n<p><u>ultralcd.h<\/u><\/p>\n<p>change<br \/>#include &lt;LiquidCrystal.h&gt;<\/p>\n<p>to<br \/>#ifdef I2C_LCD<br \/>&nbsp; #include &lt;LiquidCrystal_I2C.h&gt;<br \/>#else<br \/>&nbsp; #include &lt;LiquidCrystal.h&gt;<br \/>#endif<\/p>\n<p>and<br \/>extern LiquidCrystal lcd;<\/p>\n<p>to<br \/>#ifdef I2C_LCD<br \/>&nbsp; extern LiquidCrystal_I2C lcd;<br \/>#else<br \/>&nbsp; extern LiquidCrystal lcd;<br \/>#endif<\/p>\n<p><u>ultralcd.ino<\/u><\/p>\n<p>change<br \/>#include &lt;LiquidCrystal.h&gt;<\/p>\n<p>to<br \/>#ifdef I2C_LCD<br \/>&nbsp; #include &lt;LiquidCrystal_I2C.h&gt;<br \/>#else<br \/>&nbsp; #include &lt;LiquidCrystal.h&gt;<br \/>#endif<\/p>\n<p>and<br \/>LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); &nbsp;\/\/RS,Enable,D4,D5,D6,D7<\/p>\n<p>to<br \/>#ifdef I2C_LCD<br \/>&nbsp; LiquidCrystal_I2C lcd(I2C_LCD, LCD_WIDTH, LCD_HEIGHT);<br \/>#else<br \/>&nbsp; LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); &nbsp;\/\/RS,Enable,D4,D5,D6,D7<br \/>#endif<\/p>\n<p>Then re-compile and upload to the bigger ATmega1284P chip.<\/p>\n<p>Everything worked fine, except that when I connect to the chip from <a href=\"http:\/\/printrun\/\">Printrun<\/a>, the printer no longer comes online.<\/p>\n<p>Now this could be because I don&#8217;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.<\/p>\n<p>I have a bunch of <a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/PCF8574.pdf\">8 bit I2C Expander<\/a> chips on order (10 x PCF8574 for \u00a33.71) but they seem to be lost in the post at present, looks like I will need to have the <a href=\"http:\/\/www.ebay.co.uk\/\">Ebay<\/a> vendor resend them.<\/p>\n<p>An alternative, but slightly more expensive option is an I2C LCD interface board.<\/p>\n<div style=\"clear: both;text-align: center\"><a href=\"http:\/\/1.bp.blogspot.com\/-p-TELMbTBso\/UHGyPVeHbNI\/AAAAAAAAAU4\/7T-QW9B-1Mo\/s1600\/I2C+breakout.JPG\" style=\"margin-left: 1em;margin-right: 1em\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"320\" src=\"http:\/\/1.bp.blogspot.com\/-p-TELMbTBso\/UHGyPVeHbNI\/AAAAAAAAAU4\/7T-QW9B-1Mo\/s320\/I2C+breakout.JPG\" width=\"320\" \/><\/a><\/div>\n<p>These can be had on&nbsp;<a href=\"http:\/\/www.ebay.co.uk\/\">Ebay<\/a>&nbsp;for as little as \u00a32.44 each, I can wire my own for about \u00a30.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).<\/p>\n<p>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.<\/p>\n<p>In addition, any other I2C devices can be added with no extra pins being required as it is a bus based technology.<\/p>\n<p>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&nbsp;<a href=\"http:\/\/www.nxp.com\/documents\/data_sheet\/PCF8574.pdf\">8 bit I2C Expander<\/a>:<\/p>\n<p>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) &#8211; 0100111 (39 decimal or 0x27 hex).<\/p>\n<p>Typical connectivity to an LCD panel as follows (image from <a href=\"http:\/\/bansky.net\/blog\/2008\/10\/interfacing-lcd-using-i2c-port-extender\/\">Pavel Bansky&#8217;s<\/a> website):<\/p>\n<div style=\"clear: both;text-align: center\"><a href=\"http:\/\/4.bp.blogspot.com\/-z6S0OeGa4Z4\/UHKKo-p5v7I\/AAAAAAAAAVQ\/weX1ZXrjr5o\/s1600\/alphanumericLCD_I2C.png\" style=\"margin-left: 1em;margin-right: 1em\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" height=\"310\" src=\"http:\/\/4.bp.blogspot.com\/-z6S0OeGa4Z4\/UHKKo-p5v7I\/AAAAAAAAAVQ\/weX1ZXrjr5o\/s320\/alphanumericLCD_I2C.png\" width=\"320\" \/><\/a><\/div>\n<div style=\"clear: both;text-align: left\">I don&#8217;t have any <a href=\"http:\/\/uk.mouser.com\/ProductDetail\/Fairchild-Semiconductor\/BC548B\/?qs=sGAEpiMZZMsTKkj12KWLXuW5oDYpP%252bzxL5rpPNu0IkY%3D\">BC548B<\/a> NPN transistors, plus they are end of life anyway, however I do have a <a href=\"http:\/\/uk.mouser.com\/ProductDetail\/Fairchild-Semiconductor\/KSC945GTA\/?qs=sGAEpiMZZMvAvBNgSS9LqoiWbxgIB8sD\">C945<\/a>&nbsp;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.<\/div>\n<div style=\"clear: both;text-align: left\"><\/div>\n<div style=\"clear: both;text-align: left\">I also ordered some <a href=\"http:\/\/reprap.org\/wiki\/Stepstick\">stepstick<\/a> A4983 units from&nbsp;<a href=\"http:\/\/www.ebay.co.uk\/\">Ebay<\/a>, these ones do 1\/16 microstepping and are only \u00a34.43 each, so nearly half the price of the previous ones I bought from Denmark and free shipping from China.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I bought a few items from RS&nbsp;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&nbsp;for running new wires to my Steppers (50 pack for \u00a33.30)Crimp Contact Pins for the connectors (50 pack for \u00a31.60)ATmega1284P-PU&nbsp;Microcontroller (\u00a34.55 each)Nylon Screw Insulator&nbsp;Rail bushings&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":0,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hslracing.com\/3dprinters\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}