Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for F32]-02 Read digital input ports state by 9555 chip
#1
Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
* - XL9555SS I2C Address: 0x24 for inputs 1-16, 0x26 for inputs 17-24, 0x27 for inputs 25-32
*/

#include "Arduino.h"
#include <Wire.h>
#include <PCA95x5.h>

// Define I2C pins
#define I2C_SDA 8  // Define SDA pin
#define I2C_SCL 18  // Define SCL pin

PCA9555 inputIO1; // Address 0x24, ports 0-15: DI1-16
PCA9555 inputIO2; // Address 0x26, ports 0-7: DI17-24
PCA9555 inputIO3; // Address 0x27, ports 0-7: DI25-32

void setup() {
    Serial.begin(115200);

    // Initialize I2C communication
    Wire.begin(I2C_SDA, I2C_SCL); // Initialize I2C with defined SDA and SCL pins

    // Configure the expanders for this standalone input test.
    inputIO1.attach(Wire, 0x24);
    inputIO1.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    inputIO1.direction(PCA95x5::Direction::IN_ALL);

    inputIO2.attach(Wire, 0x26);
    inputIO2.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    inputIO2.direction(PCA95x5::Direction::IN_ALL);

    inputIO3.attach(Wire, 0x27);
    inputIO3.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
    inputIO3.direction(PCA95x5::Direction::IN_ALL);

    Serial.println("KinCony F32 32 channel input state 0:ON  1:OFF");
}

void loop() {
    // Preserve the original channel positions in the 32-bit value.
    const uint32_t inputs1To16 = inputIO1.read();
    const uint32_t inputs17To24 = inputIO2.read() & 0x00FFU;
    const uint32_t inputs25To32 = inputIO3.read() & 0x00FFU;
    const uint32_t state = inputs1To16
                         | (inputs17To24 << 16)
                         | (inputs25To32 << 24);

    // Print the state of all 32 inputs in binary format
    Serial.print("Input state: ");
    Serial.println(state, BIN); // Print the state of inputs in binary

    delay(500); // Delay 500ms
}
arduino ino file download:

.zip   2-digital-input-9555.zip (Size: 915 bytes / Downloads: 3)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-digital-input-9555.ino.merged.zip (Size: 194.12 KB / Downloads: 3)
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)