PCF8575 output pin voltage LOW

First time meddling with a PCF8575 (Open-Smart)and using the "Example" from the "PCF8575_library-master" Library.

Using a Arduino Mega 2560 with vcc and gnd connected to all 4 appropriate pins on the module.

When module pins are pulled HIGH by the sketch, the pin output voltage at the pin is only between

between 14mV and 450mV(depending which pin is programmed "ON").

Voltage measured on the vcc pin of the embedded chip is 4.9v so what am I missing??

Want to be able to use the 8575 pins to light LED's.

Second question do I have to set a new address for output pins 10 to 17 on the other side of the

module as I cant get any output from these pins at the moment.

Pcf output pins can only be pulled high weakly, so cannot source enough current to light a led. But they can be pulled low strongly, sinking up to 20mA I think, so connect your LEDs (+series resistors) between Vcc and the pins.

Pcf8575 has 16 output pins which are numbered 0 to 15, so not sure what pins 10-17 refer to. The chip has one address. If your module contained 2x pcf8574, which have 8 output pins each, then the two chips would need to have different addresses.

PaulRB:
Pcf8575 has 16 output pins which are numbered 0 to 15, so not sure what pins 10-17 refer to.

No, it actually has port pins numbered “00” to “07” and “10” to “17”, corresponding to the two byte-wide ports. :roll_eyes:

You have to write - or read - two bytes at a time via I2C whenever you access the PCF8575. The library should have shown this.

You guys both need to sit down and read the datasheet. :grinning: Particularly section 8.1.

I do hope the OP has a proper regulated 5 V supply to power the 2560 and the LEDs.

Yes, it implements a quasi-open-drain pin interface where it can pull down and drive LEDs but has a weak pull-up (very similar to INPUT_PULLUP on the Arduino) except for a stronger brief impulse as the Write command is executed.

Fair enough, they are perversely numbered p10-p17! Whatever happened to p08 & p09?

EDIT: I guess they wanted to use “P” as the naming conveniton.

PaulRB:
I guess they wanted to use “P” as the naming convention.

Kinda like on the microprocessor, except using “0” and “1” instead of “A” and “B”. :sunglasses:

Thanks PaulRB pins P0 to P7 now working fine however not P 10 to 17.

Infact P10 to P15 will compile OK but P16 and P17 will not.

All pins P10 to P17 remain "LOW" would not seem to go "HIGH",

hence LED is constantly lit.

I have assumed that as I am using only 1 module that the same address (0x20)

applies to all pins 0 to 7 and 10 to 17 is this correct?

have attached a pin out for the module.

Tx for any help you can offer.

That picture shown the led between the pcf pin and ground. That won't work as I explained before, and I thought you had rewired your LEDs between Vcc and the pins?

Yes, one module, one chip, one address.

We need to see your code now I think.

PaulRB:
Yes, one module, one chip, one address.

Two bytes. :roll_eyes:

PaulRB:
We need to see your code now I think.

Yesterday would have been OK.

Sorry but I made a mistake on the sketch.

The LED is positioned Vcc to Resistor to Led + then LED - to gnd.

This is working.

My sketch is

/*
 Blink led on PIN0
 by Mischianti Renzo <http://www.mischianti.org>

 https://www.mischianti.org/2019/01/02/pcf8575-i2c-digital-i-o-expander-fast-easy-usage/
*/

#include "Arduino.h"
#include "PCF8575.h"

// Set i2c address
PCF8575 pcf8575(0x20);

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

	// Set pinMode to OUTPUT
	pcf8575.pinMode(P10, OUTPUT);

	pcf8575.begin();
}

void loop()
{
	pcf8575.digitalWrite(P10, HIGH);
	delay(1000);
	pcf8575.digitalWrite(P10, LOW);
	delay(1000);
}

This code does not work for me as the Pin 10 LED goes ON but wont turn off.

Changing the code to alter the 3 instances of P10 back to P0 and the P0 LED blinks on off as expected.

The LED is positioned Vcc to Resistor to Led + then LED - to gnd.

