I'm currently using an Arduino Nano 33 Iot, however, due to my project being large scale I would require more GPIO pins for output control of my LED lights. I have decided to use the PCF8574 expansion module and it will be connected to a npn transistor to control my relay, however, when I turn on/off my LED light (Arduino Things), the PCF8574 doesn't output the voltage and current to turn on my relay.
My code below:
bool lED;
bool lED2;
bool lED3;
bool lED4;
bool lED5;
#include "thingProperties.h"
#include <Wire.h>
int PCF_Output = 0x20;
byte PCF8574OUTPUT = B00000000; //sets a variable to be used for logic operator
void setup() {
// Initialize serial and wait for port to open:
Wire.begin();
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(9, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
Wire.beginTransmission(PCF_Output);
Wire.write(0x00);
Wire.endTransmission();
delay(1500); // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// int voltage_2 = analogRead(A1);
// core_2_Value = voltage_2 * (5.0/1024.0);
// delay(10);
}
void onLEDChange() {
Serial.println(lED);
if (lED) {
digitalWrite(A0, HIGH);
Wire.beginTransmission(PCF_Output);
Wire.write(0x01);
Wire.endTransmission();
delay(500);
}
else {
digitalWrite(A0, LOW);
Wire.beginTransmission(PCF_Output);
Wire.write(0x00);
Wire.endTransmission();
delay(500);
}
}
void onLED2Change() {
if (lED2){
digitalWrite(6,HIGH);
}else {
digitalWrite(6,LOW);
}
}
The onLEDChange() is linked to Core 1 LED variable in Things, by toggling the LED I would like my PCF8574 to turn either on and off when the LED is true and false respectively.