Placeholder Image

字幕列表 影片播放

  • please go to the line the computer guy dot com, in order to view schematics, code and Maur for the projects that you are learning about.

  • Welcome back.

  • So in this video, we'll talk a little bit of, um, or about the eye to see or the I squared PSI Communication protocol in regards to our Dino says, This is an amazing little protocol that allows you to communicate with multiple different electronic devices using simply two wires coming off of your art Ueno board.

  • But the only issue with the eye to see protocol is that it's an addressable protocol, which means every single device I to see device or going to connect to your ID we know is going to need an eye to see address.

  • Many times, those addresses are hardwired into the dip.

  • Advice that you've purchased, and one of the problems you can run into is that you simply literally don't know what the hell the address is.

  • It's kind of like putting a D a C P client on your network and then not knowing what I p address, it was able to pick up a big problem that you can run into it I to see is you connect the eye to see device, but then when you go to try to communicate with it, you don't know what address that that device has, and so therefore, you're not able to connect with it.

  • So what we're going to do today is we're going to create a sketch that allows you to scan for I to see devices that are connected to our do we know.

  • And it will output the hex address for those devices so that you can plug that into whatever sketchy you're going to create with your eye to see devices.

  • So with that, let's go over the work bench so I can show you how this particular project was put together.

  • Then I will show you the sketch and bring it all together and show you how it works.

  • So I've put this little project together to show that you can scan for multiple eye to see addresses at the same time.

  • So this is a 20 by four eye to see LCD screen, and this is a little eye to c o l E D screen.

  • I've connected both of these to the artery.

  • No, essentially to the bread board.

  • Now again, it is important to understand when you're dealing with eye to see that more or less you're just using to communication wires in order to communicate with the Arduino.

  • So I have these two communication water wire.

  • So a four and a five those air then come into the bread board and then on the bread board.

  • I am simply splitting them out in order to connect to the 20 by four LCD screen and the led.

  • So, basically, both of these screens are sharing both the V, C, C and the ground, and they're sharing a four a five.

  • And this is what makes eye to see so nice.

  • As you can see, I have these two devices connected to the Arduino, and for all of that, I am simply using to analog ports.

  • So I've done it this way.

  • Do you realize if you simply need the address for one device, you could simply connect that one device directly to the yard?

  • We know and then run the sketch that I'm about to show you, and it will show you the address for that single device.

  • But I do want to show you that both devices can be connected at the same time, and you can scan for multiple addresses at the same time.

  • So here's a sketch for the eye to see scanner.

  • Relatively simple.

  • So the first thing that we need to do is we need to include the wire, a library, the wire 0.8 library, and this is included with your artery.

  • No, I d e by default.

  • So you don't need a download or install that you just simply include that there.

  • The next thing we need to do is we need avoid set up the environment that is going to run in, and the first thing that we need to do is wired, not begin.

  • It's basically begins the wire service.

  • So we need to do that.

  • And then we will be using the serial monitor to view the output.

  • So we need to do cereal that began that 9600 with that we set up our environment from they were just going to go down.

  • We're gonna go to the loop and we're going to try to figure out what addresses we have connected to this particular aren't.

  • We know.

  • So we're gonna need to create to variable are three variables.

  • To begin with, we're gonna have an end for error.

  • So if there is an error from any of these eye to see devices, we need to be able to see what that is.

  • We're going to create an end for a dress.

  • So for the address we can have up to 127 and basically what's going to happen with this particular sketch?

  • Is it simply going to iterated through all the possible addresses and see if anything is connected to any of those addresses?

  • So it's basically going to loop through its eye for a loop.

  • So it's going to start at one, is going to increment up to 127 and basically all that's going to do is see if anything is connected to those addresses.

  • So we need an inter variable for the address, and then we need an EMT variable for devices, and we're going to simply set that to zero.

  • And so basically, what that's gonna be used for is if no devices, air found, we need something to print out to literally say no devices have been found.

  • We're gonna create those variables and we'll set devices to zero.

  • The next thing we're gonna do is cereal that Francis will be putting out to the serial monitor serial dot print line and devices found Colon.

  • So basically, just gonna print out devices found.

  • And then underneath that, if devices were found, it will tell us what the address of those devices are.

  • They were gonna come down here, and we're going to do a four on a loop for address equals one.

  • So we're going to start the address at one address is a less than 127 because you go up to a total of 127 with eye to see address, plus plus add one to the address.

  • So it's gonna look at address number one and it's got Luke.

  • It's gonna do this.

  • Luke was gonna go to to do Lupin going three and 45 and six and seven all the way up Thio 100 and 26 on.

  • Then it will drop out of the loop.

  • Then what we're going to do is wire dot begin the transmission at the address given so begin transmission at one.

  • Right, So at 123456 So on so forth, then we're going to have this error.

  • So error equals wired dot, end of transmission.

  • So basically, when when the Arduino communicates with the eye to see device, it's going to respond back with a code, and so were simply calling that code error.

  • So if error equals zero so basically, if the code back from Wired in transmission equals cereal zero, then we're going to print out the address for the eye to see.

  • Device Zero means there's something there, so the first thing we're gonna do is cereal, not print print zero X Then if address is less than 16.

  • So if this address here while it's under 16 it's going to zero X and then sealed up print another zero.

  • So if it's under 16 the reason is, is when you turn numbers under 16.

  • So zero through 15 in the hex, those air single characters you're going to be receiving back and so you want a double character for this.

  • And so you're gonna be adding that extra zero to give you a double character.

  • So zero x zero f or something like that.

  • Now you'll notice there's no semicolon here.

  • So with the if so, if this, then this just continuously happens.

  • Otherwise it just breaks out.

  • Keeps going down.

  • Then we're going to do is cereal about print line.

  • So this will print zero X whatever, and then it'll print this out and go to the next line.

  • And what we're gonna do here is the address.

  • So the number for the address, but doing this, it formats it in hex.

  • It's got format in hex, so we're going to get the hex number for whatever address it is.

  • So if it's 22 we're going to turn 22 into a Hexi decimal number to be able to print out, and it'll be zero X and then whatever the hex decimal number is, then we're going to do devices plus plus.

  • So we're on.

  • Add one advice.

  • This plus plus else if if error code comes back to equal to four, what is going to do is, say, is on unknown error at the address.

  • Zero X, again, if the addresses under 16 or a print another zero and then zero print line address in the hex format.

  • So zero x two F or something like that.

  • That is what will get printed out there once it goes all the way down, if devices equals zero.

  • So remember, we have this device plus plus, So every time this looks through, it adds the number of new Isis.

  • So if it zero so we set it to zero here, it doesn't find any addresses.

  • While that's going through this for a loop, then it will see area simply serial dot print line.

  • No, I two devices found.

  • Then what it's gonna do is going to delay for 5000 milliseconds five seconds and then it will loop through again.

  • Now, this is dynamic.

  • If you if you switch around the wires while this is looping, you can you can see the changes so you can have devices drop off for devices.

  • Come back on.

  • If if you screw up in the SD a wire or the S C.

  • L wires in the wrong position, you can swap those around.

  • And so it will just keep looping, looping, looping, looping.

  • So let me upload the code for this, and I'll show you how this works.

  • Okay, so I've uploaded the sketch to the art we know we can see the 20 by four Spring is on.

  • There's no real indication whether or not this screen is plugged in, so we'll just simply have to go to the serial monitor to see if we are getting any addresses.

  • If you go to tools, you go to serial monitor.

  • We should start getting something.

  • So we got devices found, and so we have one device at zero x 27 and another device at zero x three c.

  • So we know these are the addresses of these two particular device is now.

  • The one thing that I will say is you're not sure which one is weak.

  • Is this 27 or is this three c you don't know?

  • So that's one reason if you don't know the address of a particular I to see device, you may want to plug these in individually, but this just kind of shows you that both devices can be plugged in and communicated with at the same time again, just using these two little wires here.

  • So that's really all there is to this particular project and sketch, and it will make your life a hell of a lot easier being able to find those addresses simply by running a little sketch like this.

  • So there you go.

  • That's how you scan for I to see or I squared Psi addresses again.

  • These air, these air, great little devices to be a bit connected.

  • Or do we know it's a great way to connect a lot of different devices using only two wires?

  • The problem being though the problem being is, you may not know what exact address your device is, and if you don't have some way to scan for it, they may become a real problem again with these eye to see devices, some documentation for these devices is great, and some documentation with these devices is horrible.

  • So if you're sitting there and you know you bought something for half Price because you thought it was gonna be such a great deal, and then you find out, Oh, I have no idea what the hell the address for this thing is.

  • Using this little guy to see scanner can be a real life saver.

please go to the line the computer guy dot com, in order to view schematics, code and Maur for the projects that you are learning about.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

A2 初級

在Arduino上查找I2C地址(I2C掃描器)。 (Find I2C Addresses on Arduino (I2C Scanner))

  • 10 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字