Hi,
i wanna control 4DC Motors and manage ther Speed by using each drive a 1203BB Module (H-Bridge dosent work with my drives).
To do that i uns a NodeMCU with ESP8266 and 2 of the PCF8574 IOExtender.
The PCF8574 are bit dificult to use for me and í need help.
For the drive controlers i need 4 ports of each Extender, thats why i have 2 of them.
No my Problem, i initilize the PCFs in my global code and use a own class to put the pin informations in it.
But i cant put a reference of the PCF object in the class.
If i try to put the PCF initialisation in myDrive class, i got address errors after first pin manipulation.
And if i init the PCF 4 times (for each drive controler) the pn manipulation works, but not correct because its bad to handle an i2c module in 2 obcets.
Does anyone have a idea to handel that ?
Example Code:
#include "PCF8574.h"
// Set i2c address
PCF8574 IOBank[2] = { 0x20, 0x21 };
class myDrive{
private:
public:
int Bank, POT_UC, POT_INC, PIN_OnOff, PIN_UpDwn;
String Direction;
myDrive() { }
myDrive( int arg1, int arg2, int arg3, int arg4, int arg5 )
{
Bank = arg1;
POT_UC = arg2;
POT_INC = arg3;
PIN_OnOff = arg4;
PIN_UpDwn = arg5;
}
};
myDrive DriveObj[5]{ {},
{ 0, 0, 1, 2, 3 }, // Drive 1: Bank0 , Pin 0-3
{ 0, 4, 5, 6, 7 }, // Drive 2: Bank0 , Pin 4-7
{ 1, 0, 1, 2, 3 }, // Drive 3: Bank1 , Pin 0-3
{ 1, 4, 5, 6, 7 } // Drive 4: Bank1 , Pin 4-7
};
void setup() {
Serial.begin(115200);
Serial.println("");
Serial.println("start Setup");
// PCF8574 init
int p;
for( p=0; p<=7; p++ )
{
IOBank[0].pinMode(p, OUTPUT);
IOBank[1].pinMode(p, OUTPUT);
}
IOBank[0].begin();
IOBank[1].begin();
// test once the direction Pins
int d;
for( d=1; d<=4; d++ )
{
Serial.print("\tDriveObj "); Serial.print(d); Serial.print(" PIN_OnOff: "); Serial.println(DriveObj[1].PIN_OnOff);
IOBank[DriveObj[d].Bank].digitalWrite( DriveObj[d].PIN_UpDwn, 1 );
delay(1000);
IOBank[DriveObj[d].Bank].digitalWrite( DriveObj[d].PIN_UpDwn, 0 );
delay(1000);
IOBank[DriveObj[d].Bank].digitalWrite( DriveObj[d].PIN_UpDwn, 1 );
}
Serial.println("Setup done");
}
void loop() {
}