https://www.automationdirect.com/adc/home/home
(VID-BS-0001) Learn how to program in Labview with this quick example of how to re-create the temperature example shown in the merit badge book.
AutomationDirect donated time and equipment for the creation of these Boy Scouts of America Merit Badge videos.
in this video we're going to recreate the labview program shown in the meripage book i believe it's on page 30. it works like this we run the program by clicking on this run arrow right here and then we change the slider you can see that the temperature in degrees f is here and that's converted into degrees celsius over here as we pass certain temperatures we get different messages in here looks like if we pass 85 we change to a sunscreen message and if we drop below about 40 degrees f we get a long underwear message to stop the program we hit the stop sign writing programs in labview is a little different than what you might be used to but once you get the hang of it it's actually kind of fun and really easy to generate nice professional looking displays like this so let's go ahead and get started when you go to the ni.com try lab view page you'll see something looks like this click on download options and you'll see three options like this are you a professor or student are you evaluating live view or your current live view user the best one to click on is evaluating live view you'll download labview here and install it and that can take a little while so while that's happening go ahead and watch these little getting started videos right here there's short little three or four minute videos that'll give you a quick understanding of how labview works once labview is installed go ahead and launch the program you should get something that looks like this you have to get through a couple of the dialogues now keep in mind this is liveview2012. if you're using an older version like liveview2011 you might get a screen like this the bottom line is we want to find a blank vi so if using an old version it'll be right there under the new version it looks like we need to create a project which brings up a screen like this and there's my blank vi so i'll double click on him and we're ready to go what you should end up with is two windows one that looks like this we call that the front panel and one that looks like this and we call that the block diagram give me a second while i rearrange all of this and fit it on this small screen great so again on the left of my front panel on the right of my block diagram on the front panel you drop all the controls and indicators that you want and on the block diagram you wire them all together and that's your program the first thing we need is that temperature slider so let's right click go to numeric controls and i'm going to use this pointer slide right here drop it on the screen click on it to select it and i'm going to make it a little bit bigger so it's easier for us to see well that's probably a little too big there we go you have this little slider here and i want this to be red so i'm going to right click on this guy and say properties give it a second to find the properties here they are and i'm going to change that color to just a standard red and while i'm at it my temperature doesn't go from 0 to 10 degrees does it so let's change our scale a minus 40 to oh i don't know how about 150 degrees that ought to cover it beautiful okay so the first thing we want to do is display that in a text box so i right click numeric indicators and i set this empty box here grab that put it up on the screen change the name to degrees f and let's change the size of all this if i click on this and get a marquee around everything i can just change the font size right here grab the size and let's just make it something bigger like 24. there we go it's easier to see i need to repeat that for degree c so let's go right click numeric indicators grab the box drop it on the screen change the name to degree c click on the edge of the box to highlight everything and let's change that size 24. there we go it's easier to see finally i need that message box right here so i right click and i want a text indicator and i just grab a text box and drop it here grab the corner and make it bigger there we go we have our entire front panel ready to go let's go ahead and change the name of the slider to temperature there we go that'll work now did you notice as we drop these on the screen a corresponding icon was dropped in our block diagram so here's our temperature slider here's our string box and here is the output in degrees f and now put in degree c all we have to do is wire these together now what's the formula to convert to temperature in degrees f to degrees c do you remember well i'm going to type it down here in the bottom to enter just a random text note just double click and i'm just going to make a note to myself that degree c is equal to degrees f minus 32 times five divided by nine and again i'll highlight that change the font size to something bigger there we go now it's nice and easy to see so we need to replicate this formula up here i need to take the temperature in degrees fahrenheit which is coming out of the slider and i need to subtract 32. well here we go we just right click hit this down arrow here if it doesn't already show and click on programming i'm going to click on this little pin here to keep this guy handy where we can see him there we go okay so i'll take temperature and i want to subtract 32. so i go to numeric subtract and drag it up onto the screen i'm going to move that out of the way drag this guy over here and when i hover over this you see these little orange terminals on here i want to wire those up so i want to wire this terminal to that one i hover over this guy to that nub appears i left click on it and i draw a wire over to that guy now i take the temperature minus 32 so i right click on this guy i say create a constant 32. great we just subtracted 32 from the temperature now what i want to do i want to multiply by 5. well here we go again i go get my multiply drag him over here wire him up i just left click on the nub and i need a constant here i need to multiply by five so i right click create a constant five perfect okay we need to take all that divide by nine so we go grab and divide and did you notice that simply because i brought that real close to the multiply it automatically wired it for me that's pretty handy right click on this nub create a constant and that needs to be a nine great that's our whole formula the temperature minus 32 times five divided by nine is the temperature in degrees celsius so i simply take that and i wire it up to that guy now i don't like the placement of all this stuff so i'm going to move some things around i'm going to grab the temperature in degree c bring them down here take that wire and move them over here that's a little better now degrees f we already have that right that's this wire right here so i bring my wire spool down here click on that wire and bring it up there perfect let's move some stuff around make it look nice and we're ready to go now one of the cool things about labview is it's constantly checking your program and whenever it sees a program that's ready to run it turns this arrow white do you see that right there for example if i delete one of these wires look what happens that arrow turns into a broken arrow that means your program isn't ready yet so i go back and i look over here and i say oh yeah i forgot a wire so i left click on this guy drag them over there and boom my arrow turned white it's ready to go let's see what happens when we run this program i'm going to close this guy out if i run this program by clicking on the white arrow it ran but when i move the slider nothing happens interesting so if i put the slider at 100 degrees f and hit the white arrow it took 100 degrees f and it converted it to degree c but then it stopped well what's wrong here what's happening is the program is executing this once and quitting which is exactly what we told it to do what we really want to do is we want to do it over and over and over again so we can adjust this slider and see the answer well that's easy i'm going to take all this stuff and move it just a little bit to make some room like that and i'm going to right click and go find my programming toolbox again there it is and i'm going to go to structures and pick up this while loop and i'm going to draw a marquee around all this stuff what this box says is do this over and over and over again until we tell it to stop now i don't want it to stop so i'm going to right click on that little green nub right there i'm going to create a constant and i put a false there it says don't ever stop this while loop perfect that's exactly what i wanted i see my white arrow so let's try and run this thing oh now it's running see the little black arrow with a dashed line that means we're running over and over and over again so now if i move this guy look all my temperatures are updating in real time so zero degrees f is about minus 17 i think 32 degrees f should put me right around zero and sure enough it does looks like everything's working that's perfect now the only thing we need to add is our text message display right and i think in our early example when we went above 85 degrees we had a message here that said to bring sunscreen when we went below 40 degrees we got a message here that said bring long underwear and in between we just said how to have a nice trip so how do we get those three different cases to display three different messages well whenever you have something like that you want to use something called a case structure now before we can edit our block diagram we've got to stop the program so hit the stop sign that kills the program come over here to the block diagram right click go find your programming toolbox there it is back in structures there's this case structure right here grab that guy and make a box right around here that ought to be enough room now we want him to make decisions based on the temperature so i'm going to wire the temperature from here down to this input i'm going to move some things around a little bit make it easier to see there we go so now we're going to take the temperature into this case structure so the first case i want for all temperatures up to 40 degrees so dot dot 40 will give me one result i'm going to right click add a case after this i'm going to say all temperatures that are 85 degrees or higher so two dots there and there's always a default case sitting here so he'll get everything else so one case will take all the cold temperatures one case we'll take all the hot temperatures and this guy will get everything else so let's get rid of that zero we don't need that great we have now three cases in here so for the cold case we need some text that says bring along underwear well i just right click go find my programming toolbox and i want a string constant this guy right here drop him in there and let's just put whatever we want in here i'm going to say bring long underwear maybe two exclamation points and i'm going to wire that guy out to the display remember this guy is this box over here on the control panel right okay for the default case we want to put another string in here now we could go back to our toolbox and get that but what i like to do is go back to that one we just did i'm going to take this guy say ctrl c for copy come up here to 85 and say paste i can just move him in here and just change the words so let's see when it's real hot out we want to say bring sunscreen great and then we wire him out and we have one more case to do the default case i'm going to paste that one in with control v and in the default case we're just going to say have a nice trip and wire that out now notice before i finish this wiring i have a broken arrow up here means my program's not ready right but as soon as i finish that wiring boom that arrow turned white my program is ready to run so what's going to happen here is as that temperature changes this case structure will output a different text message to our text box over here we have a white arrow so let's try it run the program and there's our default message have a nice trip let's go up to 85 boom changes bring sunscreen gone to -40 bring long underwear that's it that's how you write a live view program you create your control panel you hook everything together put it in a while loop and you're ready to go now here's what's really cool about labview let me stop the program i suppose i don't like this little text box here that's kind of boring i want to change that to some colorful meter of some kind well watch i just come up here right click on this guy i say i want to replace him with a numeric indicator and instead of using a text box let's use a meter and we can move him down here maybe let's see i don't want the temperature to go from 0 to 10. so i'm going to right click change the properties and let's make our temperature -40 to 150 just like our slider and we're ready to go i have a white arrow so i can run that the program's running and look now i have a graphical meter for my output instead of that boring text box how cool is that i can stop the program if i don't like the way that looks i can change the shape of it the size of it i can change the colors all kinds of things i can do what about temperatures in degree c let's change the look of that guy let's right click replace go to my indicators let's make him a gauge cool move them around so i can see them and let's see again we don't want to go from 0 to 10 so i right click change my properties uh i don't know what he's going to go from into but i'll just say minus 40. to plus let's say 100 great i have a white arrow so let's run the program if i change my temperatures look there's degree c and there's degrees f all graphical so you can see with labview it's really easy to get carried away with how your front panel looks and it's actually kind of fun too labview is primarily used in science and engineering but you can use it for just about anything i love to pull labview up because it's so quick and easy to get a program up and running now here's a couple challenges for you the first one's easy change the messages when you go above 85 give me a different message let me go below 40 give me a different message how would you do that well that's easy stop the program you just change these text messages right okay that one's pretty easy how about changing the values of the temperatures at which we change these messages how would you do that well that's easy you would stop the program and then you just click the case you want let's say 40. well if you want to change that to you know 32 boom done that's all there is to it so you can change the temperature value at which the messages change that was pretty easy too wasn't it okay how about something a little bit harder instead of three cases you know up to minus 40 normal and above 85 give me more cases how about minus 40 minus 32 and minus 32 to zero break this up into like five or six cases i think you'll find that's a little more challenging but you can do it give it a try and see what happens now please understand we've just barely scratched the surface with labview it's an incredibly capable program that can do lots of different things so have fun experimenting with it and good luck with your programming merit badge
Voted #1 mid-sized employer in Atlanta
Check out our
job openings