From 2a264c7dd6fef4b62fedb2ea45b4fb3dd0d74a29 Mon Sep 17 00:00:00 2001 From: telliottosceola Date: Mon, 22 May 2017 09:35:23 -0500 Subject: [PATCH] Updated initialization of PCA9536 in setup Updated to set all channels to 0/off prior to setting channels to outputs. By default on power up all channels are set to high so after channels are set to outputs they turn on, setting channels low prior to setting to outputs prevents relays from turning on after set to outputs. --- Particle/PCA9536_R21.ino | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Particle/PCA9536_R21.ino b/Particle/PCA9536_R21.ino index f8e2de4..9c90441 100755 --- a/Particle/PCA9536_R21.ino +++ b/Particle/PCA9536_R21.ino @@ -14,19 +14,22 @@ void setup() { // Set variable Particle.variable("i2cdevice", "PCA9536_R21"); - - // Initialise I2C communication - Wire.begin(); // Initialise Serial Communication, set baud rate = 9600 Serial.begin(9600); + // Initialise I²C communication + Wire.begin(); + + // Turn off all channels prior to initialization of chip so relays do not turn on after initializing channels to outputs. + Wire.beginTransmission(Addr); + Wire.write(0x01); + Wire.write(0x00); + Wire.endTransmission(); - // Start I2C transmission Wire.beginTransmission(Addr); // Select configuration register Wire.write(0x03); // Set all pins as OUTPUT Wire.write(0x00); - // Stop I2C transmission Wire.endTransmission(); delay(300); }