I want to use a PCF8575 as a switch

I am currently using 16 toggle switches on a Model Railway point switching, I am using a Mega with a PCA9685 operating 16 servos, but I dont like these minature switches so I would like to use minature momentary push buttons instead, so I think the PCF8575 would probably do the job using 8 as inputs and 8 as outputs and add another PCF8575 on the I2C bus to give me another 8 channels, but as I havnt used this module before would be grateful for any help, I would probably use an Arduino Nano or Uno…

Thanks for any help

John

The first thing to say about the PCF8575 is that it is (more or less) an open collector device in output mode. For example, you can switch a led on, if that led's anode is connected to the high side by pulling its cathode low with a PCF8575 pin. But it is not symmetric. You cannot take a led where its cathode is connected to the low side and apply a voltage from a PCF8575 pin to that led's anode and switch the led on.

Can you supply a wiring diagram of the current circuit. A couple of examples of each element (switch, solenoids etc.) would be enough.

Are you saying you are using RC miniature servos to actuate model train track switches ?

If so, what is the end to end travel distance for the track switch ?

And if so, are you using the PCF8575 to send control signals to RC servos ?

Have you ever tried the TLC5940 ?

The switches 5 “Y” point which are on a mimic panel go straight to the Polarity Mega, this in turn feeds to a small LED mimic panel so I can see whats going on these 5 then go to a 5 Relay board which in turn switch inputs on a points Mega, the other 11 switches go straight to the Servo control Mega, the servo’s I am using are the small DC90 which are mounted under the layout and move through an angle of about 20 deg’s in the sketch the movement is from 270 to 350 which I can vary, the arm of the servo has a piece of 0.8mm piano wire which goes through board and through a small hole in the point so its just a rocking action and as the piano wire is flexible it can flex in the hole through layout …

It is certainly a large development. The resolution of the schematics , though, is not high enough to identify all components/interconnections.

I’m not sure about the mechanical aspects of your railway design, but the pcf8575 pin can be used to sink (but not source) a load 20mA. It can also read a switch wired on the low side (add a 100k pull-up resistor). See data sheet ch. 9 for examples: http://www.ti.com/lit/ds/symlink/pcf8575.pdf

If you have a large number of switches or buttons, you also have the option of wiring them in a matrix configuration. 16 switches could be wired as a 4 x 4 matrix using only 8 pins. Obviously, the more switches, the more the savings. However, the coding is considerably more complex.

Also to consider with I2C is that the wires cannot be too long.

I could send an Eagle cad file if you had this program…

I was also looking at using a 74HC595 shift register, I saw a Youtube video linking 8 switches to outputs via a diode so stop shorts and LED’s to outputs and the sketch allows single or multiple switching …

74HC595_Switch.ino (1.09 KB)

Let's try to work out exactly what your requirements are, first.

It seems simple. You have toggle switches which you want to replace with push buttons. If those toggle switches are switching only a signal voltage, it is very easy. You simply read the button state with an Arduino (either directly or through a port multiplier like the PCF8575 to save arduino pins) and the arduino maintains the state of the button press (toggle on / toggle off etc) in a variable for each button. The arduino can, on the basis of those state variables switch on leds, relays, operate servos etc. etc. again, either directly or through a (suitable) port multiplier. Obviously, if you are replacing a toggle switch with a push button, and alternate presses of the button switch on then of, there has to be a led to indicate to the user what the current state is.

I'm a bit puzzled by your 595 shift register circuit. A 595 is basically an output device and I would not normally expect to see its output pins to be connected to what looks like a switch.

What the operation is … if I toggle one way switch is closed this causes Polarity Mega to give output and when I toggle opposite it turns off … so I want a momentary push button to toggle on and then when I press again it goes off … the output for 5 of the toggle switches goes to Polarity Mega pins 35,37,39,41,43 …

I will send you the sketches for polarity and point switching … NB … these are not my sketches a friend in France was good enough to design these …

I have looked at a youtube video were this guy mocked up this 595 and Uno to switch LEDs and it seemed just what I wanted albeit I would put opto isolators in place of LED’s …

Another device I found was a 74C922 which gives a BCD output and then by feeding into a 74HC4515 4 to 16 channel decoder I get an output when any of the buttons 1 - 16 are pressed only problem with that it probable doesnt latch so would have to work that one out…

rail_crossings_sample2_V2.ino (34.4 KB)

Bolton_Station_Point_Servo_sketch_28042020.ino (4.99 KB)

This was the youtube video...

https://www.youtube.com/watch?v=1Vb2BpxPnjU

One other thing you may have a look at for me in the Bolton Station point servo ... which I have not tried yet I have another sketch ... and one problem I have is the servo moves to fast and doesnt detach and I am finding the DC90 servos are jamming ... so was wanting to use the Attach / detach command so servo's are not live all the time...

Sorry there was an error on my 595 drawing I missed a connection from 10kohm and all common switches going to PD0 or pin 0 if using Arduino ...

Impressive setup.

Have you used TLC5940s to drive servos yet ?