PCF8574 I2C GPIO Expander Tutorial

  Рет қаралды 36,310

Gadget Reboot

Gadget Reboot

Күн бұрын

Getting familiar with using the PCF8574 GPIO Expander with Arduino, including using it as outputs, inputs (polled and interrupt driven), addressing multiple devices on the same bus, and limitations on using this device.
Related: I2C bus expander • TCA9548A I2C Multiplex...
For when you have multiple devices with the same address or you want to use more modules than the bus allows because you run out of addresses. This allows switching different chains of devices onto the main I2C bus.
Arduino Sketch:
github.com/GadgetReboot/Ardui...
Support me on Patreon: / gadgetreboot

Пікірлер: 39
@popcappsproductions
@popcappsproductions 3 ай бұрын
It's not often I feel like I understand less about what I'm doing after watching a well put together tutorial. Sheesh, I am NOT grasping I2C
@UDoIt2
@UDoIt2 4 жыл бұрын
I love this video! I've been in embedded systems for a long time. Great stuff!
@peachville4383
@peachville4383 5 жыл бұрын
Excellent work! Code works right out of the gate with Nano too as IC2 uses same SDA and SCL pins (A4 & A5) as UNO.
@crckdns
@crckdns 5 жыл бұрын
Clear explanation, useful! Thanks!
@denbeibaron7797
@denbeibaron7797 2 жыл бұрын
Thanks a lot for this video. The clearest one among others that explains the work of Arduino with I2C ... down to code level.
@bebhavs
@bebhavs 2 жыл бұрын
So well explained spacely the corner case for pull-ups in ||.
@electronic7979
@electronic7979 6 жыл бұрын
Useful project
@mauriciokarpf4126
@mauriciokarpf4126 3 жыл бұрын
Excelente el video, muy bien explicado
@nikhuge6580
@nikhuge6580 Жыл бұрын
can we control a speed of a motor using i2c expander
@blendgashi6437
@blendgashi6437 Жыл бұрын
Where can I found this datasheet?
@gameisrigged6942
@gameisrigged6942 2 жыл бұрын
Where are the resistors, and why not use shift register
@eduardodanielramosmendoza7566
@eduardodanielramosmendoza7566 2 жыл бұрын
Hi, my question is, trying to simulate the project in proteus a fault occurs, could you tell me how to connect the circuit in more detail?
@incognito827
@incognito827 5 жыл бұрын
Have you measured these expanders standby current consumption?
@GadgetReboot
@GadgetReboot 5 жыл бұрын
Not yet but I added it to a to-do list to investigate. Maybe I will add the information to some sort of mini update video where I revisit some old issues or discuss upcoming things.
@lifeonagriculture3330
@lifeonagriculture3330 Жыл бұрын
@@GadgetReboot Yes, this will helps really.
@ManuelCastillo-kq3xy
@ManuelCastillo-kq3xy 5 жыл бұрын
Hi, howdo use one extented and each gpio one by one. I need use por 8 relays module. Please, help me.
@GadgetReboot
@GadgetReboot 5 жыл бұрын
This project should help: geek.adachsoft.com/home/article/id/21/n/How-to-use-ESP8266-with-PCF8574-4-input-and-4-output/refid/it#software I found this once when I was looking for some research. It’s a wireless interface to individually control some relays so the source code has routines like SW_on SW_off SW_toggle. Those show how to manipulate just one thing on the eight pin expander by reading in the state of all pins, changing just the one of interest, then writing it all back out so everything is preserved.
@djluchocrescente
@djluchocrescente 3 жыл бұрын
Hello, excellent tutorial. I need to read the status of 150 buttons. Is it possible to cascade 19 PCF8574? The project is with Raspberry pi 3 b +
@GadgetReboot
@GadgetReboot 3 жыл бұрын
A PCF8574 has 3 address pins allowing up to 8 on a single bus for 64 IO pins, but then an I2C bus expander like this kzfaq.info/get/bejne/fM1zjMaA17fSmKM.html can be used to allow multiple busses, each with up to 8 PCF8574 on them
@mattiaiezzi9381
@mattiaiezzi9381 2 жыл бұрын
I suggest you to divide it into a matrix (for example a 12x13 allows you to read 156 pins), so that you only require 25 pins, which means 4 PCF8574 should be enough
@browaruspierogus2182
@browaruspierogus2182 6 жыл бұрын
Can you control 64 leds with 2 x 8bit expanders?
@GadgetReboot
@GadgetReboot 6 жыл бұрын
It would seem like you would still require some kind of extra chips or driver transistors like an 8 x 8 matrix or an address decoder like taking three inputs and turning it into eight decided outputs. For a matrix I’m not too familiar with how those LED cubes do it or even general keyboard input matrix circuits but if one side of the matrix is sinking while the other one is sourcing, that’s where this particular unit would need some extra help. I don’t know if having just external pull up resistors to help source current would be enough and then there’s the whole Matrix ghosting thing where if it’s not done properly if you try to activate three sides of a square, the fourth side gets phantom activated. So I think it would be fun to look in those LED cubes and see exactly what they do because I believe those are the most efficient way to get the maximum usage out of minimal GPIO.
@browaruspierogus2182
@browaruspierogus2182 6 жыл бұрын
Interesting
@GadgetReboot
@GadgetReboot 6 жыл бұрын
Maybe 2 expanders plus 4 more Arduino I/O can do 64 like this: kzfaq.info/get/bejne/gZljlbWgl9qtiZs.html
@GnuReligion
@GnuReligion 6 жыл бұрын
Congrats, looks like you beat your issues! The best use of a PCF8574 is for input, rather than output. One of my 5x7cm perfboard projects has an I2C OLED and a PCF8574 connected to 5 buttons in a cross, and plus a rotary encoder (left, right, push==3 more buttons). In this way, you can display output, navigate menus, and rapidly twist in a value, all with two i2c data lines. The speed of the rotary's turn is calculated to accelerate, so high values will not require a whole lot of twisting. If you must have symmetrical drive output with a PCF8574, an octa-buffer is the thing. 74HC14's may be cheaper. If you are just driving a LED matrix or a bunch of 7-segs, the 74HC595 shift register is superior. Inexpensive, chainable, good at sourcing current, and fast. You can use the AVR native SPI bus to "shiftout()" data to them.
@GadgetReboot
@GadgetReboot 6 жыл бұрын
Yeah I saw an LED cube schematic using 74HC595s as part of the mass control infrastructure. After all the learning I have done in the past two days on the expander I can see how it is well-suited for inputs. Along the way I resolved many different issues but I think there still might be a few unresolved mysteries for another day. Now I have to think about what to tackle next...
@tengelgeer
@tengelgeer 5 жыл бұрын
Two comments on the code: 1) not everything is an int ;) (yeah, I know, it's driven by all the bad tutorials and examples... :( ) 2) which can turn into a problem, variables used in a ISR should be declared volatile. Otherwise the optimizer might think the variable is never used (or at least never changed) and optimize it away. Leaving you with weird problems. And did you already try the library? Tinkering like this is good to understand how it works. But libraries just make it a lot quicker and cleaner. Because as you said, it's not the most elegant :) (tip, try to be more consistent in your code) Also note, hardware interrupts are a complete overkill for switches ;) The INT of the PCF can be useful but that result doesn't need to be checked by a hardware interrupt, polling will be fine.
@GadgetReboot
@GadgetReboot 5 жыл бұрын
Thanks for the comments! I didn’t know about using volatile. I remember I couldn’t get the library to work but if I tried again I might have better luck now after using the part several different ways. I just needed something to work. I haven’t done any coding in about 10 years so this is also kind of a re-introduction experience for me. The interrupt is overkill here but it was also to test it and if the code gets bigger polling may not be frequent enough.
@tengelgeer
@tengelgeer 5 жыл бұрын
If polling gets to slow your code has other problems ;) And besides the overkill, interrupts come with pitfalls like the need for volatile. But also non-atomic can be a problem. A good series about interrupts and the good, the bad and the ugly parts of it: hackaday.com/?s=Embed+with+Elliot%3A+Interrupts And if you have a working hardware setup, just load the library (with the right address) and it should work out of the box. And welcome back to coding! About consistency, there are multiple ways of doing it consistent but by the names of loop() and setup() and other examples Arduino it would be more consistent to follow that style. Aka camelCaseForVariables and forFunctions. And as an aid, UpperCamelCaseConstVariables or ClassNames. ALL_CAPS_FOR_MACROS (but really the need for them in C++ is VERY little). And things like pin 2 also deserves a (const byte) variable ;) Keep up the nice video's!
@GadgetReboot
@GadgetReboot 5 жыл бұрын
Thinking about consistency, one thing I did notice while poking around is the different ways people structure the use of the braces like if they are starting a for loop, some people put { at the end of that same line and others put it on the next line and it’s easy to get lost. I don’t know if there is a more accepted etiquette on that. The more I do it, the more I will figure it out. Coming from a world of spaghetti BASIC coding, any structure is good at this point.
@tengelgeer
@tengelgeer 5 жыл бұрын
Yeah, the placement of brackets is the biggest disagreement in C/C++ world :D I think 50/50 like it at the end or at a new line. I'm, like the IDE (because look at the default sketch), in favor of placing it on the same line. Because the block has a hard connection with the if/else/while/for/etc. You can not read it on it's own. But yeah, that is just style. As long as your consistent I don't mind people having different styles. But a consistent style makes it easier to read the code and also remember function/method/variable names.
Not enough Arduino Pins? Try this I2C Port Expander! | Chip Tips #1: PCF8574
7:59
MCP23017 Port Expander and ESPHome: Add More I/O Pins to Your Project
20:39
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 7 МЛН
ТАМАЕВ УНИЧТОЖИЛ CLS ВЕНГАЛБИ! Конфликт с Ахмедом?!
25:37
Now THIS is entertainment! 🤣
00:59
America's Got Talent
Рет қаралды 16 МЛН
How to Use 5 Volt Relay Modules with Arduino and ESP8266
23:03
Gadget Reboot
Рет қаралды 40 М.
Connecting Arduino with multiple I2C devices
6:22
BlueDot
Рет қаралды 190 М.
Basics of I2C on Linux - Luca Ceresoli, Bootlin
48:57
The Linux Foundation
Рет қаралды 10 М.
Add more than 100 GPIO pins to your PICO!!!!
24:49
Making Stuff with Chris DeHut
Рет қаралды 10 М.
Practical Guide to PCF8574: Adding Extra Pins for Arduino
16:46
Mario's Ideas
Рет қаралды 4,6 М.
IO Expander with I2C
14:49
nLab
Рет қаралды 11 М.
063. Setting up a DCC-EX EX-IOExpander
25:51
Model Railroading with Bill Masters
Рет қаралды 1,4 М.
GPIO Expander COMPLETE User Guide (for beginners)
5:10
RGB Engineering
Рет қаралды 4,7 М.
Why build an entire computer on breadboards?
28:43
Ben Eater
Рет қаралды 3,1 МЛН
Я УКРАЛ ТЕЛЕФОН В МИЛАНЕ
9:18
Игорь Линк
Рет қаралды 118 М.
Samsung Galaxy Unpacked July 2024: Official Replay
1:8:53
Samsung
Рет қаралды 23 МЛН
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 4,1 МЛН
Сколько реально стоит ПК Величайшего?
0:37
Hisense Official Flagship Store Hisense is the champion What is going on?
0:11
Special Effects Funny 44
Рет қаралды 3,2 МЛН