Modifying Nokia 5110 to work with MCP23017
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Modifying Nokia 5110 to work with MCP23017

by rahatmaini on Wed Apr 24, 2013 7:41 pm

After digging through some code, I found this in Adafruit's library:
Code: Select all | TOGGLE FULL SIZE
void Adafruit_PCD8544::begin(uint8_t contrast) {
  // set pin directions
  pinMode(_din, OUTPUT);
  pinMode(_sclk, OUTPUT);
  pinMode(_dc, OUTPUT);
  if (_rst > 0)
    pinMode(_rst, OUTPUT);
  if (_cs > 0)
    pinMode(_cs, OUTPUT);

  // toggle RST low to reset
  if (_rst > 0) {
    digitalWrite(_rst, LOW);
    digitalWrite(_rst, HIGH);

  clkport     = portOutputRegister(digitalPinToPort(_sclk));
  clkpinmask  = digitalPinToBitMask(_sclk);
  mosiport    = portOutputRegister(digitalPinToPort(_din));
  mosipinmask = digitalPinToBitMask(_din);
  csport    = portOutputRegister(digitalPinToPort(_cs));
  cspinmask = digitalPinToBitMask(_cs);
  dcport    = portOutputRegister(digitalPinToPort(_dc));
  dcpinmask = digitalPinToBitMask(_dc);

That isn't the whole function but I figured this was the most important part pertaining to the MCP23017. So I want to make a humble request to Adafruit to help all of us out in setting up the MCP to work with the Nokia, if this can be done, lots of people on this forum will be able to save 5 pins from their arduino!!! My current idea is to incorporate the MCP library into this one and replace pinMode() functions with mcp.pinMode(), but I know that is not all that needs to be done, as the bottom half of the code shows there is another cumbersome function, digitalPinToPort(), Please please help Adafruit and anyone else with the knowledge to help!!! I myself am working hard to figure this out if possible, and will post any results I find.

Thanks guys!

Posts: 176
Joined: Wed Aug 29, 2012 5:15 pm

Re: Modifying Nokia 5110 to work with MCP23017

by adafruit_support_mike on Thu Apr 25, 2013 9:15 am

What you're talking about is an I2C wrapper around an SPI interface. There are some inherent data rate problems in that.

First of all, you need to shift at least 16 bits through the I2C lines to change the state of the MCP23017's GPIO pins. Toggling an exported SPI clock pin HIGH then LOW again would take 32 ticks of the I2C clock. You can set the data pin in the same set of transactions, so that doesn't cost anything extra, but it's still a pretty serious slow-down.

To make matters worse, SPI is the fast protocol and I2C is the slow one. SPI can run at a few megahertz, but standard I2C runs at 100kHz. Fast I2C runs at 400kHz. Dividing that by a factor of 32 gives you a clock rate in the 3kHz-12kHz range for an SPI-over-I2C connection.

The 5110 is an 84x48 screen, so it has 4032 pixels. At 3kHz it would take a little more than a second to send one screen's worth of data. At 12kHz your refresh rate would max out at about 3fps.

There are probably situations where a screen that slow is acceptable, but it won't be an "export the screen I/O to a chip and everything runs just the same" kind of deal.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

Posts: 59421
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.