Hi,
I have begin tests with an ESP32 and a MCP23017
And this seem very too slow for my needs on my firsts basics tests on it ![]()
(the display of ONLY one RGB charlieplexed tower of 4x RGB leds that are turned at 90 degrees for each level to the next = 12 monochromatics leds)
Here is the code, I use :
#include <Wire.h>
#include <MCP23017.h>
#define I2C_SDA 21
#define I2C_SCL 22
hw_timer_t *My_timer = NULL;
int seconds = 0;
int frames = 0;
MCP23017 mcp;
void IRAM_ATTR timer_func()
{
seconds++;
Serial.print(seconds);
Serial.print(" seconds (");
Serial.print(frame);
Serial.println(" fps)");
frames=0;
}
void setup_timer()
{
seconds = 0;
My_timer = timerBegin(0, 80, true);
timerAttachInterrupt(My_timer, &timer_func, true);
timerAlarmWrite(My_timer, 1000000, true);
timerAlarmEnable(My_timer); //Just Enable
}
int search_i2c()
{
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");
delay(5000); // wait 5 seconds for next scan
return nDevices;
}
void setup_i2c(int sda = I2C_SDA, int scl = I2C_SCL)
{
int found = 0;
Wire.begin();
Serial.println("\nI2C Scanner");
while ( (found = search_i2c() ) == 0 )
{
Serial.println("I2C device not found \n");
delay(5000);
}
}
void mcp_reset()
{
// for ( int i = 0 ; i < 16 ; i++ )
for ( int i = 8 ; i < 12 ; i++ )
{
mcp.pinMode(i, INPUT);
}
}
void setup_mcp()
{
mcp.begin( 7 );
mcp_reset();
}
void mcp_set_pins(int low, int high)
{
mcp.pinMode(low, OUTPUT);
mcp.pinMode(high, OUTPUT);
mcp.digitalWrite(low, LOW);
mcp.digitalWrite(high, HIGH);
// delay(1);
}
void mcp_stage( int pin0, int pin1 )
{
/*
Serial.print("mcp_stage(");
Serial.print(pin0);
Serial.print(",");
Serial.print(pin1);
Serial.println(")");
*/
// mcp.digitalWrite(pin0, LOW);
// mcp.digitalWrite(pin1, HIGH);
mcp_reset();
mcp_set_pins( pin0, pin1);
}
void loop_mcp(int first)
{
int nextpin[4] = { 1, 2, 3, 0};
for ( int i = 0 ; i < 4 ; i++)
{
for ( int j = 0 ; j < 4 ; j++)
{
if( i != nextpin[j] )
{
mcp_stage(i + first, nextpin[j] + first);
}
}
// this seem needed to wait a little if we don't want a regular crash
delay(1);
}
}
void setup()
{
Serial.begin(115200);
setup_i2c();
setup_mcp();
setup_timer();
}
void loop()
{
// search_i2c();
loop_mcp( 8 );
frames++;
}
This give me only something between 11 and 12 refresh per second when I need something very more high like 50 or 100 Hz
I find 12 fps with the mcp_reset() call into mcp_stage() and 23 fps without
I find too 23 fps without tje mcp__set_pins(pin0, pin1)
And A VERY BIGGER frequency of refresh at 250 fps without mcp_reset() AND mcp_ set_pins() calls
(and I reset only 4 pins at the mcp_reset() call, not alls pins because in this case the fps is lowered to ONLY 4 fps ...)
It exist another MCP23017 package that is very more speed than the version that I have use from https://www.waveshare.com/wiki ?
(I use the mcp23017.h and . cpp files into the arduino directory of the MCP23017-IO-Expansion-Board-Demo-Code.7z archive)