Hello. I have problem with 2 MCP23017
1x MCP23017 "mcp0" on GPA are connected ULN2803A, on output of ULN2803A leds with 10kR to VCC
1x MCP23017 "mcp1" on GPA are only leds with 10kR to VCC
Connections:
reset pin >10k > VCC
VCC > 100nF > GND
mcp0 0x20
GPA0 > ULN2803 > led1 blink on/off 1s
GPA1 > ULN2803 > led2 blink on/off 1s
GPA2 > ULN2803 > blink on/off 1s
GPA7 > ULN2803 > led4 on/off via button on GPB0
mcp1 0x21
GPA4 - led5 blink on/off 1s
GPA7 - led6 on/off via button on GPB0
On I2C I have also OLED SH1106 ; Tiny RTC .
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)
#include <Wire.h>
#include "Adafruit_MCP23017.h"
Adafruit_MCP23017 mcp0;
Adafruit_MCP23017 mcp1;
#include "RTClib.h"
RTC_DS1307 RTC;
#include <Adafruit_SH1106.h>
#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
void setup() {
Wire.begin();
RTC.begin();
mcp0.begin(0); //0x20
mcp1.begin(1); //0x21
mcp0.pinMode(0, OUTPUT);
mcp0.pinMode(1, OUTPUT);
mcp0.pinMode(2, OUTPUT);
mcp0.pinMode(7, OUTPUT);
mcp0.pinMode(8, INPUT);
mcp0.pullUp(8, HIGH);
mcp1.pinMode(4, OUTPUT);
mcp1.pinMode(7, OUTPUT);
mcp1.pinMode(8, INPUT);
mcp1.pullUp(8, HIGH);
Serial.begin(9600);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
display.display();
delay(1500);
display.clearDisplay();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
//delay(1000);
display.setTextSize(2);
display.setTextColor(WHITE, BLACK);
display.setCursor(20, 4);
display.print(now.hour(), DEC);
display.print(':');
display.print(now.minute(), DEC);
display.print(':');
display.print(now.second(), DEC);
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(35, 22);
display.print(now.year(), DEC);
display.print('/');
display.print(now.month(), DEC);
display.print('/');
display.print(now.day(), DEC);
display.display();
display.clearDisplay();
mcp0.digitalWrite(0, HIGH);
delay(100);
mcp0.digitalWrite(0, LOW);
mcp0.digitalWrite(1, HIGH);
delay(100);
mcp0.digitalWrite(1, LOW);
mcp0.digitalWrite(2, HIGH);
delay(100);
mcp0.digitalWrite(2, LOW);
mcp1.digitalWrite(4, HIGH);
delay(100);
mcp1.digitalWrite(4, LOW);
mcp1.digitalWrite(7, mcp1.digitalRead(8));
mcp0.digitalWrite(7, mcp0.digitalRead(8));
}
Problem:
- If switch on mcp0 is open:
- led 1;2;3 is blnking ok
- led 4 is always on with blinking (never off)
- If switch on mcp0 is close:
- led 1;2;3 is blinking ok
- led 4 is off
- If switch on mcp1 is open:
- led 5 is blinking ok
- led 6 is off
So all its ok
- If switch on mcp1 is close:
- led 5 is blinking with smaller power
- led 6 is always on with blinking like "1" with led 4
Whats its wrong? Software or hardware?
About mcp0 - I added ULN2803 because on outputs will be relays.
If I connect mcp0 to leds without ULN2803 situation is the same as I have wrote in "mcp1" with 3 and 4 step.
Regards
EDIT:
Problem solved I have added 2k2 to each leds, now works ok.
But I have question about code for RTC. Its all ok? I see thats code for RTC use delay, can it be changed to mills? I think that delay has negative effect for all software/program.