Cockpitbuilders.com

Main => Builders Discussions => Topic started by: iwik on January 11, 2024, 09:31:07 PM

Title: PCF8574 I/O Extender Board Problems
Post by: iwik on January 11, 2024, 09:31:07 PM
Hi Guys,
Having trouble getting switches and LEDs read by these i/o boards.
I have my A320 quad interfaced with a Arduino Promicro and two PCF8574 i/o cards.Attached to these cards are 10 leds and 5 switches.
The leds show for off and on states.
When i first built it these functioned perfectly.Since then i had to do some mechanical work and i update dthe firmware.This is when i noticed the leds and switches were no longer working.Thinking it might have been the firmware i reverted back to the original sketch.No such luck,still not working.
I think the hardware is ok as i have loaded a sketch from the PCF8574 library and that reads the switch and lights the led.
The firmware that had loaded was a hex file and not done thru Arduino IDE.
I have no Arduino experience and was hoping someone can help me to get it going.I also ran a i2C scanner skecth and it identified the two cards at address 20 and 21.I have attached the sketch.Thanks
P.S i have noticed if i disconnect the I2C bus all the axis and buttons connected to the arduino stop working.
Title: Re: PCF8574 I/O Extender Board Problems
Post by: ame on February 02, 2024, 04:04:37 PM
Ok. This is incredibly badly-written code, but I suppose it's all we've got.

Firstly, it declares three PCF I/O extenders, but only uses two.

The code for the PCF extenders seems to read both of them (the two that are actually used), checks the value of some of the input bits (presumably switches), then writes different bit values back to the PCF extenders according to the state of the input bits. Presumably that is to drive the LEDs.

If it was working, but now it isn't, even with the original firmware, then something has changed.

Now is your chance to become an Arduino expert. Don't worry, just start slow and try various things.

The first thing to try is serial debugging.

The USB cable that connects the Arduino to the PC acts as a serial link, so if you have a serial terminal on the PC you can see what information the Arduino is sending. On the Arduino side, if you use Serial.print("Something") then "Something" will appear on the PC terminal. What this means is that you can send information from inside the program about what is going on.

If you are using the Arduino IDE then there is a button at the top right (looks like a magnifying glass). It opens a serial terminal so you can see what the Arduino is sending back. The only thing you need to do is set the baud rate to match the value set in the Arduino code, which in this case is 115200.

If you do this and the Arduino is connected and running, you should see a couple of messages. You can look at the code to see where they come from.

First, it should say "Start". Next, the code checks for the PCF chips. You shouldn't get any error messages except for "pcf_2 could not initialize..." and "pcf_2 not connected", because you don't have a third chip.

After that you will probably see a bunch of debug messages that change when you change various switches.

If you can do that then the next step is to add some code to tell you what the PCF chips are doing, which I can help you with.

Do you have a schematic or wiring diagram for what is connected to the PCF chips and how they are connected?

 
Title: Re: PCF8574 I/O Extender Board Problems
Post by: iwik on February 05, 2024, 11:10:06 PM
Hi Andrew,
Thanks for replying.I tried the serial thing but got nothing.I expected to see what you were saying.I could follow that bit of the code.
Anyway i found by hacking out any code that refered to I2C_IF-USED and placed Wire.begin(); just after Pinmode statement my switches worked fine.
However i have moved on from using the arduino skectch.The developer has written the firmware in VScode and incorporated the switches and so no further help is required.
Thanks and i have to say ive learnt more about Arduino code as result.Along with you explanation.
Les
Title: Re: PCF8574 I/O Extender Board Problems
Post by: ame on February 06, 2024, 01:02:58 PM
Excellent. Glad you got it going.