today's tinkerage is accompanied by a red planet Rocketeer Red Ale from dastardly villain Brewing
who declare themselves to be the makers of beer flavored beer hidden among the steampunk themed
description on the back of the can they uh they describe this beer as a malt-focused beer with
hints of toffee caramel up front and balanced with a roasty dryness and grainy biscuity character in
the Finish well that's nice but that's not the main event the main event tonight is checking
out these PCF 85748 Channel mux chips that I got in a recent mailbag these are as the description
suggests an i squared C interface chip that gives you eight uh digital in out ports which can be
used to expand the number of digital i o you have on your microcontroller and as far as I can tell
they should be able to communicate with pretty much any type of microcontroller as long as you've
got a library for it and Arduino has a library uh so does Micro python a couple of them actually so
that's what I'm going to be doing today just getting my feet wet experimenting just a little
bit to see how easy it is to make these things get up and dance might as well start with a data
sheet just to see what we've got here as we already know from the description I mentioned
earlier the input input output expander that communicates over a two wire I squared C bus
runs anywhere from Two and a half to six volts so you can run it directly off the 3.3 volts of the
ESP type chips or off the 5 volts of the Arduino style chips cool there is the basic block diagram
we have three address lines for a total of eight addresses so if you load up the I squared C bus
you can have 64 digital I OS available to uh play with one thing to note is this thing syncs current
on the load side it doesn't Source current which means you have to have your load between the pin
and VCC and you can do up to 50 milliamps per pin you cannot use the sync to supply voltage
so if you want to connect your load to ground in a pin it's not going to work it's not going
to be able to supply that so you need to have positive as your comment on your load side that's
the one big gotcha on this chip and it's not a huge deal but you just have to keep it in mind
but you can drive 50 milliamps so that's a few LEDs or a few opto isolators or a ridiculous
amount of transistors and there it's just reminding you of that again your load needs to be
between the pin and VCC not to ground so there's a pinout and block diagram of the whole thing
the i o is on pins 4 through 12. uh VCC is on 16 and ground is on eight it's a 16 pin
dipped chip there is an interrupt output if you choose to use it and a few of the
example sketches use it but I don't know that I'm going to play with that I'm just
going to use it without having to worry about thinking about interrupt handling and all that
anyway there is the three address lines there is the Sarah clock and serial data of the I squared C
and here is what goes on inside it basically just control logic and shift register going to the i o
pretty straightforward I don't know if we need to go through the rest of the 45 pages of this uh
data sheet I can link you to it if you really care to so here is just a fairly
basic circuit on on the breadboard there's the chip there we've got power and ground
I got the sco and SDA pins on 14 and 15 there these three are address pins I've just got them
all pulled low and that gives me a base address of 2 0 or 20. I guess it's two zero hex and if I send
them all high that will give me what two seven I guess for a total of eight addresses but I'm just
going to stick with uh all well I'm not sure if they have pull-ups or pull Downs internally but
I'm just going to force them so that I know what it is and then I've got one lonely gpio connected
to an LED that led through a resistor to the positive rail to VCC and using an example from the
Adafruit Library yeah as I mentioned there are a few libraries for this but I grabbed the Adafruit
one just because it has the cleanest examples to play with we have the include for the library we
have the library call and Define an object called PCF could I call it anything but that's what it is
um this is just some niceties which is actually useful for troubleshooting especially this part
right here because it will show you on the serial console if your I squared C isn't connected right
or if the Chip's not talking or something like that so that's cool We Set uh pin 7 to an output
just like standard gpao stuff in Arduino and then the loop quickly blinks it that's all
there is to this sketch and when we Power It Up the LED starts blinking as you would
expect it to not very exciting but that proves that I've got the wiring connected right and
everything is uh is working just happily let me expand this just a little bit so here
is basically that same sketch only copy paste expanded a whole bunch with a Twist put into it
so first of all we have seven of the eight pins set to Output now and we have pin zero
set as an input with a pull-up resistor so I am going to connect a switch to that and well
let's see what happens here if the digital read of zero which is the switch equals zero IE a low
um which is not pulled up anymore then we will run through and blink all seven of the LEDs
and then come back up here and just wait for this to go to zero again
here is that wired up uh pin zero goes to this little pushy button here and
the rest of them go to seven LEDs with the resistors all going to the high rail
just like I promised it would which amazes me as much as anyone because well programming ain't my
forte I'm sure you've heard that before if you've been hanging around this channel long enough so
that's basic Arduino with it let's try uh Pi Pico and see how that works because that will be using
micropython and as it turns out for the pipe Pico well for actually any micro python device
so any of the ESP boards as well there are a couple of libraries available for this 8-bit
I squared C expander this particular one seems to be the easier one to deal with or at least
it's the one that I found easier to deal with your mileage may vary anyway I found a bunch of
examples for it online that's probably what made it the easiest so that's the librarian as you can
see on my Pi Pico I've got it already connected or already uploaded and then this main comes from
a few examples that I found online and then my body so we import the library we import I squared
C and pin from machine we import time just to get it all set up we Define the I squared C
on I squared c number zero so on the pi Pico and you know any uh rp2040 device there are multiple
places where you can pick up the I squared C bus I chose to use the one that's on pins 11
and 12 and that's what the example used so just to make it easy on myself so then we Define up
the PCF object that we'll reference further down in there tell it that it's I squared C and then
its address is hex 2 0. and again I'm just going to use the Base address of the thing because that
makes it easier anyway so uh here is the basic Loop the oil Loop that is a micro python thing
um it seems this Library seems to address it just as a an 8-bit uh bit mask or port so by
setting the output ports to FF that is basically a binary one one one one one one one one one one
um it goes to sleep for half a second and then it sets the port oh and then it prints just on
the monitor down here the port and then it sets the port to zero zero so that's all eight zeros
and then it does a few different patterns and turns them on and off and goes to sleep so
then we come down to the part that I wrote which is basically just copy paste and changing this
one has a uh one dark Chase so seven lit in one dark so I'm turning off bit one then bit two then
Four's place which is the third bit over and in the eighths place which is the fourth bit
over in binary right and then one zero two zero four zero and eight zero so that chases across
and then I do it the other way around with most of them dark and only one lit and if you go and
look up these hexadecimal values in binary you'll see what's going on but basically it's a bunch
of ones with a single zero in it remember we're pulling the port low to turn on the LEDs so that's
what's going on here that's why it seems a little backwards but anyway this chases through oh we'll
just look at it you'll see so here it is set up on the breadboard just as it powered up and I tell
funny to run here we go Chase Chase that's the first chase that I wrote there is the second chase
that I wrote and then we'll go back to the two that came with the example that alternating blink
and away we go again it just does that forever so that's pretty straightforward um oh yeah the other
thing that's happening on this let me just go into the series The Monitor up in this first little bit
it is printing out to the monitor down here what the value it's reading in the port is and that's
what's going on down here it's only doing it for this first handful you can see them changing
as it runs that part of the script so after I write FF it reads it back and that's the 255
then I write 0 and it comes up with zero then I write a a which is uh decimal one seven zero
and then it writes 5 5 which is decimal eight five so if I wanted to read inputs instead of
uh instead of setting outputs I would just have to reference that in my if statement or in my
read statement whatever I wanted to use and do the math to figure out what the binary bits are
relatively straightforward a little bit more math heavy there's probably
easier ways to do it but this seemed fairly intuitive to me when I found that Library
and just for fun I soldered up some pins on one of these smaller rp2040s that I got in a
mailbag a few weeks ago let's just quickly connect him up and I've dropped that same
a piece of code onto there as a head running on the pi Pico so let's just see what happens here
well there we go as expected it's doing exactly what the program is telling it to do cool
so these little pie rp2040 boards do a pretty good job in a tiny little form factor
although I don't mind this with this breakout board either
good to have options and of course you could use that same micro python setup on any of
the ESP boards right up to esp32 as an example I compiled it for unexpected makers tiny Pico and
it came out just fine so it should work on any of the esp32s for uh using the Arduino libraries
as well if you prefer that over micropython all in all a fairly competent little chip
um and I think one that will come in useful in the future especially having a bunch of them can
you imagine having 64 extra gpos hanging off a board I think that could be really useful anyway
um let me know what you think about this down in the comments have you played with this chip
before is there a better 8-bit gpao expander for cheap that's available out there that I
don't know about yet let me know thanks for watching I will talk to you later