Switching the PCF8574 chip on a Orange/Raspberry PI

Moderator: leecollings

Post Reply
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Switching the PCF8574 chip on a Orange/Raspberry PI

Post by ILoveIOT »

Switching 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.

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;
}
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests