byteman59 Posted January 27, 2022 Posted January 27, 2022 Is anyone familiar on how to code for a PCF8575 Expansion ports module in arduino mega? thanks
Zero-One Posted January 31, 2022 Posted January 31, 2022 Hi byteman59, Go to Libraries -> Library Manger and install PCF8575 by Rob Tillaart. Then google "arduino PCF8575 Rob Tillaart" to find the Arduino & github sites. Scroll down on the github site and you'll see the documentation. Also, look through the examples folders for code examples. It's fairly easy to read and write all 16 bits and save them to a uint16_t variable. When you get more experienced, you can read/write individual ports. Some key items: #include <PCF8575.h> // Set address for I2C device PCF8575 PCF(0x20); // set I2C address as appropriate. PCF is your own unique device name. Hex 20 is often the default, but you can add more devices to your I2C bus if you set the links on the PCB to give another unique address. Check if you can find the device and print some debug output: // Initialise I2C I/O expander if (!PCF.begin()) { Serial.println("could not initialize..."); } else { Serial.println("Initialised!"); } // Test is I2C chip is connected if (!PCF.isConnected()) { Serial.println("=> not connected"); } else { Serial.println("=> connected!!"); } Read it to a 16 bit variable called 'x' uint16_t x = PCF.read16(); Code snippets above are from others on the Web - credit to their collective Authors. Good luck Zero-One.
byteman59 Posted January 31, 2022 Author Posted January 31, 2022 thank you so much! I will give it a try.
byteman59 Posted January 31, 2022 Author Posted January 31, 2022 ok, got it connected properly. // // FILE: PCF8575_isConnected.ino // AUTHOR: Rob Tillaart // DATE: 2021-01-03 // PUPROSE: demo device detection #include "PCF8575.h" // adjust addresses if needed PCF8575 PCF(0x20); void setup() { Serial.begin(115200); // Initialise I2C I/O expander if (!PCF.begin()) { Serial.println("could not initialize..."); } else { Serial.println("Initialised!"); } // Test is I2C chip is connected if (!PCF.isConnected()) { Serial.println("=> not connected"); } else { Serial.println("=> connected!!"); } } void loop() { } // -- END OF FILE -- How would i include the DCS-BIOS commands into this sketch? For example, for the "DcsBios::Switch2Pos gearLever("GEAR_LEVER", PIN);" Thanks
Recommended Posts