Welcome to Cockpitbuilders.com. Please login or sign up.

April 18, 2024, 08:54:58 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
87 Guests, 0 Users
Members
  • Total Members: 4,154
  • Latest: xyligo
Stats
  • Total Posts: 59,640
  • Total Topics: 7,853
  • Online today: 162
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 87
Total: 87

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

PCF8574 I/O Extender Board Problems

Started by iwik, January 11, 2024, 09:31:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

iwik

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.

ame

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?

 

iwik

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

ame


Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate