Add Analog IO to #RPi with SpazzTech AD5592 Snack Board

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I'm going to show you how to add analog input output capability to Raspberry Pi using a new product that I have available here the 85 592 snack board and this is basically a breakout board that allows us to add analog capability to any device that has super interface and we'll talk a little bit about it in this video here so let's go ahead and get started that first of all a lot of our past videos have focused mainly on the software side in this video we're going to be dealing with some hardware sir some things are going to need to follow along first of all and growing need a basic understanding of fundamental electronics components and if you find at any point during this video that I'm talking about things that you don't not quite grasping please send me a comment I've debated on whether I should do a series on basic electronics or not if you'd like me to do that let me know and I'll do a series on basic electronics so everybody can follow along in the meantime if you find yourself getting lost on some of the stuff we're talking about with the hardware check out at the web site comm I've got some basic electronics tutorials on that website there you might might bring you up to speed and what we're doing here next we're going to need a Raspberry Pi of course in your Cologne you need to get yourself less fast tech eighty five five nine to snack board and that's just just available as I'm making this video so go ahead and get yourself one you're also going to need assortment of jumper wires and some LEDs a couple of two or twenty ohm resistors and also decoupling capacitors and potentiometer or some kind of analog sensor that you can use to give an input to the analog inputs channels and then you're going to need a solderless breadboard and then optional I for troubleshooting you might want to have a multimeter or oscilloscope if you have one available not absolutely necessary but if you it helps out with troubleshooting if you have run into issues okay just a little bit about the 8592 snack board first of all the reason I did this is that you know there's in some of the modern electronics that are coming out now that the chips are getting smaller smaller and with a lot more capability and but if you want to even try to thing you need to basically design your own circuit board get it fabricated assembled and then and then you can try it out to see if you like it so I'm I'm taking those first few steps they're out of the loop here and offering this is just a little breakout board so you can try out this little tiny but capable chip with your project and so so this on this one little tiny chip we have available to us eight configurable IO channels we have a 12 bit ADC so that would provide our analog inputs we have a 12 bit DAC so that's digital digital to analog conversion or so so we have an analog output capability there and or we can configure depends as digital inputs or outputs so any one of the eight channels can be configured as any one of those things over to serial prefer interface which on this device can be up to 20 megahertz in this example we're going to be using a 15 megahertz clock on our spy but you can run it up to 20 megahertz I've actually run up to 30 but that might not always be possible another advantage of this particular chip is it has a separate logic and reference voltage inputs so what that means is a lot of a lot of devices out there including the Raspberry Pi their logic level is a 3.3 volt logic when you're dealing with sensors in the outside world a lot of popular sensors they're really looking for like a 0 to 5 volt output so this particular device allows us to provide the the chip 5 volts and provide 5 volts to the the voltage reference but also then give 3.3 volts to the logic input so that allows us to use 3.3 volt logic with a zero 5 volt analog signal input so so that's an advantage of this of this chip over some of the other ones out there also I've put together some sample code and see it's available on github at the address right there and you're you're welcome to use that however you like and we're going to use that in this video here and it's also this is available with or without the pin header so if you want to solder wires on to it get it without the pin headers you can solder your wires in it this this picture here showing it with the pin headers in place and it now allows you to stick it into a solderless breadboard and then just use jumper wires to to work with it or you can use jumper wires directly to the pin headers so listen this is just kind of like the high-level overview of how we're going to connect this thing and I'll show you a picture of it actually wired up here for this project just so when you you put this if this head pin headers and we put down on us our breadboard this would be decided we'd be looking at and I'm just going to go down the list here we have our ve D so that's where we want to supply as the the voltage supply and in this example we want to tie that to five volts then we have the the sync line and you see the the line over that means that it's active low so when when this miss pin is low the device is active when it's high it's inactive so we're going to tie that to our ce0 line on the Raspberry Pi and then we have our V logic input and this is what we're going to this is what we're going to going to tie that to 3.3 volts because the serial peripheral interface of the Raspberry Pi runs at 3.3 volt logic so we want to tie that to 3.3 volts the voltage reference Revere F we want to also tie that to 5 volts and and one one note here is that that the V reference cannot be more than VDD so so if we want to use zero to five volt we need have EDD tied to five volts and that's why we have it there another thing to note on V references that would be best practice to put a capacitor close to that so that we have a nice smooth reference voltage there and we'll have that in our example I'll show it to you here in a minute next we have our s do line s serial data out so that is the serial data going out from the device and we're going to tie that to the master and slave out so it's coming out of the slave and going into the master and and there you go next we have our syrup clock and that's forced tied to the spy clock and we're going to have that clocked at 15 megahertz and then we have this real data in so this is we were going to tie that to the master out slave in okay ground has straightforward one tied at the ground and then we have our eight IO pins and they are labeled io 0 through iOS 7 and do it that way because if you're working with binary numbers and we're going to work with bit masks and stuff you know your first bit is bit 0 and so bit 0 on your bit mask corresponds to i/o pin 0 and so that's pin 0 through pin 7 right there and so those are all of our inputs or outputs however we want to configure them so let's go take a look at this in real life and I'll kind of point out where all the components are and how I have it wire it up for this particular project okay here we have our circuit all wired up on to a couple slaughters or red boards I have a potentiometer that I'm going to use for analog input and you see I just have a dial on that fuse then over here first of all here's our 85.5 9 to stack board and we have our analog or input/output pins over on this side then our power and our serial interface depends over on this side and so we have our analog input with the potentiometer I have an LED that's on pin six and going back the the analog input the potentiometer is wired into pin seven we have an LED on pin six and we have a 220 ohm resistor in that circuit that's to limit our current there should limit our current sufficiently for this particular device and then on a C on pin - I have a push-button now I have a pull-up resistor here you want to use that you can use a higher resistance resistance maybe tape 10 km or 1000 ohms it doesn't really matter and you want to have a higher resistance for this one so it's not going to use a lot of current so that will be tied to the push button so that as a pull-up resistor so basically pin 2 is at 5 volts normally and if we push the button it goes to ground and so then that would go to 0 volts and then I think it's I'm sorry that was on pin 1 on pin 2 we actually have another LED and and also a 2 hour 20 ohm resistor on that LED and that's those are only pins wired up so in review pin one has the push-button pin 2 is an LED and pin 6 is an LED and in seven we have a potentiometer which is just basically tied to between ground and 5 volts and so it's just going to give us our 0-5 volt input we could also use other sensors for that for example this is a position sensor you might use say on yeah let's just think like your foot pedal in your car is is attached to something like this - to tell the computer in car where you're putting that pedal at so so we could use a lot of different things dress sensitive in this case spring use a potentiometer and you can see this is this is all tied to the raspberry I with this ribbon cable here and this this just makes it a little bit easier to wire up for so I can give you a link to where where you can get that for yourself oh I guess I should probably cover the other stuff so you can see I have a 1 micro farad capacitor that's tied to the V reference and the both the the V reference and the VDD lines are connected to this bus right here which is 5 volts positive then we have our V logic you can kind of see it down here with this yellow jumper is tied to the 3.3 volts positive our grounds are are the same so we have our ground and put catch there and then we have our C 0 line is brought over here and it goes over to the sink input ok and then we have a master slave in going to the the serial data in pin then we have our clock line so the master in slave out going to the is shorted out pin this orange jumper here there are 3 o clock is going to the the clock and that's the green jumper here I think that's about it let's go ahead and take a look at the software ok to get started with a software regretting a few things first of all this example we're going to be using a raspbian operating system that's the the basic operating system as Barry pilot that most folks use give the link here we're also going we're also going to need the BCM 2835 library that's going to provide us the low-level code that's needed to interface with the serial peripheral interface of the Raspberry Pi if you don't know how to install that I have another video on installing libraries and I install that in that video I'll go check that out I'll provide the link below and that works on I've tried that on the Raspberry Pi B+ or pi2 and on a Raspberry Pi 3 it work doesn't work the same even though it's actually a different chip other than the BCM 2835 it still works on or as break by three and then you need to go over to my github page and get the source for the 85 592 our our PI dot H and our PI dot C and that's available right there on github let me show you that real quick ok here's a repository on github I basically need to get these two files here and so you just click on those and if you're if you know get and you can and you can go get those those repositories that's fine but you can also just go in here and copy and paste this so if you if you don't know how to use git you can just copy this and paste it into your your project and that should work just fine for both of those those files so you'll want to grab each of those and as of this recording we're using version 1.0 point 1 for both of those if you if you're using an earlier version check the notes and you'll get to see what the differences are between the different versions there so try to try to capture what I change from version to version ok once you have all those I there's a few things that we need to know about the the source files that I'm providing you there's really only six function calls we really need to worry about to use the basic functions of the 85 592 snack board those six functions are the 85 5 9 to underscore init function and that function is just going to basically initialize a spy it's actually going to be accessing the 85 5 I'm sorry the BCM 28 35 library and initializing the serial interface and setting it up to use with the Raspberry Pi and I'm sorry use the reading up the super interface to the Raspberry Pi use the 85 5.92 and so that's gonna actually give us our clock clarity and our sink line polarity for that device it's also going to set the clock at 15 megahertz next we're going to want to use this set 85 592 channel function and we're just going to pass which channel we have the device connected to so we have a cs0 line we have cs1 line then this example we're going to be use and you see s0 line so we'll pass a zero to that function so so it knows that we're connected to the sea s0 line then then the next four functions are all the the the pin functionality that the device has so we have analog in so that's get analog in and then we just pass an integer value that represents the pin number so that's a that's a number between zero and seven inclusive so passing number zero seven and I'll get and I will change what that function will do is it's going to change that pin to an analog input if it is already configured that way and then it's going to read the analog input and return it the next function is a set analog out and that and that function requires to two arguments that we need to pass to it we need to identify the pin that we want the analog out to go to so that's the same as the analog in so we want to do a number between 0 and 7 to identify which pin we want to analog analog out and if it's not already configured as analog out it'll do that and then it will will set that pin at a voltage level that is equivalent to that millivolts in output now this is assuming 0 to 5 volt configuration so just just note that that as assuming 0 5 volts and in a future video I'll show you how to reconfigure that in the next function is the get digital in and in this is a little bit different we're not we're not going to identifying a single pin we're passing a bit mask to identify all of the pins that we want to read so we might have if we want to read all of the pins all of the bits and that 8-bit data is going to be are going to be once so if we just want pin 0 we're going to pass a 1 what pin 2 we're going to pass is a to a pin 3 we're gonna pass a 4 and so on and so that's a bit mask going to digital in and then oh it'll return a bit mask of what all the digital input pins are set to 0 being low one being high the next function is then the set digital out and in that case we need we need two arguments we need to identify which pins we want to be configured as digital out and then we need to pass a variable that is a bit mask identifying different states of all those pins so so that will do that there so what that'll do is if the pins identified are not already configured as digital out it'll configure them as digital out then it'll set their States to the bit master you send to it so let's go ahead and look at an example of how to use these in action ok here we are on the Raspberry Pi I have a program started in geni just a single source file now if you are are all up to speed on on using make files and and build configurations like that then you can use those those helper files the the 85 592 R PI C naught H on their own and you can you can set that up but if you're just getting started that can be a little bit complex so you have the option you can just bring all of that source into your single file to make us the simplify things and what you're going to want to do is above your main function you want to include all of the code that's from the 85 592 our pH so everything in the dot H file you want to copy and paste into the your source file above the main function like I've done here and that's all the source that I just showed you on github okay and then after the main function so down here after the main function after this closing curly brace after main function you want to include everything from the dot C file that I just showed you on github and and you could just copy paste that down below and then then you can access all that without having to create your own make file and build configuration on here nicolas let's just go over the example here had a first like i said the first thing you want to do is call that eighty five five nine to underscore net function and doesn't take any arguments then we're going to set the channel and and there's a there's a pre compiler definition that is channel 0 so that i just said at the channel zero there down here we're just using there's a few variables I have a eight unsigned integer 8-bit of that variable called button are going to use that to capture two digital inputs I have millivolts variable I'm going to initialize that at 2500 so it'd be 2.5 volts and then I'm going to use the that get a timestamp in and you can I have another video on timestamps and file IO that you can go go look at if you like if you want to find out how how do you use those but then i i'm sending me up to two variables an old time and new time is basically every time this thing loops its gonna check to see of the time incremented and at the time incremented then it's going to toggle one of the digital i/os to blink an LED so that's what that is and so I have a variable here that I'm calling blink bit and just setting that to zero and then here's the main execution loop of the program it's a do-while loop so you can go look at some of my previous videos on what a do-while loop is but essentially what's this going to do is going to execute all this code once and then it's going to check the condition and the condition is is button equal to a hexadecimal 0 2 and especially what that that's that's doing is it's checking to see if the button is equal to basically channel 2 of our our device hat sets in a high signal and I remember the push-button that we had in that circuit is connected to channel 2 so and it's an have a pull-up resistor so it's normally going to be high so it's going to have a 1 in that position and it'll give us a hexadecimal of 0 2 alright so going down through here first of all we're going to use our get n log in function and we're I remember we had our potentiometer connected to channel 7 so we're just going to pass a 7 there to grab the analog input from that channel and we're going to pass that to the millivolts variable and this analog in and it will will return a millivolts value based upon an assumption that you're using a 0-5 volt reference okay and I'll show you in a future video how to reconfigure that next we're going to set the analog out on channel 6 remember Channel 6 is connected to an LED with with a resistor and we're going to set that equal to the input on channel 7 so we're basically going to pass the millivolts variable to that that function and now it will then so basically what it's going to do is when we turn the potentiometer it's going to change the input voltage and then it'll make the LED brighter or dimmer depending on what that that put that voltage is next we're going to go ahead and get it time stamp and and then we're going to check to see if the time changed and the this setup here is just it's only going to increment once per second so essentially this this section of code is going to execute once every second so what we're going to do is we're going to take our blitt blink bit and we're going to use the X or a bit op bitwise operator and you can go look at one of my previous videos and bitwise operators to find out how that works and we're going to pass it this precompiled definition that's included in that source that I just gave you basically is going to toggle the bit that that corresponds to channel two of the device which is then connected to an LED on the output and so we're then we're going to pass that blink bit to the set digital out function and then that's going we're going to use that bitwise or I'm sorry we're going to use that pre compiler definition of eighty five five nine to underscore IO to IO to for channel two and then we're going to pass that blink bit variable which is going to be toggling that that bit that corresponds to that channel between a 1 and a 0 which will blink the LED so that should blink the LED on one second off one second next we're going to check if our buttons press so we're just going to get digital in we're going to use the get digital end function pass it the pre compiler definition as provided in the source and of 8559 to underscore IO 1 and that's just going to read the value whether it's high or low on D on the digital input on IO 1 okay and then we're going to assign that to button if that button value happens below it means the buttons been pressed and then this button is equal to 0 0 2 that will be false and then the loop and then will be done in their program so from a high level what's it's going to do it's going to read reading the analog input from the potentiometer it's gonna set the voltage going through one of the LEDs to that to match that analog input so it'll be a dimmer basically then as every once every second it's going to blink one of the the other LED with a digital out is I'm going to check the digital in to see if the buttons pressed and if the buttons press is going to exit the program otherwise it's gonna keep on looping okay so let's go ahead and see this in action I'll just go ahead and I've already built a compiled and built this but we'll go ahead and run it and it pops up and I'll go go the other camera to show you what it's doing okay here we are with the program running you can see we have an LED blinking and that's blinking on one second off one second just like that we showed you code and then we have potentiometer here and and if we turn this potentiometer it's gonna change the analog input which will dim or brighten this LED right here so we go ahead and change that and you can see we can make that led dimmer or brighter depending on where we position LED so what's happening is that the device is reading the analog input from the potentiometer and just changing the analog output to change the voltage going through the LED which also changes the current it makes it dimmer or brighter okay and so that we have the analog input the analog output with a digital output here blinking this LED and then if we if we push the button that'll be our digital input and that will actually stop the execution of the program so we go ahead and press it they see the LED stops blinking and this this will just stay where it was that for right now and this in this particular program but that's it that's how this works so that's about it for this video but what we have coming up next is in a future video we're going to take a deep dive into the source files that I provided and that I used in this video so in dig into all those functions and how they work so that you can customize them for your needs we're also going to do a Raspberry Pi data logger video and so we're going to use the 85 590 to snack board with the Raspberry Pi to create a data logging application we're also going to go over using the 85 592 with the kinetise sdk 2.0 library that's for the kinetics of devices and then use the freedom k 64 as a data logger as well and so I hope you like this video please subscribe check back soon and like it if you liked it and we'll talk again real soon thanks a lot bye
Info
Channel: SpazzTech
Views: 2,077
Rating: undefined out of 5
Keywords: Tutorial, Raspberry Pi, RPi, ADC, DAC, AD5592, SpazzTech, analog, GPIO, SPI
Id: jSnT0_RSBUk
Channel Id: undefined
Length: 29min 42sec (1782 seconds)
Published: Fri Dec 23 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.