Platformio sketch

Hello everyone, I have an old sketch that works only on old versions of arduino. I would like it to work on: Platformio, unfortunately, when I upload it, errors pop up.

#include <Wire.h>
#include "Adafruit_MCP23017.h"
 
 
//Adafruit_MCP23017 *mcp[8]; 
Adafruit_MCP23017 mcp;
Adafruit_MCP23017 mcp2;
Adafruit_MCP23017 mcp3;
Adafruit_MCP23017 mcp4;
Adafruit_MCP23017 mcp5;
Adafruit_MCP23017 mcp6;
Adafruit_MCP23017 mcp7;
Adafruit_MCP23017 mcp8;
 
unsigned long previousMillis = 0;        // will store last time was updated
const long intervalMilis = 500;           // interval at which to blink (milliseconds)
 
byte pressTable[128][1];
 
void setup() { 
 
  Wire.begin();
   
  Serial.begin(9600);
  while (!Serial);            
  Serial.println("\nI2C Scanner");
  i2cscanner();
    
  mcp.begin(0);
  mcp2.begin(1);
  mcp3.begin(2);
  mcp4.begin(3);
  mcp5.begin(4);
  mcp6.begin(5);
  mcp7.begin(6);
  mcp8.begin(7);
 
  byte i=0;
 
  for(i=0;i<=15;i++){
    mcp.pinMode(i, INPUT);
    mcp.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp2.pinMode(i, INPUT);
    mcp2.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp3.pinMode(i, INPUT);
    mcp3.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp4.pinMode(i, INPUT);
    mcp4.pullUp(i, HIGH);
  }
 
   for(i=0;i<=15;i++){
    mcp5.pinMode(i, INPUT);
    mcp5.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp6.pinMode(i, INPUT);
    mcp6.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp7.pinMode(i, INPUT);
    mcp7.pullUp(i, HIGH);
  }
 
  for(i=0;i<=15;i++){
    mcp8.pinMode(i, INPUT);
    mcp8.pullUp(i, HIGH);
  }
 
  delay(1000);
}
 
void loop() {
 
  byte in;
  byte i;
    
  for(i=0;i<16;i++){
    in = mcp.digitalRead(i);
    if(in == 0){
      pressTable[i][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp2.digitalRead(i);
    if(in == 0){
      pressTable[i+16][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp3.digitalRead(i);
    if(in == 0){
      pressTable[i+32][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp4.digitalRead(i);
    if(in == 0){
      pressTable[i+48][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp5.digitalRead(i);
    if(in == 0){
      pressTable[i+64][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp6.digitalRead(i);
    if(in == 0){
      pressTable[i+80][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp7.digitalRead(i);
    if(in == 0){
      pressTable[i+96][0] = 1;  
    }
  }
 
  for(i=0;i<16;i++){
    in = mcp8.digitalRead(i);
    if(in == 0){
      pressTable[i+112][0] = 1;  
    }
  }
  
    unsigned long currentMillis = millis();
 
     
        
  if (currentMillis - previousMillis >= intervalMilis) {       
    for(i=0;i<129;i++){
      if(pressTable[i][0] == 1){
        Serial.print("Press MCP: ");
        Serial.println(i);   
      }
    }
    resetTable();
    previousMillis = currentMillis; 
  }
 
    
}
 
void resetTable(){
  byte i;
  for(i=0;i<129;i++){
    pressTable[i][0] = 0;
  }
}
 
void i2cscanner() {
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
}

Let me unpack my telescope, to see the error on your screen…

1 Like

You are copy-pasting your original .ino sketch as a .cpp file, but didn’t do the INO to CPP conversion.

So you have to predeclare

void resetTable();
void i2cscanner();

at the top of the file. Plus of course the library giving you Adafruit_MCP23017.h has to be declared in the platformio.ini like the documentation says.

lib_deps =
   adafruit/Adafruit MCP23017 Arduino Library@^2.3.0

[quote=“maxgerhardt, post:3, topic:31688”]

lib_deps =
   adafruit/Adafruit MCP23017 Arduino Library@^2.3.0

[/quote

still throws errors, I must be doing something wrong

Please show the exact errors when building / uploading the project.

I can’t change what you said. Could you change it in the code

I didn’t ask you to change something, I asked you to show a screenshot or the error message that you’re getting.