#28 DS18B20 Temperature Sensor and CAP1188 Touch Board

and welcome back now today we’ve got a few things to talk about before diving into the details of one of them first of all it’s this thing over here perhaps this this one here which I don’t want to go too close to you because you’ll see why if in fact I press this green wire here hello Here I am yes you might have guessed it this is a touch control unit and it’s actually a cap one one eight eight breakout board by Sparkfun and what are we going to be using it for in conjunction with this Leonardo style micro is to have this to control my videos so if I press other well what will be buttons on here not button touch pads you’ll see if I press this second one we should go to our code window there we are and if I press my third one which is this black one down here that’s the same code whenever it was me in it as well so I think you get the idea of what’s happening on here so let’s go back to the in the main window right so this this touch control unit is going to be built into little boxes and with some touch pads for the three main views that I use and then the webcam that’s me and the picture in picture of my workbench so as you can see it’s some even now with these funny little bits of worrell hanging out in the back it’s working exactly as I wanted it to the Leonardo I’ve here that’s a whole topic in itself I say a Leonardo it’s a pro micro of sorts which could be a spark phone Pro micro which comes up and identifies itself as actual it could be a Leonardo micro and identifies itself as such they’re not original so I do have an original one coming and I’d be interested to see how that changes the whole point that these though is that they don’t have the same USB connection as you standard uno because this is a virtual USB device which means this can talk back to my computer that’s now when I press these buns this micro here is saying send the following shortcut keys back to Windows and then of course this what you’re looking at here which is my camera in it well interpret that to say are you mean switch to that camera or go back to that one so it’s um identifies itself as a lot of an hid human interface device very easy and simple to use using the keyboard library but we’ll talk about this and this in much more detail when I’ve moved this on a pace but today we’re going to talk a little bit more about this now this unit it’s a standard Arduino clone on the bottom and I’ve got this shield plugged in which you’ve probably seen from other videos I’ve done we’ve a little tiny breadboard in here now this breadboard I’ve now stuck on it comes with a double-sided pad but I could have used the solder pads to make it more permanent now this unit is connected up to this here this is a DES 18 B 20 which is a lots of you of course with middlee ringabel as being a temporary in it but it’s a temperature unit using the one wire system and the one wire system works differently to I squared C or indeed SPI it’s sort of proprietary communications protocol but has now been adopted for lots of different things so I want to talk a little bit about this because if there’s been lots of things on the forum about a fundamentally how do you use it and how simple is it to use and B what if I want to monitor not just one vat of beer but two that’s a beer or for bases that’s a beer or indeed your beehive down the bottom of the garden and we’ll be looking ahead to do that in some detail so join me in just a few SEC’s well I get this set up and we’ll talk about that then and welcome back here we are now with the board we’ll set up for the DSA 18 B 20 temperature converter now there’s this little device here it looks like a transistor just the three proms coming out of it there are lots and lots of transistors inside here there are two ways of determining what the temperature is using this device one is the easy way using somebody else’s library which is a bit like plug and playing Lego bricks together means you don’t really learn much and you just hope to god it works because when it doesn’t you’ll be stuck and there’s the hard way which is you do all the work you talk to this device directly so that you understand some of the things that’s going on that’s what we’re gonna do first of all now don’t get me wrong the the library that’s

