Problem with adding MCP23017 code to existing program

Hi all,

A few years ago I created a code to use multiple relays on a Arduino Mega. I did this with help from some very nice guys on the forum.

I haven't had to change the code until now. I need to add more relays and found a IO Expander board which I was hoping would do it for me. I've tried everything with my very limited coding knowledge, but just can not get it working.

The Expander is supposed to use the wire.h and Adafruit_MCP23017.h libraries, according to research that I've done. But I'm either not getting the code right, or my connections are incorrect, I think it's the code.

I've tried to change the digitalWrites to mcp.digitalWrite, I've tried the wire.Write way, but nothing so far is working. Cant even get any of the relays to react...

Does anyone have an idea of how I can add these extra relays please?

I tried to add the code, but it causes the port to exceed the maximum number of characters, will add the code in a following post.

Thanks a lot

I've taken out the screen section, keypad section and a few other things that I don't think have to do with what I need. (Did this so that the code would fit into the post)

// Codes
#include <UTFT.h>
#include <Keypad.h>

// TFT and Fonts
UTFT myGLCD(CTE32HR, 38, 39, 40, 41);
extern uint8_t BigFont[];
extern uint8_t Grotesk32x64[];

// Keypad
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Four columns
char keys[ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int InputNumber;
int pressedKeyCount = 0;

// Serial Number, change for each new unit
int serialNum = 4001;  // 1xxx for 8 relay, 2xxx for 4 relay, 3xxx for 2 relay, 4xxx FOR 16 relay, 

//Blowers
const byte Machine1 = A0; // I/O pin connected by the first relay
const byte Machine2 = A1;
const byte Machine3 = A2;
const byte Machine4 = A3;
const byte Machine5 = A4;
const byte Machine6 = A5;
const byte Machine7 = A6;
const byte Machine8 = A7;
const byte Machine9 = A8;
const byte Machine10 = A9;
const byte Machine11 = A10;
const byte Machine12 = A11;
const byte Machine13 = A12;
const byte Machine14 = A13;
const byte Machine15 = A14;
const byte Machine16 = A15;

typedef struct
{
  byte Pin;
  unsigned long StartedTime;
} Blower;
Blower Blowers[] = {
  { Machine1, 0 },
  { Machine2, 0 },
  { Machine3, 0 },
  { Machine4, 0 },
  { Machine5, 0 },
  { Machine6, 0 },
  { Machine7, 0 },
  { Machine8, 0 },
  { Machine9, 0 },
  { Machine10, 0 },
  { Machine11, 0 },
  { Machine12, 0 },
  { Machine13, 0 },
  { Machine14, 0 },
  { Machine15, 0 },
  { Machine16, 0 }
};
byte BlowerCount = (sizeof Blowers) / (sizeof Blowers[0]);
unsigned long BlowerStartTime;
byte CurrentBlower = 0;
int onTime = 8 ; // seconds on
int offTime = 1 ; // seconds off
unsigned long blows = 0;
unsigned long activeDays = 0;
unsigned long activeHours = 0;
unsigned long powderUsed = 0;


//Display modes
enum DisplayMode { TitleMode, SetOffTimeMode, SetOnTimeMode, ExamplesMode};
DisplayMode CurrentMode = TitleMode;

void setup()
{
  for (int i = 0; i < BlowerCount; i++)
  {
    pinMode(Blowers[i].Pin, OUTPUT);
    digitalWrite(A0,HIGH);
    digitalWrite(A1,HIGH);
    digitalWrite(A2,HIGH);
    digitalWrite(A3,HIGH);
    digitalWrite(A4,HIGH);
    digitalWrite(A5,HIGH);
    digitalWrite(A6,HIGH);
    digitalWrite(A7,HIGH);
    digitalWrite(A8,HIGH);
    digitalWrite(A9,HIGH);
    digitalWrite(A10,HIGH);
    digitalWrite(A11,HIGH);
    digitalWrite(A12,HIGH);
    digitalWrite(A13,HIGH);
    digitalWrite(A14,HIGH);
    digitalWrite(A15,HIGH);
  }

void loop() {
  ManageBlowers();
  int activeDs = millis() / 86400000UL;
  int activeHrs = millis() / 3600000UL;
  activeDays = activeDs;
  activeHours = activeHrs;
  int powderUse = blows * 50 / 1000;
  powderUsed = powderUse;
  char key = keypad.getKey();
  //  Serial.println(activeDs);
  //  Serial.println(activeHours);
  //  Serial.println(blows);
}
void ManageBlowers() {
if (millis() - BlowerStartTime > offTime * 1000UL)
    {
    StartBlower(CurrentBlower);
    CurrentBlower++;
    if (CurrentBlower >= BlowerCount)
      CurrentBlower=0;
    }
for (int i = 0; i < BlowerCount;i++)
  {
  if(millis()-Blowers[i].StartedTime > onTime * 1000UL)
    {
    StopBlower(i);
    }
  }
}

void StopBlower(int BlowerIndex)
{
digitalWrite(Blowers[BlowerIndex].Pin, HIGH);
}

void StartBlower(int BlowerIndex)
{
    digitalWrite(Blowers[BlowerIndex].Pin, LOW);
  blows ++;
  BlowerStartTime=Blowers[BlowerIndex].StartedTime = millis();
  myGLCD.setColor(VGA_WHITE);
  myGLCD.print((char*)"LAST APPLICATOR TO BLOW", CENTER, 239);
  myGLCD.setFont(Grotesk32x64);
  myGLCD.setColor(VGA_RED);
  myGLCD.print((char*)"'", 192, 255);
  myGLCD.print((char*)"'", 256, 255);
  myGLCD.printNumI(BlowerIndex + 1, CENTER, 255);
  myGLCD.setFont(BigFont);
}