hI! I am using an arduino and a microchip MCP23008 to test how fast an I2C communcation can be. To see that I am controlling a LED. The LED blinks for some time and then it stays on. After some time blinks again and stays on. So it keeps doint that. My intention is to blink nonstop. The other problem is that thic microchip is 400kHz. When I set the delay in 20 miliseconds or 10 is not able to handle. #include <Wire.h>
// I2C address of the MCP23008 #define MCP23008_ADDRESS 0x20
void setup() {
// Start the I2C communication
Wire.begin();
// Set I2C clock speed to 400kHz
Wire.setClock(400000);
// Set all pins to output (IODIR register to 0x00)
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(IODIR);
Wire.write(0x00); // All pins as outputs
Wire.endTransmission();
// Turn off all pins initially (OLAT register to 0x00)
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x00); // All pins low
Wire.endTransmission();
}
void loop() {
// Turn on the LED connected to pin 0
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x01); // Set pin 0 high
Wire.endTransmission();
// Wait for 10 milliseconds
delay(10);
// Turn off the LED connected to pin 0
Wire.beginTransmission(MCP23008_ADDRESS);
Wire.write(OLAT);
Wire.write(0x00); // Set pin 0 low
Wire.endTransmission();
// Wait for 10 milliseconds
delay(10);
} What could be the problem?
Can you tell more ?
Can you show a photo with all the wires ? Which Arduino board do you use ? Do you have pullup resistors ? Do you have a MCP23008 module or just the chip ? On a breadboard ? without decoupling capacitors ? There are many things that can go wrong.
What happens at 100kHz, I suppose it will work better.
Can you set the delays to 100ms, to see the led blinking.
Breadboards can have bad contacts. The on and off switching of the led might cause noise which gets somehow to the I2C bus. That is just a guess, but I'm thinking in that direction.
A schematic or a photo will help us to see if the GND wire is connected properly.
I moved your topic to an appropriate forum category @albionqovanaj.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.