supplied does do a lot of the things and takes the pain out of doing this however I’ve cobbled together a bit of code here mostly comments than code and it’s honestly not that difficult so if we look at this here right first of all we’re yeah we have to get the one wire device in this one here okay so make sure you install that I think it’s standard for Arduino but if it’s not you just google it and download it okay there’s the debug window for us now there are options on this device so what we can say is what resolution that we want this device to return the temperature by resolution I mean do we want it in hold degrees only so you know its degrees centigrade by the way if you want Fahrenheit just do a quick maths conversion so do we wait in hold degrees like 20 21 22 that’s a little bit broad isn’t it really but 20.5 21 21.5 might be enough for like a room-temperature Merson like that you can get an two quarter degrees twenty point two five twenty point five twenty point seven five or the default which is not point not six two five resolution and you might think oh yeah I’ll have it as high as I possibly hand out of it the most accurate well then your programs are going to be hanging around for a bit because it takes three-quarters of a second to convert the temperature on here if you’re gonna have maximum resolution out-of-the-box so what most people do apparently is to reduce the 12 bit accuracy down to 10 bit which is naught point 2 5 degree let’s face it if you’re sticking one of these a waterproof one of these into a vat of beer or something does it really matter of it 21 point two five or 21 point 3 I don’t think so even for a room-temperature I don’t think it matters that much so most people set it down to to a 10 bit resolution and the conversion is done a lot lot quicker something like 160 milliseconds as opposed to a full 3/4 of a second so I will show you how to do that and you can decide then whether you want the highest or the medium resolution in fact any other resolution in between so the first thing to do of course is to understand what the address of your individual device is now each D s 18 B 20 has a lasered unique 64-bit address in here how you get that address I’ll show you on a different bit of code not here I’ll run that little bit code and got the dress out for this one this other one and over here there’s not connected up at the moment it’s gonna be used in another little bit of this video has a totally different address okay so they aren’t unique you only need two wires and well you need some sort of power somewhere but this is running on parasitic powers a little tiny resistor and you can probably run five of these off that one resistor but it does take power to do the conversion or just sitting here but when you say go give me the temperature it takes some power about one and a half millions so you’ve got to make sure that if you’re asking all five for example to convert the temperature at that precise instant that you need one point five milliamps through this resistor just something to bear in mind might be better to do it one at a time stank of them anyway having got your address your unique 64-bit address for your device this sequence is fairly good use you reset everything you select the device using the address that we’re putting in this 64-bit address and then there are some let’s say command codes you can send or registers as it’s like to be no more like to call them command cozy you far offer this thing and they’re all in the they’re all in the datasheet now data sheets are easy to read some ways over there have a look here’s the data sheet for the D s 18 being this one who’s this from now this is Maxim it used to be Dallas semiconductors but they were bought out in Maxim in about 2001 so it’s now Maxim but the library we’ll be using later on is still called Dallas would you believe so down here somewhere and forget all this first bit that’s just the characteristics of the device in terms of electrical you know minimum maximum voltage and so forth it’s fine fault tolerant this one though now it’s worth reading this actually all this gubbins here it’s worth reading it because it does tell you quite a bit bit

about how it works alarm signaling for example you might want that if you’re putting in a device into a vat of beer or wine or the Beehive or down the bottom of your garden you might only want to know if the temperature exceeds or drops below a certain value so that you can set the alarm to come on at that temperature and then your Arduino can just pole for those this says give me the temperature of all those units that have an alarm condition that is that’s gone out the preset temperature range that I’ve set so that’s useful to know there’s lots more about powering it up and so forth and somewhere down here oh yes this is we’re gonna be talking about this configuration register that’s the resolution that’s how you set the resolution and well there’s the configuration register there talks about it anyway there’s loads of stuff in there and I would say you know it’s not it’s not that difficult it might look a lot of it but it’s not that complicated the bits you don’t stand skip but just understand that at the end of the day what you’re actually doing it’s just sending a series of commands down the wire to this thing say boy get ready I’m talking to you not you over here I’m talking to you I want you to do this do that to the other and mainly you’ll be saying I’m for you I want you to convert the temperature now thank you very much I’ll give you a few milliseconds to do that right or you this one here not that one there you I’m gonna read your scratch paper memory where you’ve put that temperature information okay I think you say right I’m gonna read it one two three right I’ve read it I’m gonna reset now you not you okay this unique one and that’s the end of it really so let’s just whizz through this code because it really is fairly straightforward so what we’re saying here is initially what’s the resolution we want no I’m setting it down to ten minutes which is this one here so three F so in this little tiny bit here from here onwards here down to here that’s optional if you don’t want to set it down to the ten bits it comes by default as 12 minutes which is no point not six to five resolution ridiculous amount but you you may want it for something who knows what you’re using it oh but I’m setting it here just to ten bits just to show you that it can be done you can then also incidentally write that resolution into EEPROM and then remove this code remember to remove this code when you’re doing it though because you don’t want to write it to the prime every single time give it an it once that’s it just like comes out the factory then write then the next thing this is where the rule governs is we’re saying right oh you they were so addressing particular one that one there we’re saying I’m now going to ask you to do the temperature conversion place that’s a we do now here it tells you what the resolution is and we’re going to wait a full one second now we’re waiting for one second in case you do choose the full 12 bits as I say that for the not 0.25 which is it’s this one here it probably takes about 160 milliseconds so it’s pretty quick we need to reset it then we need to say or you I think you’re getting the idea now I’ll stop saying it but we’re saying we’re addressing the individual unit we say look now this command here this is all defined in the the datasheet that I’ve shown you Vee says right I’m reading your scratch pad which is the bit of memory where you’ve put that temperature and you read it eight bytes of data but you only want byte 1 and byte 0 they’re the ones that actually contain the temperature and then we’re going to convert it using two’s complement because remember the temperature could drop below zero which means the very first bit of the temperature come return which is the most significant bit which is data one will have it’s bit set if it is and of course we have to flip all the bits to get the actual temperature in negative so that’s what this does here I’m not going to go into that because quite frankly this is just for demoing and then we’re gonna print it so let’s let’s actually see this running so oh and there we go that now my studio here is 25 degrees it says and if I’ve put my hands on this device here we bring a bit closer to the camera so if I touch this you should see it change into increments of 0.25 oh yeah twenty-five point two five so you’ve got 25 point five and twenty five and seven five and it goes so if I really hold it tire might leapin bigger increments in that 26 now know it’s always going up in 0.25 in fact it’s off slowing down there I’m obviously not as warm as I think I am so

