I would like to just use pin 13 to receive the information of a wafer switch i.e.
one of four inputs.
I have a PCF 8574
I have been looking for information about how to run this and the best I can come up with is
here
After correcting for wire.send being changed to wire.write().
I am left with the error message
no matching function for call to "TwoWire::write()"
and a "wire.write" line covered in the orange strip?
If I comment this line out it just does the same to the next wire.write() line?
I have no instance of TwoWire::write() anywhere in the sketch?
Can someone explain this?
Is there an easy sketch somewhere that I can use as a basis for just using a PCF8574 as a parallel in serial out chip.
This is a nice library for the PCF88574. It can make full use of the quasi IO 
I have worked out a solution to my problem.
I used
this page to good effect and thank you to PugazhM for that.
I have altered it so it just receives signals from 8 switches.
Use PugazhM's G2-PCF8574 IN/OUT diagram but remove the LEDs and extend the switches and resistors to all eight pins and use this short sketch.
//Include Wire library
#include <Wire.h>
#define CHIP 0x39
int c;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
for(byte i = 0; i<255; i++)
{
IOexpanderRead(CHIP);
delay(1000);
}
}
//Read a byte from the IO expander
byte IOexpanderRead(int address)
{
byte _data;
Wire.requestFrom(address, 1);
if(Wire.available())
c=Wire.read();
Serial.println(c);
}
The serial monitor reflects the setting of the switches.
Why is the address an int?
Why is the return type byte but don't you actually return anything?
Why do you loop from 0 to 254 but don't actually do anything with it?
Why do you use a macro for the address instead of the saver C++ alternative, const byte?
Questions questions questions...
septillion:
Why is the address an int?
I have made it an int, what difference does it make, apart from using less memory?
septillion:
Why is the return type byte but don't you actually return anything?
if you mean byte _data:
I have removed it, it's not being used.
septillion:
Why do you loop from 0 to 254 but don't actually do anything with it?
Is that not loading the data? I don't fully understand the I2c system and was just using PugazhM's program, I have removed that also and it still works but only gives the first four outputs? how do I get the other four?
septillion:
Why do you use a macro for the address instead of the saver C++ alternative, const byte?
Macro? where?
matelot:
I have made it an int, what difference does it make, apart from using less memory?
That, which is already good practice to lean when programming a micro. And the weird behaviour you will get if you now accidentally call it with a number bigger then 255. Let alone what happens when you call it with a negative number...
matelot:
if you mean
byte _data:
I have removed it, it's not being used.
Then change the return type of the function to void to match. Or better, make the function actually return the value instead of placing it in a global.
matelot:
Is that not loading the data?
It does absolutely nothing... i is never used, so all it does now is loop 255 tine in loop() and then start over because loop() loops....
matelot:
I don't fully understand the I2c system
Then why didn't you made you life easier by using the library?
matelot:
I have removed that also and it still works but only gives the first four outputs? how do I get the other four?
Show the changed code. Although I doubt the problem is there....
matelot:
Macro? where?
Here:
#define CHIP 0x39
where
const byte ChipAddress = 0x39;
is the safer C++ alternative. Also changed the name to something more useful.
#include <Wire.h>
const byte ChipAddress = 0x39;
byte c;
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
IOexpanderRead(ChipAddress);
delay(1000);
}
//Read a byte from the IO expander
void IOexpanderRead(int address)
{
Wire.requestFrom(address,1);
if(Wire.available())
c=Wire.read();
Serial.println(c);
}
I have already had an attempt at using libraries, or in fact a few attempts, but I can't seem to work out what instructions I can use.
It looks as if my chip is broken, if I put a 10k resistor on pins P0-P3 I can hold the voltage on those pins up to 5v but if I do it on pins P4-P7 the voltage stays at 0v.
It does depend on the documentation. The PCF8574 does come with example. But when in doubt, you can always open op the .h.
To use it here:
#include <PCF8574.h>
#include <Wire.h>
PCF8574 module(0x39);
void setup(){
Serial.begin(9600);
module.begin();
}
void loop(){
Serial.println(module.readButton8());
}
This even allows us the use a pin as output at the same time if you want to. See the buttonRead8 example.
OK thanks I will try that tomorrow.
how do I download this library?
Yeah, it's a bit stupid. The library is part of a bigger collection and RobTillaart just made it available as a whole. Just go to the main page of the git and click Clone or Download => Download ZIP or just click here.
In the zip, browse to Arduino-master\libraries and copy the PCF8574-folder into you library folder (the one in your sketchbook, default (on Windows) c:\Users[user]\Documents\Arduino\libraries). That's the place all downloaded libraries should go. If you want, you can copy multiple/all libraries from the zip.
OK thanks . I did that and to check it was in, though I can see it if I go to sketch/include library, I put your little sketch in below and when I tried to compile it I got
"call of overloaded 'readButton8))' is ambiguous"
I don't know enough about libraries to go looking for this problem, though I will try, can you see what might be causing it? Could it just be that I am just compiling it without an arduino connected?
can I get PCF8574.h to go into the IDE? I can only get it to go into notepad?
I think my chip is ****. I have just run the PCF8574_test from the examples and I get F where * is the state of P0-P3.
P4-P7 don't change no matter how I set them up, I assume this is the first F in the test?
Update.... I have swapped some of the components around and now get all eight inputs working using PCF8574_test and buttonRead8.