That would certainly make the led stay on permanently! Is that also a mistake?

#include "PCF8575.h"

There are several libraries available with this name. Which one are you using? Did you use library manager or download a zip file? From what address?

I think it might be this one?

This library defines these pins:

#define P0   0
#define P1   1
#define P2   2
#define P3   3
#define P4   4
#define P5   5
#define P6   6
#define P7   7
#define P8   8
#define P9   9
#define P10   10
#define P11   11
#define P12   12
#define P13   13
#define P14   14
#define P15   15

So the library author is not following the pin naming convention used in the chip data sheet. That explains why P16 and P17 stop the sketch compiling. It might also explain why your sketch does not work. The pin labelled P10 on the module would need to be P8 in the code, I think.

Sorry. Another "old fart" moment.

The routing is ; Arduino vcc - Resistor - LED - Pin0 (to gnd);

The code I used is from the IDE Library ; PCF8575 Renzo Mischinati Ver 1.0.1

Following your remarks I reconnected LED to Pin 10 on the module but coded it as P8 in the sketch

and BINGO it works.

Can I overcome this by altering all instances referring to "PIN" in both the "cpp" and "h" library files

Tx for your help

Yes, editing the ".h" file only should be required, but test thoroughly. To match the chip data sheet and the labels on most (all) modules available on eBay etc), the definitions should be "P00" to "P07" (not "P0" to "P7") and "P10" to "P17". When you have done and tested that, it would be helpful to the Arduino community if you raise a new issue on the git repository I linked to above, explaining the problems you found, how you fixed them and why the new definitions are more correct, and ask the author politely to make changes to the library so that other Arduino users do not face this same problem in future. You will need to sign up for a gitHub account to do this, it is free.

Sorry to be a pest but altered the .h file and would not compile.

Altered the .cpp file and it compiled and uploaded but the end result was

no different.

