Sunday, 20 January 2013

Huxley #710 - I2C Panelolu Test...

Sanguinololu Huxley #710 connection to I2C And Panelolu 2
I received the Microchip MCP23017 I²C I/O Expander parts this week and put one on a prototype board to test out with the Sanguinololu hardware on Huxley #710. This implementation is intended to be compatible with the Panelolu I²C update.

The intended configuration consists of the MCP23017 connected to a parallel LCD display device based on the Hitachi HD44780 device.  The MCP23017 device has an I²C connection (I2C) which can control 16 input / output lines. The input / output line direction can be configured independently.  There is an interrupt feature, where the chip monitors configured input lines and generate an interrupt when a change occurs. Useful, as the CPU can get on with other things and respond to an interrupt when it feels like it, without having to poll pins configured as inputs.

Using the I2C rather than a 4 bit parallel connection, releases I/O pins on the Sanguinololu board for things such as multiple extruder heads! Additionally more hardware can be tacked on the end of the I2C channel, less wires are needed and they can be screened more easily.

You can see my previous implementation using a more constrained I2C device here

Huxley #710 Microchip I2C Panelolu Test
Although there is quite a thick ribbon cable running to the prototype board, only 4 wires in use!
The lead was recovered from an old personal computer and I use it for prototyping connections as it saves me making up cables until the project is stable. You can just see the connections from the ribbon cable at the back of the ribbon connection to the prototyping board.

There are two connections for the I2C (Yellow and White) and 5v power supply (Red and Blue) to the power strip at the rear of the prototype board. The LCD connections are 4 bits for the communication, 3 bits for RS,RW and E of the HD44780 compatible display unit.

Microchip I²C I/O Expander

Huxley #710 Sanguinololu Rev 1.3a PCB
Connections To EXT Connector

Reset - later

The resistor (10kΩ) shown connected to the Microchip MCP23017 part is connected to the MCP23017 reset line to make sure that the reset line is not floating. The reset line could be tied to the reset on the expansion socket of the Sanguinolou board, but for the moment I thought I would do without it for testing.

The connector being used is the EXT connector which is the 14 way connector next to the ISP/SPI port connection used to program an Atmel device or connect an SPI device such as the SD card.
Huxley #710 Sanguinololu Rev 1.3a PCB Expansion connectors

On the Huxley machines the SD card connects to the ISP/SPI port and two pins on the EXT connection. One of the pins is not used (SCL/D16). The other pin, A0 pin acts as the device select line for the SD card. In principle more SPI devices can be added to the interface. Each requiring a device select line (more on that later). When the final display unit is implemented this pin will be used together with the SDA/D17 line.
Sanguinololu Rev 1.2 PCB Render

To test out the connections to the MCP23017  I used a small piece of software called I2C_scanner. It's really cool because it does not use any third party libraries and reports any device hanging off the I2C bus. You can find it here in the Arduino Playground.

I compiled this and downloaded it onto Huxley #710 to determine if the I2C device could be seen by the ATMega part on the EXT connection. The program scans all the I2C addresses from 0 to 127 and writes what if finds to the serial port, which you can monitor using the Serial Monitor (Ctrl+Shift+M key combination) in the Arduino software. I am now on 1.0.3 of Arduino by the way. You can see the output on the terminal screen shows that a device is present at address 0x20 which is the correct address for the MCP23017 with all the address lines held at 0v.

I2C Scanner output screen on the terminal
The output from the I2C scanner software on the serial terminal monitor in the Arduino software is very plain, but when you are hooking things up you don't want bells and whistles!

Having verified the hooked up Microchip I2C device, I connected the display to the I2C device and get the library working that Tony has selected for use with the I2C Panelolu device.

Testing with the LiquidTW2 Library
Testing with the LiquidTWI2 library next using the sample programme I had changed the code so that it would intialise the MCP23017 in the setup routine initially, I had issues compiling the Hello_i2C_LCD.ino sample programme. My code fragment looked like this:
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI2 lcd(0x20);  // SC All MCP23017 address lines pulled to 0V

void setup() {
// set the LCD type
// lcd.setMCPType(LTI_TYPE_MCP23008);
// set up the LCD's number of rows and columns:
lcd.begin(20, 4); // I have a 20 character by 4 line display
// Print a message to the LCD.
lcd.print("hello, world!");

This gave rise to the error shown below:
Hello_i2C_LCD.ino: In function 'void setup()':
Hello_i2C_LCD:26: error: 'class LiquidTWI2' has no member named 'setMCPType'

The error seemed to be with the definition of setMCPType however following an exchange with Lincomatic on GitHub who indicated that the setMCPType only needs calling if both devices are used. So using the following in the Hello_i2C_LCD example:

// lcd.setMCPType(LTI_TYPE_MCP23008);
// lcd.setMCPType(LTI_TYPE_MCP23017);

With both setMCPType lines commented out, the code compiled and downloaded successfully running the display as expected.

Latest news - an update library has been released (20 Jan 2012) which allows the definition to be retained as shown in the code shown above handling the issues internally. So I imagine either way will work now.

Next stop, integrate all this into Marlin - configure, design a custom panel and have fun...

I2C - LCD Test connection to Huxley #710

No comments:

Post a Comment