if I let go you should see that slowly drop there it goes so what you can see here is that it’s doing it in point two five of the degree increment not point to 5 degree increments here on the resolution okay so the resolution is ten bit now if you do want a higher resolution no point not six five wishes out the box you can do that all you’ve got to do is change this bit here so we’ve got three in here at the moment if we change that back to 7f and recompile know if it goes and done uploading right what’s the output window here there we are now we’re seeing all sorts of funny values look because there’s no point naught sixty or five isn’t a multiple and therefore looks a bit alternate really nothing do you think that’s probably what people don’t use it part from it taking forever to convert to this resolution thanks we’re of us if I just solve touch this a little bit know that soon as I touch you though it changes so you may need this in your project you might want the altar but just bear in mind you’re paying the price in terms of time now you might think well this doesn’t seem a very good design if I’ve got to wait a whole 750 milliseconds to get back that up there full resolution that sounds like a poor design really there’s a way around that at the moment if I bring this in closer the camera you’ll see this resistor here that one there now that’s one resistor that can be used for all of these so from this point onwards we can have two wires coming off here and that’s all we’d need because the power is being taken down the signal line a bit like a phantom power on a microphone or Electra might burn us and lava but it’s basically two wires even though it’s called one more and so what we can actually do is rather than using this parasitic power we can actually supply the voltage to each of these then what you can do is say I’m not supplying porosity power I’m giving you the full 5 volts go and get me the temperature I’ll come back in a little bit and ask you whether it’s done so that’s an alternative way of doing it some people wouldn’t want to do that if you’ve got a loop in your code over there that needs to do other stuff as well as getting the temperature of this thing you might say fire off the command to five of my units they go and get me the temperature I’ll come back and just poll every few milliseconds they are you done yet are you done yet and then when they are done you can retrieve the values out now we haven’t done it here in this code because it’s demo code Ness difficult to do all that polling and stuff writing it manually but it does mean that this is a bit more flexible than what you might have think but a lot of people most people always say you use this parasitic power because then even if this is now built into project you see you could use a little Jack plug and one-eyed Jack plug and just run it off into you beer that or your beehive or whatever it is you doing the waterproof ones in the other sort of a little tubular cylindrical metal ones with a little very long lead on and you just drop it into your VAT a beer or wine or swimming pool fish pond or whatever it is you’re monitoring and they’re totally waterproof and they work just great but then you wouldn’t need that kind of resolution it’s currently showing you you basically probably want whole degrees might be enough or at least certainly core degrees plenty so there we are this tiny little bit of code here which once again is probably know what 50% comments and I’ve just try to explain what’s happening is very simple and it gives you an idea of how we talk to this because when we switch to the library in a minute all that complex see if you like goes away and all you say is go and get thank you very much the end it’s easy yes but it means you haven’t understood anything about how to talk to it and you might want to if you don’t want to that’s great go and use the library I mean let’s face it we don’t look at the decompiled code very often of what goes into the Arduino do we in reverse engineer that we don’t care we use the easy manner of writing stuff like this so horses of course is now I’m going to kill this one stop all this unplug a couple of things can get bring back the other bit of code I’ve got ready that shows you how to use the library and how to use more than one device at the same time right here we are again now ready for our library version of that code but before we do that there’s two things I forgot to mention last time so if we go back to our code first of all if you’re using Windows 10 you will have a calculator like this and if you if you choose the programmer version on here that you can choose