Works fine but output is 2 pins out.(Sketch calls P12 but P14 is pulled low.

In case I have missed something I have attached the altered copies of both

.h & .cpp files.

Tx.

.h FILE

/*
 * PCF8575 GPIO Port Expand
 * https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2019 Renzo Mischianti www.mischianti.org All right reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef PCF8575_h
#define PCF8575_h

#include "Wire.h"

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

// Uncomment to enable printing out nice debug messages.
// #define PCF8575_DEBUG

// Uncomment for low memory usage this prevent use of complex DigitalInput structure and free 7byte of memory
// #define PCF8575_LOW_MEMORY

// Define where debug output will be printed.
#define DEBUG_PRINTER Serial

// Setup debug printing macros.
#ifdef PCF8575_DEBUG
	#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
	#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
	#define DEBUG_PRINT(...) {}
	#define DEBUG_PRINTLN(...) {}
#endif

#define READ_ELAPSED_TIME 10

//#define P0  	B00000001
//#define P1  	B00000010
//#define P2  	B00000100
//#define P3  	B00001000
//#define P4  	B00010000
//#define P5  	B00100000
//#define P6  	B01000000
//#define P7  	B10000000
//
#define P0  	0
#define P1  	1
#define P2  	2
#define P3  	3
#define P4  	4
#define P5  	5
#define P6  	6
#define P7  	7
//***********************************************************DELETED************
#define P10  	10
#define P11  	11
#define P12  	12
#define P13  	13
#define P14  	14
#define P15  	15
//***********************************************************ADDED************
#define P8  	16
#define P9  	17
#include <math.h>


class PCF8575 {
public:

	PCF8575(uint8_t address);
	PCF8575(uint8_t address, uint8_t interruptPin,  void (*interruptFunction)() );

#if !defined(__AVR) && !defined(__STM32F1__)
	PCF8575(uint8_t address, uint8_t sda, uint8_t scl);
	PCF8575(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin,  void (*interruptFunction)());
#endif

#ifdef ESP32
	///// changes for second i2c bus
	PCF8575(TwoWire *pWire, uint8_t address);
	PCF8575(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl);

	PCF8575(TwoWire *pWire, uint8_t address, uint8_t interruptPin,  void (*interruptFunction)() );
	PCF8575(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin,  void (*interruptFunction)());
#endif

	void begin();
	void pinMode(uint8_t pin, uint8_t mode);

	void readBuffer(bool force = true);
	uint8_t digitalRead(uint8_t pin);
	#ifndef PCF8575_LOW_MEMORY
		struct DigitalInput {
			uint8_t p0;
			uint8_t p1;
			uint8_t p2;
			uint8_t p3;
			uint8_t p4;
			uint8_t p5;
			uint8_t p6;
			uint8_t p7;
	//****************************************************DELETED***************		
			uint8_t p10;
			uint8_t p11;
			uint8_t p12;
			uint8_t p13;
			uint8_t p14;
			uint8_t p15;
        //****************************************************ADDED***************	
                        uint8_t p16;
			uint8_t p17;
		} digitalInput;


		DigitalInput digitalReadAll(void);
	#else
		uint16_t digitalReadAll(void);
	#endif
	void digitalWrite(uint8_t pin, uint8_t value);

private:
	uint8_t _address;

	#if defined(__AVR) || defined(__STM32F1__)
		uint8_t _sda;
		uint8_t _scl;
	#else
		uint8_t _sda = SDA;
		uint8_t _scl = SCL;
	#endif

	TwoWire *_wire;

	bool _usingInterrupt = false;
	uint8_t _interruptPin = 2;
	void (*_interruptFunction)(){};

	uint16_t writeMode 	= 	0;
	uint16_t readMode 	= 	0;
	uint16_t byteBuffered = 0;
	unsigned long lastReadMillis = 0;

	uint16_t writeByteBuffered = 0;

};

#endif

.cpp File follows as exceeded permitted characters

Follows:

.cpp file

.cpp FILE[code]

#include "PCF8575.h"
#include "Wire.h"

/**
 * Constructor
 * @param address: i2c address
 */
PCF8575::PCF8575(uint8_t address){
	_wire = &Wire;

	_address = address;
};

/**
 * Construcor
 * @param address: i2c address
 * @param interruptPin: pin to set interrupt
 * @param interruptFunction: function to call when interrupt raised
 */
PCF8575::PCF8575(uint8_t address, uint8_t interruptPin,  void (*interruptFunction)() ){
	_wire = &Wire;

	_address = address;
	_interruptPin = interruptPin;
	_interruptFunction = interruptFunction;
	_usingInterrupt = true;
};

#if !defined(__AVR) && !defined(__STM32F1__)
	/**
	 * Constructor
	 * @param address: i2c address
	 * @param sda: sda pin
	 * @param scl: scl pin
	 */
	PCF8575::PCF8575(uint8_t address, uint8_t sda, uint8_t scl){
		_wire = &Wire;

		_address = address;
		_sda = sda;
		_scl = scl;
	};

	/**
	 * Constructor
	 * @param address: i2c address
	 * @param sda: sda pin
	 * @param scl: scl pin
	 * @param interruptPin: pin to set interrupt
 	 * @param interruptFunction: function to call when interrupt raised
	 */
	PCF8575::PCF8575(uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin,  void (*interruptFunction)() ){
		_wire = &Wire;

		_address = address;
		_sda = sda;
		_scl = scl;

		_interruptPin = interruptPin;
		_interruptFunction = interruptFunction;

		_usingInterrupt = true;
	};
#endif

#ifdef ESP32
	/**
	 * Constructor
	 * @param address: i2c address
	 */
	PCF8575::PCF8575(TwoWire *pWire, uint8_t address){
		_wire = pWire;

		_address = address;
	};

	/**
	 * Construcor
	 * @param address: i2c address
	 * @param interruptPin: pin to set interrupt
	 * @param interruptFunction: function to call when interrupt raised
	 */
	PCF8575::PCF8575(TwoWire *pWire, uint8_t address, uint8_t interruptPin,  void (*interruptFunction)() ){
		_wire = pWire;

		_address = address;
		_interruptPin = interruptPin;
		_interruptFunction = interruptFunction;
		_usingInterrupt = true;
	};

	/**
	 * Constructor
	 * @param address: i2c address
	 * @param sda: sda pin
	 * @param scl: scl pin
	 */
	PCF8575::PCF8575(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl){
		_wire = pWire;

		_address = address;
		_sda = sda;
		_scl = scl;
	};

	/**
	 * Constructor
	 * @param address: i2c address
	 * @param sda: sda pin
	 * @param scl: scl pin
	 * @param interruptPin: pin to set interrupt
	 * @param interruptFunction: function to call when interrupt raised
	 */
	PCF8575::PCF8575(TwoWire *pWire, uint8_t address, uint8_t sda, uint8_t scl, uint8_t interruptPin,  void (*interruptFunction)() ){
		_wire = pWire;

		_address = address;
		_sda = sda;
		_scl = scl;

		_interruptPin = interruptPin;
		_interruptFunction = interruptFunction;

		_usingInterrupt = true;
	};
#endif

/**
 * wake up i2c controller
 */
void PCF8575::begin(){
	#if !defined(__AVR) && !defined(__STM32F1__)
		_wire->begin(_sda, _scl);
	#else
	//			Default pin for AVR some problem on software emulation
	//			#define SCL_PIN _scl
	// 			#define SDA_PIN _sda
		_wire->begin();
	#endif

//		Serial.println( writeMode, BIN);
//		Serial.println( readMode, BIN);

	// Check if there are pins to set low
	if (writeMode>0 || readMode>0){
		DEBUG_PRINTLN("Set write mode");
		_wire->beginTransmission(_address);
		DEBUG_PRINT(" ");
		DEBUG_PRINT("usedPin pin ");


		uint16_t usedPin = writeMode | readMode;
		DEBUG_PRINTLN( ~usedPin, BIN);
//		Serial.println( ~usedPin, BIN);

		_wire->write((uint8_t) ~usedPin);
		_wire->write((uint8_t) (~(usedPin >> 8)));

		DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
		_wire->endTransmission();
	}

	// If using interrupt set interrupt value to pin
	if (_usingInterrupt){
		DEBUG_PRINTLN("Using interrupt pin (not all pin is interrupted)");
		::pinMode(_interruptPin, INPUT_PULLUP);
		attachInterrupt(digitalPinToInterrupt(_interruptPin), (*_interruptFunction), FALLING );
	}

	// inizialize last read
	lastReadMillis = millis();
}

/**
 * Set if fin is OUTPUT or INPUT
 * @param pin: pin to set
 * @param mode: mode, supported only INPUT or OUTPUT (to semplify)
 */
void PCF8575::pinMode(uint8_t pin, uint8_t mode){
	DEBUG_PRINT("Set pin ");
	DEBUG_PRINT(pin);
	DEBUG_PRINT(" as ");
	DEBUG_PRINTLN(mode);

	if (mode == OUTPUT){
		writeMode = writeMode | bit(pin);
		readMode =  readMode & ~bit(pin);
//		DEBUG_PRINT("writeMode: ");
//		DEBUG_PRINT(writeMode, BIN);
//		DEBUG_PRINT("readMode: ");
//		DEBUG_PRINTLN(readMode, BIN);

	}else if (mode == INPUT){
		writeMode = writeMode & ~bit(pin);
		readMode =   readMode | bit(pin);
//		DEBUG_PRINT("writeMode: ");
//		DEBUG_PRINT(writeMode, BIN);
//		DEBUG_PRINT("readMode: ");
//		DEBUG_PRINTLN(readMode, BIN);

[/code]

Follows:

.cpp FILE ( Continue)

}
	else{
		DEBUG_PRINTLN("Mode non supported by PCF8575")
	}
	DEBUG_PRINT("Write mode: ");
	DEBUG_PRINTLN(writeMode, BIN);

};

/**
 * Read value from i2c and bufferize it
 * @param force
 */
void PCF8575::readBuffer(bool force){
	if (millis() > PCF8575::lastReadMillis+READ_ELAPSED_TIME || _usingInterrupt || force){
		_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
		lastReadMillis = millis();
		if(_wire->available())   // If uint16_ts are available to be recieved
		{
			uint16_t iInput = _wire->read();// Read a uint16_t
			iInput |= _wire->read() << 8;// Read a uint16_t
			if ((iInput & readMode)>0){
				byteBuffered = byteBuffered | (uint16_t)iInput;
			}
		}
	}
}

#ifndef PCF8575_LOW_MEMORY
	/**
	 * Read value of all INPUT pin
	 * Debounce read more fast than 10millis, non managed for interrupt mode
	 * @return
	 */
	PCF8575::DigitalInput PCF8575::digitalReadAll(void){
		DEBUG_PRINTLN("Read from buffer");
		_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
		lastReadMillis = millis();
		if(_wire->available())   // If uint16_ts are available to be recieved
		{
			  DEBUG_PRINTLN("Data ready");
			  uint16_t iInput = _wire->read();// Read a uint16_t
				iInput |= _wire->read() << 8;// Read a uint16_t

			  if ((iInput & readMode)>0){
				  DEBUG_PRINT("Input ");
				  DEBUG_PRINTLN((uint16_t)iInput, BIN);

				  byteBuffered = byteBuffered | (uint16_t)iInput;
				  DEBUG_PRINT("byteBuffered ");
				  DEBUG_PRINTLN(byteBuffered, BIN);
			  }
		}

		DEBUG_PRINT("Buffer value ");
		DEBUG_PRINTLN(byteBuffered, BIN);

		if ((bit(0) & readMode)>0) digitalInput.p0 = ((byteBuffered & bit(0))>0)?HIGH:LOW;
		if ((bit(1) & readMode)>0) digitalInput.p1 = ((byteBuffered & bit(1))>0)?HIGH:LOW;
		if ((bit(2) & readMode)>0) digitalInput.p2 = ((byteBuffered & bit(2))>0)?HIGH:LOW;
		if ((bit(3) & readMode)>0) digitalInput.p3 = ((byteBuffered & bit(3))>0)?HIGH:LOW;
		if ((bit(4) & readMode)>0) digitalInput.p4 = ((byteBuffered & bit(4))>0)?HIGH:LOW;
		if ((bit(5) & readMode)>0) digitalInput.p5 = ((byteBuffered & bit(5))>0)?HIGH:LOW;
		if ((bit(6) & readMode)>0) digitalInput.p6 = ((byteBuffered & bit(6))>0)?HIGH:LOW;
		if ((bit(7) & readMode)>0) digitalInput.p7 = ((byteBuffered & bit(7))>0)?HIGH:LOW;
		
		if ((bit(10) & readMode)>0) digitalInput.p10 = ((byteBuffered & bit(10))>0)?HIGH:LOW;
		if ((bit(11) & readMode)>0) digitalInput.p11 = ((byteBuffered & bit(11))>0)?HIGH:LOW;
		if ((bit(12) & readMode)>0) digitalInput.p12 = ((byteBuffered & bit(12))>0)?HIGH:LOW;
		if ((bit(13) & readMode)>0) digitalInput.p13 = ((byteBuffered & bit(13))>0)?HIGH:LOW;
		if ((bit(14) & readMode)>0) digitalInput.p14 = ((byteBuffered & bit(14))>0)?HIGH:LOW;
		if ((bit(15) & readMode)>0) digitalInput.p15 = ((byteBuffered & bit(15))>0)?HIGH:LOW;
//*********************************************************************************************************************ADDED
                if ((bit(16) & readMode)>0) digitalInput.p16 = ((byteBuffered & bit(16))>0)?HIGH:LOW;
		if ((bit(17) & readMode)>0) digitalInput.p17 = ((byteBuffered & bit(17))>0)?HIGH:LOW;

		if ((readMode & byteBuffered)>0){
			byteBuffered = ~readMode & byteBuffered;
			DEBUG_PRINT("Buffer hight value readed set readed ");
			DEBUG_PRINTLN(byteBuffered, BIN);
		}
		DEBUG_PRINT("Return value ");
		return digitalInput;
	};
#else
	/**
	 * Read value of all INPUT pin in byte format for low memory usage
	 * Debounce read more fast than 10millis, non managed for interrupt mode
	 * @return
	 */
	uint16_t PCF8575::digitalReadAll(void){
		DEBUG_PRINTLN("Read from buffer");
		_wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
		lastReadMillis = millis();
		if(_wire->available())   // If uint16_ts are available to be recieved
		{
			  DEBUG_PRINTLN("Data ready");
			  uint16_t iInput = _wire->read();// Read a uint16_t
				iInput |= _wire->read() << 8;// Read a uint16_t

			  if ((iInput & readMode)>0){
				  DEBUG_PRINT("Input ");
				  DEBUG_PRINTLN((uint16_t)iInput, BIN);

				  byteBuffered = byteBuffered | (uint16_t)iInput;
				  DEBUG_PRINT("byteBuffered ");
				  DEBUG_PRINTLN(byteBuffered, BIN);
			  }
		}

		DEBUG_PRINT("Buffer value ");
		DEBUG_PRINTLN(byteBuffered, BIN);

		uint16_t byteRead = byteBuffered;

		if ((readMode & byteBuffered)>0){
			byteBuffered = ~readMode & byteBuffered;
			DEBUG_PRINT("Buffer hight value readed set readed ");
			DEBUG_PRINTLN(byteBuffered, BIN);
		}
		DEBUG_PRINT("Return value ");
		return byteRead;
	};
#endif

/**
 * Read value of specified pin
 * Debounce read more fast than 10millis, non managed for interrupt mode
 * @param pin
 * @return
 */
uint8_t PCF8575::digitalRead(uint8_t pin){
	uint8_t value = LOW;
	if ((bit(pin) & writeMode)>0){
		DEBUG_PRINTLN("Pin in write mode, return value");
		DEBUG_PRINT("Write data ");
		DEBUG_PRINT(writeByteBuffered, BIN);
		DEBUG_PRINT(" for pin ");
		DEBUG_PRINT(pin);
		DEBUG_PRINT(" bin value ");
		DEBUG_PRINT(bit(pin), BIN);
		DEBUG_PRINT(" value ");
		DEBUG_PRINTLN(value);

		if ((bit(pin) & writeByteBuffered)>0){
			  value = HIGH;
		  }else{
			  value = LOW;
		  }
		return value;
	}

	DEBUG_PRINT("Read pin ");
	DEBUG_PRINTLN(pin);
	// Check if pin already HIGH than read and prevent reread of i2c
	if ((bit(pin) & byteBuffered)>0){
		DEBUG_PRINTLN("Pin already up");
		value = HIGH;
	 }else if ((/*(bit(pin) & byteBuffered)<=0 && */millis() > PCF8575::lastReadMillis+READ_ELAPSED_TIME) /*|| _usingInterrupt*/){
		 DEBUG_PRINTLN("Read from buffer");
		  _wire->requestFrom(_address,(uint8_t)2);// Begin transmission to PCF8575 with the buttons
		  lastReadMillis = millis();
		  if(_wire->available())   // If bytes are available to be recieved
		  {
			  DEBUG_PRINTLN("Data ready");
			  uint16_t iInput = _wire->read();// Read a uint16_t
				iInput |= _wire->read() << 8;// Read a uint16_t

//				Serial.println(iInput, BIN);

			  if ((iInput & readMode)>0){
				  DEBUG_PRINT("Input ");
				  DEBUG_PRINTLN((uint16_t)iInput, BIN);

				  byteBuffered = byteBuffered | (uint16_t)iInput;
				  DEBUG_PRINT("byteBuffered ");
				  DEBUG_PRINTLN(byteBuffered, BIN);

				  if ((bit(pin) & byteBuffered)>0){
					  value = HIGH;
				  }
			  }
		  }
	}
	DEBUG_PRINT("Buffer value ");
	DEBUG_PRINTLN(byteBuffered, BIN);
	// If HIGH set to low to read buffer only one time
	if (value==HIGH){
		byteBuffered = ~bit(pin) & byteBuffered;
		DEBUG_PRINT("Buffer hight value readed set readed ");
		DEBUG_PRINTLN(byteBuffered, BIN);
	}
	DEBUG_PRINT("Return value ");
	DEBUG_PRINTLN(value);
	return value;
};

/**
 * Write on pin
 * @param pin
 * @param value
 */
void PCF8575::digitalWrite(uint8_t pin, uint8_t value){
	DEBUG_PRINTLN("Begin trasmission");
	_wire->beginTransmission(_address);     //Begin the transmission to PCF8575
	if (value==HIGH){
		writeByteBuffered = writeByteBuffered | bit(pin);
	}else{
		writeByteBuffered = writeByteBuffered & ~bit(pin);
	}
//	DEBUG_PRINT("Write data ");
//	DEBUG_PRINT(writeByteBuffered, BIN);
//	DEBUG_PRINT(" for pin ");
//	DEBUG_PRINT(pin);
//	DEBUG_PRINT(" bin value ");
//	DEBUG_PRINT(bit(pin), BIN);
//	DEBUG_PRINT(" value ");
//	DEBUG_PRINTLN(value);

//	Serial.print(" --> ");
//	Serial.println(writeByteBuffered);
//	Serial.println((uint8_t) writeByteBuffered);
//	Serial.println((uint8_t) (writeByteBuffered >> 8));

	writeByteBuffered = writeByteBuffered & writeMode;
	_wire->write((uint8_t) writeByteBuffered);
	_wire->write((uint8_t) (writeByteBuffered >> 8));
	DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");

	_wire->endTransmission();
};

No, like this:

#define P00   0
#define P01   1
#define P02   2
#define P03   3
#define P04   4
#define P05   5
#define P06   6
#define P07   7
#define P10   8
#define P11   9
#define P12   10
#define P13   11
#define P14   12
#define P15   13
#define P16   14
#define P17   15

What did you need to change in the .cpp file?

I am getting a little confused so I have started again from scratch.

I deleted all PCF 8575 libraries from my computer libraries and downloaded the

Renzo Mischianti PCF8575 Library direct from the IDE libraries.

Without modifying anything in the .cpp file I loaded the “blinkOnP0” example.

In the sketch I changed the Pins one by one ,(p0 to p7) and all worked just fine.

p10 to 17 however, worked just fine except it was 2 pins out.

e.g. Sketch p8 activates Pin 10, up to Sketch p15 which activated Pin 17.

I then changed the .cpp file as per your instructions

#define P00 0
#define P01 1
#define P02 2
#define P03 3
#define P04 4
#define P05 5
#define P06 6
#define P07 7
#define P10 8
#define P11 9
#define P12 10
#define P13 11
#define P14 12
#define P15 13
#define P16 14
#define P17 15

And uploaded the sketch.

It made no difference to the outcome which remained exactly the same as the original

.cpp library.

Naming the Pin from p0 to p00 seems to make no difference.

Farticus:
I then changed the .cpp file as per your instructions

No, I said change the .h file.

Farticus:
#define P00 0
#define P01 1
#define P02 2
#define P03 3
#define P04 4
#define P05 5
#define P06 6
#define P07 7
#define P10 8
#define P11 9
#define P12 10
#define P13 11
#define P14 12
#define P15 13
#define P16 14
#define P17 15

And uploaded the sketch.

It made no difference to the outcome which remained exactly the same as the original

.cpp library.

Naming the Pin from p0 to p00 seems to make no difference.

That's odd. After the above change, P0 should cause an error, it is no longer defined. Only P00 should work.

Make a small unimportant change (e.g. to comments) to the .h, .cpp and your sketch and upload again. The IDE is supposed to detect any changes and re-compile as needed. Sounds like that didn't happen for some reason.

I thank you for your patience PaulRB you deserve a medal. :slight_smile:

Finally what you have been saying "sank in" and all is working as it should.

Many many thanks.