mc23016 pin expander lots of leds weird behavior.

Hello,
I’m experimenting with the MC23016 pin expander and noticed something weird,
I made a sketch that turns a set of lets on 1 after the other, till they all burn.

Now what i notice is that, before any lets are on there is a faint glow coming from the leds?
any reason why this is?

Also when i connect a external power supply to the arduino (so it’s not power by USB but via a battery) all goes well till all leds burn, and then go pulse at a rate of about once a second.

here is my sketch:

  #include <IOexpander.h>
  #include <Wire.h>;
  #include <inttypes.h>;
  
  IOexpander IOexp;
  
  int controleled = 13;
  
  void setup(){
    //for debuggin purposes i start a serial.
    Serial.begin(9600);
    //initiaze contact with expander. and see if it's workin.
    if(IOexp.init(0x20, MCP23016))
    Serial.println("Communication with IOexpander works!");
    else
    Serial.println("No communication with the IOexpander!!");
    //set controleled as output.
    pinMode(controleled, OUTPUT);
    //setting array 0 pins on expander to output.
    IOexp.pinModePort(0, OUTPUT);
    //and second array (array 1) to input possibly to experiment.
    IOexp.pinModePort(1, INPUT);
    //looking if als is good :)
    digitalWrite(controleled, HIGH);
  
  }
  
  void loop(){
    int state = HIGH;
    int state1 = LOW;
    //for the sake of testing im gonna swith every led
    //on one at a time.
    IOexp.digitalWritePort(0, state1);
    delay(500);
    IOexp.digitalWrite(0,0, state);
    delay(500);
    IOexp.digitalWrite(0,1, state);
    delay(500);
    IOexp.digitalWrite(0,2, state);
    delay(500);
    IOexp.digitalWrite(0,3, state);
    delay(500);
    IOexp.digitalWrite(0,4, state);
    delay(500);
    IOexp.digitalWrite(0,5, state);
    delay(500);
    IOexp.digitalWrite(0,6, state);
    delay(500);
    IOexp.digitalWrite(0,7, state);
    delay(500);
    Serial.println("it was a succes!");
    
  }

I do not think that there is anything wrong with my sketch, but just to be sure.
I rather think that it is a Hardware problem :slight_smile:

Anny Ideas that would be great :slight_smile:

Add some decoupling, 0.1uF on the power lines to the chip is a mnimum. http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Also what value of resistor are you using with the LEDs and are you using the chip to source or sink the LED current.

220ohm per led, and got no decoupling i'll try that :) i didn't know it was really needed in circuit's that use a dc from battery or usb. only from outlet through rectifier, is what i thought :)

i didn't know it was really needed in circuit's that use a dc from battery

It is needed with a battery more than anything else. This is because the battery is quite a high impedance load. LEDs - Sourcing or sinking?

duality: I'm experimenting with the MC23016 pin expander and noticed something weird,

To help me answer, can you tell me please where you got the ioexpander library from? Then I can check what it is doing.

duality: Now what i notice is that, before any lets are on there is a faint glow coming from the leds? any reason why this is?

It would help to see your circuit here.

duality: Also when i connect a external power supply to the arduino (so it's not power by USB but via a battery) all goes well till all leds burn, and then go pulse at a rate of about once a second.

Sounds like it is resetting.

If you are having this problem when driving all 8 LEDs it sounds like it is drawing more current than it is designed to do.

According to the MCP23016 datasheet:

Maximum current sourced by combined PORTS ... 200 mA

Now depending on the exact LEDs and resistors you are using it is possible that you are exceeding that. Or possibly your battery is not up to supplying the current the LEDs are wanting.