programmer scientific standard why the programmer is exceptionally useful in working out all those bytes and things so as you can see if there’s one on here that was working out in binary so no so if you wanted to find out for example what a hex and the decimal value was in binary you just said it’s a hex type in some values like 56 and then it gives you back the results in decimal 86 ox or which I’ve never used actually but binaries most certainly use so just a little hint for you there about using the programmer calculator is that and secondly this Barre code here is the scanner now I mentioned that I had the address on here previously I’ve written it down and we’d used it in the actual code anyway but how do I get that address well this bit of code here is a scanner now this isn’t my code because the style is not this is not my style of coding at all so this is somebody else who’s written this I must have got off the internet at some time so if we run this and upload it let’s have a look see what happens because we’ve plugged in the unit exactly as we had it before no changes there at all and it says there we are it’s found it low looking for all my devices salt and it’s found it and that’s as easy as that I’ll put this code like I always do at the bottom of the video so you can use that to discover your 1-wire devices works real wonder why device is not just the temperature ones here okay so there was that this is the this is the library now from dallas dallas semiconductor they broke this library as the same maxine took them over in 2001 but it’s still called dallas temperature so by putting this in we can abstract our ways that ourselves away from all that register and command to my own codes and all the rest of it and just say give me the temperature so look forget all this build the front us just initialization there we say look be and then we say give me the temperatures of all devices that you’ve found and print it out do what you want to what do and then just a delay so don’t get zillion a second so let’s just upload this and see what happens then there we go now what it’s saying there is look since the zero twenty five point four four now this is probably in full resolution twelve bit so it is gonna have some funny values if I hold it up it goes twenty five point six three eight one so the next thing to ask is to say well okay that’s fine you’ve got that one temperature but I’ve got three vats of beer that I’d like to monitor plus the room temperature if need if kabane if only we could plug in another temperature sensor at this circuit somewhere I’m laughs even got a spare one here what could we do with this next one to plug in well how about just plugging in right alongside the first one which is something you’ll never see done with the semiconductors normally but there we are look two of them in line join together now remember these have got unique addresses and these aren’t transistors they’re integrated circuits and they’re identified by a unique lasered address 64 bed dress inside each one of these so that bit of code that was on the window minute ago should better figure out that we’ve now got multiple units attached and let’s see what it does and then some reset this window and restart some and there it says right there’s a first one that first one at the back here is still working but what about temperature what about the second separative sensor one is it worth was starting from zero well if we look at the code here it says how many have we got attached and we’ve said one so what happens if we need to change that too to re-upload that and off we go oh look since the zero sense of one and it’s doing the peer now how do we know it’s working well if I touch the first one which is the one at the back which would she senses zero going up so since the one is twenty six point five now since the zero is twenty seven point four four and in fact perhaps it’s the other way around then this is since one and that’s zero so look oh yes it was lol it’s the way in enumerated the individual devices so that’s zero and that’s one it’s just the order in which they’re discovered there we are so that is also running on the parasitic resistor here and the BIM reports from the Forum they’ve had five up to five running on that one resistor this the resistor is in the spec sheet it’s about

I think this is a 4.7 K you can bring it down a bit but if you get difficulties perhaps with long runs you know the resistance in the lead or something might give you problems then you’ll need to supply five volts and it suddenly becomes a three wire operation simples as they say so that’s it that’s what we have to do for this but I would urge you first of all to use the first pair code that requires a bit of pain and bit of work to understand what’s going on with these things and then you’ll understand perhaps a bit better what’s happening in the library so that one’s it up for the D s 18 B 20 from Dallas or Maxim now hope you enjoy watching it thanks for watching see you in the next video I hope you’re finding these videos interesting and useful you can leave comments down below and also click that little button that says subscribe ok thanks for watching and see you in the next video