For compiling use : cd /root/scripts/pcf8574/ ; g++ pcf8574.0x25.cpp -o pcf8574.0x25 -lwiringPi -std=c++11
For console use : /root/scripts/pcf8574/pcf8574.0x25 105 0 (this will switch port 5 on,..and uncomment the printf lines)
For Domoticz use : script:///root/scripts/pcf8574/pcf8574.0x25 106 1
When remote machine : script:///usr/bin/ssh [email protected] /root/scripts/pcf8574/pcf8574.0x25 107 0
When remote machine : script:///usr/bin/ssh [email protected] /root/scripts/pcf8574/pcf8574.0x25 107 1
For other chip addresses adjust the file below for address 0x20, 0x21, 0x22 etc, and change the 100 begin address on every chip, so when you have multiple chips, the switches are not named the same. So maybe for 0x20 start at 100, 0x21 110, 0x22 120 etc.
Filename : pcf8574.0x25.cpp
Code: Select all
#include <stdio.h>
#include <time.h>
#include <sstream>
#include <wiringPi.h>
#include <pcf8574.h>
/*
* pcf8574.0x25.cpp:
* Swithing the PCF8574 chip on a Orange/Raspberry PI.
*
*
*
* For compiling use : cd /root/scripts/pcf8574/ ; g++ pcf8574.0x25.cpp -o pcf8574.0x25 -lwiringPi -std=c++11
* For console use : /root/scripts/pcf8574/pcf8574.0x25 105 0 (this will switch port 5 on,..and uncomment the printf lines)
* For Domoticz use : script:///root/scripts/pcf8574/pcf8574.0x25 106 1
* When remote machine : script:///usr/bin/ssh [email protected] /root/scripts/pcf8574/pcf8574.0x25 107 0
* When remote machine : script:///usr/bin/ssh [email protected] /root/scripts/pcf8574/pcf8574.0x25 107 1
*
* For other chip addresses adjust the file below for address 0x20, 0x21, 0x22 etc, and change the 100 (begin address on every chip,
* so when you have multiple chips, the switches are not named the same. So maybe for 0x20 start at 100, 0x21 110, 0x22 120 etc.
*
* Updated : 11-03-2019 by ILoveIoT.
*
*/
using namespace std;
int portnumber;
int portstatus;
int main (int argc, char *argv[]){
//printf("\n\nSwithing the PCF8574 chip on a Orange/Raspberry PI on Address 0x25\n\n");
//printf("PCF8574 Port : %s\n",argv[1]);
//printf("PCF8574 Status : %s\n\n\n",argv[2]);
std::istringstream portnumberconvert (argv[1]);
portnumberconvert >> portnumber;
std::istringstream portstatusconvert (argv[2]);
portstatusconvert >> portstatus;
wiringPiSetup();
pcf8574Setup(100, 0x25);
digitalWrite(portnumber + 0, portstatus);
return 0;
}