Barcode Scanner with Raspberry PI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this Raspberry Pi video as you can see I've got a barcode scanner connected to this rally PI and I've got a sheet of barcodes here so I'm gonna scan a couple these barcodes using the scanner as you can see that information displayed up on the screen do a few more so you see the barcode is quite successful scanning codes in and presented into a writer PI screen now I always love it when I can use a Raspberry Pi to solve a real time problem let me show you what I mean so here I'm in my place of work this is the IT suite in a small primary school in their village somewhere in England and this is the problem I've got we have ten classes and we have sixteen iPads now the problem is iPads are books out continuously and I never really know whereabouts they are so I've tried to devise this paper booking system where the teacher is supposed to write in their name and then the code number of the IP that I've had that they're booking out but as you can see on this list here now there's only two or three interest but I know the iPads have been used every day this week so if you know anything about teachers you know they're extremely busy people and I don't really always have time to start white and recalling things like booking out an iPad so I've got me thinking there must be an easier way of doing this now I run the electronics Computer Club and we use an awful lot of Rodrick wires to teach the kids coding so we use them for traffic lights simulation build robot cars good in line following robots that type of thing so I was thinking maybe I could use a rather require to solve this problem so the idea I've got in mind is to get a barcode on for each teacher but maybe put them back at their ID card or maybe I'll have a folder here with all of their barcodes and then on each of the iPads I'll put a barcode as well on the back here somewhere and the process will be that the teacher will scan her ID his ID then scan all the iPads and that will display information on the only monitor and I think and see who's booked to the iPad out the time the date so if you have to go hunting for him at least I know where their belts they will be in the school so that's my plan let me go back to the office and I'll show you how I'm going to tackle it and go through the code that are written which is in Python okay I'm now back in my office now when I start a project I'd like to do or carry out a bit of a feasibility study to find out the scope of work and what I'm gonna need in terms of equipment how much it's going to cost and the complexity of the project that sort of thing so now we start off with a list of parts you know I've created a list of parts of what I need for this project but the one of my goals is to try and make it as cost-effective as possible because I do work for a school and I trying to keep the cost down because if you work in a school especially in UK you know the moment where most schools are strapped for cash so I'm trying to keep this down to keep the cost down to a bare minimum if possible and luckily I have quite a few the components already in the school so the Raspberry Pi I have numerous right suppliers because as I said before we have a electrodes Computer Club which I run and we got quite a few rows with pies so no problem with relative pie or the power units to go with it now I'm not going to use a keyboard or a mouse I want the project to be the only interface to be is the barcode and the monitor the only two add-ons I'm going to use with Roger PI so no Keaton no keyboard and no mouse now the monitor I've got quite a few monitors sitting around the school so it makes no sense for me to buy a new monitor because I've got one that works perfectly well the only problem I've got is that these monitors don't take a HDMI connection they've only got VGA but no problem I use these little converter here so a VGA comes out of the monitor into this can here and this HDMI plug straight into you the Raspberry Pi now I've used these numerous times around the school they work really well and they're really really quite cheap as well I meant about probably eight nine pounds maybe 10 pounds now I don't know yeah but not very expensive the barcode scanner I'm going to cover off in a few minutes because there are a few little issues when you're connecting a barcode scanner to Roger point nothing serious but just something to be aware of so I'll come to that in a minute the only other unknown for me was the barcodes where am I going to get barcodes from well as it turns out amazon sell barcodes and they sell em in these roles of a thousand but are clothes for twenty two twenty one pounds now for a thousand barkos twenty one pounds i think is a reasonable price but i don't want to need anywhere near that number i put me only talking about maybe a dozen dozen barcodes so for me it didn't make financial sense to buy a thousand codes where i'm going to use fresh to that number so i'd look around the internet and i found this fantastic website called barcode tech - it's common link in description below but what is site allows you to do is create your own barcodes now there are numerous barcodes outside here but i found the best one to use with the raspberry pi on the scanner that I had was code 39 filarsky now that allows you to use not only numerals but also text as well so what you can do is you can it create your you can see this is the barcode or this code here but you can create your own so I just delete that entire test - zero zero one and do a refresh you see it created the barcode for me there now you can do if you click on this button here you can create numerous barcodes 3.now I did find that if you put in more than five when you download it downloads it to a zip file and inside a zip file are a number of gifts one gift for every symbol it's every single barcode but if I did more than five the sixth and seventh barcodes were corrupt so I could only use the first five so I think it might be something the cited the website is trying to stop that do to stop you from just downloading hundreds of barcodes in one go now nothing stopped me to do five and then download them doing all five download them do another five and that seems to work for quite well so for barcodes this is really really a good site to use now let me go on to the actual barcode reader because there are far fewer little issues I think your book just need to be aware of okay here you can see there are two pi is not connected to a monitor it's connected to my laptop via VNC connection remote Wi-Fi connection which probably works very well but when I try to use the barcode scanner with what happens it's barcode scanners recognizing the code and not displaying anything on the screen which surprised me really because if I ever say hit the keyboard and just hit some keys they're appearing on the screen now the barcode scanner is boasts that just emulate the keyboard presses so I was really surprised to find that when I use the scan rate in work and disillusion to middle because I thought I thinking that fantastic idea I've got of using this to solve my iPad booking-in process and now I can't use it but I don't think about it and decided to rather news ie VNC remote connection to actually physically connect a monitor into the right supplier and I repeated a test and this is what happened okay same test as before but this time I had the monitor physically connected to the Raspberry Pi same barcode scanner same book this is the screen so let me start to scan the book again now look at the screen so it works when you have a screen physically committed to roger pyre but it does not work if you want to do over a remote connection now for me that's not problem I was always going to use a physical monitor so works fine for me but if you've got a project and use planning on using a remote connection you might have to rethink the idea okay I'm going through the Python coding now but before I do is you want to cut off this algorithm always like to write an algorithm before I start major coding project I just think it helps me structure my thoughts makes it easier to debug that sort of thing so starting at top here asks user for their bar code so basically ask the teachers have skinned their bar code match bar code with user and start a timer come on to time in a few seconds then I'll see teacher to scan Yelp own iPad barcode match the barcode with the iPad and display the teacher's name date and time on the screen now this section here is I need some sort of mechanism that the program will know when the teacher has finished scanning the iPads because it could be more than just one it could be several so I need a end code so what it's not to do is to put a or create a barcode that gonna stick on top of the monitor so once the teacher has finished scanning all the iPads they scanned the barcode on top of the monitor and that would deed that will tell the program that they finished scanning and will take him through this loop here cancel the timer and take him back to the default position which is just asking the user for the barcode that's the default position now inevitably a teacher will forget to enter the end code so what I've done is I started a timer here and after 90 seconds if the teacher has scandal and iPads and left the room and forgot to enter the end code this part here this branch here will automatically lock the teacher out and take it back to for code default position so that's the algorithm that I'm going to be using so let me go across now and look at the code and I'll go through it in a bit more detail right here I am with my Python program go through in a bit more detail for you when I first decided to stop this project I wasn't quite sure what graphical user interface to use Indian that is try decided to use TK and everything because I think is that the best application for a text-based program such as I'm using I did think about using PI game but by going is very difficult it takes onto the screen and it's not really designed for that sort of application anyway so yep TK inter was the way I went so here I'm important all the various libraries aren't going to need included some day and time libraries here I'm creating an instance of T counter now I know most people tend to use route but I always find route is a bit ambiguous the window makes more sense to me so I decided to use Windows - themself - painter then I'll just jump to the bottom of the page for a second and I'll show you how to configure the TJ TK into window so from here to here are the parameters that we're gonna need to set up the window so if I launch the window watch the program know is that for a second so the first parameters the geometry 800 by 600 a + 0 + 0 so 800 is the width 600 is the depth 0 plus 0 is how you position on the screen now you notice that when I launched it it actually appeared right up here that is 0 0 as appears here if you don't put them parameters in when you launch it sometimes it might start here you might start there it might start over here it might start down there if you want to be precise about where you want it to start you have to put those parameters in there now the reason I have chosen 0 0 not in the middle here is because once the program is sitting on the Raspberry Pi I want this window or this window will fill the hole of the monitor screen so it'll be perfect it will feel every inch of the screen just perfectly so I wanted it to launch so it appears right the top left-hand corner and to fill the whole screen that's the reason why I'm using zero zero there now the next tier parameters frame 1 and frame to define how you split the screen up so here frame one that's free one from there to there from there to there and from there to there that is frame 1 Frame 2 is from here to here right to the very bottom and across to here that is frame to the next parameter of create an instance of tree view tree view this is tree view here this bit that looks a bit like a spreadsheet that's tree view and down here I've created a function called tree view user interface and that's the first program called in the loop so if I now scroll up and minimize that for a second and scroll up to my tree view user interface function I'll go through it in a bit more detail so the first line I'm setting up a lot more global variables ID 1 to ID 16 so they're gonna associate each one of these each with an iPad the second line of just given the window a title my pad booking system from here down to here these lines of code are responsible for setting up the TV winter window so basically set up this just part of the window here so this line here actually sets up the first column which is the iPad column here and you see it's got here anchor W W means West so basically what I said is I said I want the iPad name to be not in the middle not on the far right but on the far left but slightly in a bit so I've declared it to be West but actually padded it out with a few extra spaces just so that it lines up with these I packed it the iPad labels here then I've got a number of columns these are the column variables booked out beta out and time outs they associate with these three columns here so that's booked out that state out and that's time out so I know they've got different labels but these are just variables these names here just variables so the for the variable booked out on this line here it has a width of 200 so basically what that means is that column is 200 pixels wide date out is also 200 pixels wide but this time the anchor is centered so that's actually the date is actually the date label is actually in the middle of the column and likewise with time outs that's also 200 pixels wide and centered in the middle okay then booked out the variable box out is now given in a label called booked out by so that's the text that appears in the top of the column and the same for date out which is now date and same for time out which is time it's last wrote where to position T view on the frame Europe on the screen remember I'd there was 2 frames frames your own frame 1 frame 0 was rose 0 column 0 frame 1 is Row 1 column 0 so basically that's telling you where to pull up the to review the next for liner codes are just variables that I'm gonna be using in the table the preview window I've known amounts because the information that I wanted to display first off is nothing this just blank screen eventually they will be populated by a teacher's name the date that they booked the iPad out at the time but for now and it's gonna set them as null now moving down to the table itself so you can see each id-1 id2 rethread for each of those iPads and each of the IDS has their own set of parameters so if I look at ID 1 iPad 1 it has an iPad name so I pad it number 1 as the teacher the variable names are gonna be the teacher's name DT which is the dates and HR which is the hour and it has a tag of odd row and the one below it is identical except for a hole for the tag which has even row now if we look at these two top lines here basically it's a tech configured for each of two rows so an odd row will have a white background and font size of 10 and Eva row will have a blue and light blue background with a font size of 10 so basically I'd wrote even wrote odd row even wrote I broke even where I just think it's going to make it an easier to display the text on the screen at the last line in this function is ask for barcode which is the next function down now this really isn't doing anything more than just asking the user or the teacher so scan their barcode if there had been any previous text from a previous user these two lines here just blank any text that's on the screen before hand so nothing really interesting there the only piece of code that's we're looking at here is this bind key function what it's gonna do that's gonna look at all the keys that the barcode scanner or not the keys but the characters that barcode scanner scans into the system and this can present them to the next function which is called get teacher barcode which is this this function here so what is function does is to read in events generated by the barcode scanner character by character and if it appears in this string here it will add it to the variable code let me show you what I mean if I have not the program let's move that over a second and watch this area here now I'm gonna pretend I've got the scanner with me so I pretend I'm scanning him but it's gonna hit on the keyboard 1 2 3 4 5 so 1 2 3 4 5 and you see that the the bearable code is built up character by character so the first event and the in the barcode scanner is readiness of one so the variable code is a sign of the character one next time around is a sign the character - so the code now becomes one - the next time around is a sign three so the code variable now is one two three and so on and so on so it becomes two one two three four five minimize that for a second these two next bits lines of code really just print information on the screen and basically what I've just shown you you don't really need them they're only there for diagnostic purposes this piece of code here is looking for a care of return so I've got my barcode scanner set up that when it at the last character a then inserts a character return and this is what is spendings looking for here so if it captures a carriage return it then assigns the variable code to the variable teacher and then goes off and looks at the staff dictionary with the variable code so it look at the staff dictionary and look for one two three four five so if I go up to the staff dictionary which is very minimal in a moment you can see that it says one two three four five and it's assigned to mrs. Scott the teacher mrs. Scott so if I go back to the screen and I now press care of your turn mrs. Scott is recognized because it's this dictionary one two three four five and the equivalent to that is mrs. Scott so that's basically what this piece of code here is in the next two lines basically nulls the the variable code ready for the next scan and this last line is get teacher name so the teacher now knowing and we now notice mrs. Scott then passes it through to this variable here and all this is this piece of code here does so this function here does it's just display the teacher's name on the screen so it recognizes the prints recognized on the screen and the teacher's name this piece of code here here mrs. after equals we know that after that's the timer I set a timer up there at the end of the teacher scanning all the iPads they're supposed to put in a an end code which is zero zero inevitably they will forget that at once at some stage so after 15 seconds I've got 15 seconds just series setup for test purposes but in reality there will be 90 seconds and nine zero but after 15 seconds it will automatically block the teacher out and then go to ask for barcode function so that's really what this piece of line of code here does the next one is to ask the ask to scan the iPads now to ask the sky scan the iPads is this function here and really that's just placing information on screen asking the user to scan the iPads and the last piece of code there calls this function which is get my pad code and this is identical to the one I showed you before with a teacher except it's just checking for the iPad so the dictionary you will look at will not be the teacher dictionary but the iPad dictionary everything else is identical now this next piece of code here I feel I could have written it much better than I have in a moment but the thing is it works and it works really well it's just not elegant and when I get time I will rewrite it make it into a class but for now it works it works well and I'm going to stick with it so basically what this does is I've got some global variables here device and statuses so I'll come on to him in a few minutes these two lines here define the current date and the current hour now these if statements are looking for a character one which is iPad one carry the two ipad 2 character 3 which is ipad 3 and so on and that information comes from the dictionary the ipad dictionary so if i scan in TSG ipad 0 1 then 1 is returned from the dictionary and it's that one that is being looked for in this if it is statement so if device is equal to 1 that means ipad number 1 and its status is in that means it's actually in the cupboard is not being booked out then I immediately change your status to out that because that means that someone's going to book it out and then I go to the TeamViewer identity 0 number 1 and I changed a value which at the moment would be just blank to the teacher's name in this case said that meet mrs. Scott the dates and a time that she booked it out if the status is out that means it's already booked her and the teachers now booking it back in I change the status to in and in the TeamViewer I then ID ID 1 I changed the values to null so that means there would have been the teacher's name mrs. Scott date and time and they now are logged and that's the same for device to device 3 device all right down to device 16 as I say it's a idly a piece of code I know and I can imagine yeah it's really serious Python programs that is screaming at a screen saying that this is a new way of doing things I'm not very efficient and I understand that but for now I'm going to leave as is these last two bits align the code once the teacher scanned all their iPads there's a end a barcode attached to the top of the module there will be to the test attached to the top of the monitor when they scan that in that is the signal for the program to say that they teachers it's finished scanning the iPads and to basically default back to ask for barcode what it will do it will it will cancel the after timer which you saw earlier on if the device if the teacher has not scanned the end code that means there's another iPad to be scanned and it will go back round the loop now I never to be the teacher will forget will probably forget to type in the end again and that's where the timing function comes into it and basically that that's it we're now back to the geometry of the of setting up the window choose what I covered up covered earlier on okay I think that's it for the Python side of the programming I will put this on github so if you want to download it play around manipulate it do whatever you want I have no problem with that okay so the next thing is to show you it all working in the school itself so the scanner has been in working now for a couple of days teachers seemed quite happy with it about to move it to another location because of a younger children thought the barcode scanner itself was a toy so I moved it to our corner ICT suite where that younger children don't get to go to the only thing our only other thing I need to mention is um this little box here the reason I've got this is that the scanner doesn't like to be left on for a long period of time so I've read the instructions and they advise you not to keep it all the time the problem being we've been in a school it could be on up to eight hours a day so what I've done I created this little timing device here so if I see inside there's a little flat five five timing circuit I'll show you that in a few minutes so you just press the barn it turns the scanner on for two minutes that allows the teachers to scan their code scan the iPads and then after two minutes the time the circle will just switch off and therefore switch off the barcode so it seems to work quite well let me open up the box and I'll show you what it looks like inside okay this is inside the timing box so basically what I have here this cable goes to the Raspberry Pi USB port the Raspberry Pi and this USB socket here is actually barcode scanner itself now on the USB the user pins of the USB connections are power so what I've done is I've actually made broken the power to the pasta side of the USB connection of fede through to this relay here and this relay is activated by the timer so when the button is pressed on the box the SS the IC 555 timer activates that relay for two minutes which closes that connection and therefore turns on the barcode scanner simple as that I've put a circuit diagram up neatly off this video and all the code in the pike the Python coding and this circuit diagram will all be available on github ok thanks for watching bye for now as a footnote to the video I just thought I'd go through the timing circuit with you so here we have the Raspberry Pi and normally the barcode scanner will plug directly into this port here what I've done was I have used the USB cable that has a plug in that in and a socket in this end that's important because that's where the barcode scanners going to plug in so what I've done was I put a piece of error board in here and I've actually cut the cable in half and sold these these wires on it now I'm guessing really you could have was just stripped away like let's just ripped away the sleeve and intercept the the red power wire but I decided I was gonna use a variable so it's up to you if you ever want to do that I've soldered the Commission's on so very bored and you can see here that there's a break in the Vera board here so the red wire is not it's not connected straight through so it's intercepted by these two wires here which goes through this relay so in its default State there is no power go into the u.s. USB connector therefore the barcode scanner is off so when I got to sort of five five Simon Thomas circuit here what happens is when I press the button on the box which is this switch here it sends a low condition to the trigger pin the trigger pin goes high through this resistor which powers up this transistor the transistor goes closed circuit and I've now got a path from five volts through the relay through the transistor down to ground and that then activates these this contact here the contact closes and powers up the USB and the barcode scanner and it powers up for two minutes only two minutes just determined by these two components here this one mega ohm resistor and this one 100 microfarad capacitor now I mean if you want to go higher or lower make a higher value or a lower value in terms of time then you just have to play around these components here so that's it's a very very simple circuit I see five five timers are really cheap to buy their pennies I think I bought a hundred for about five pounds yeah so that that's the circuit so thanks for watching again
Info
Channel: Davis MT
Views: 18,240
Rating: undefined out of 5
Keywords: Raspberry Pi, Barcode Scanner, Python 3, coding, science, electronics
Id: GITYVmEG7xs
Channel Id: undefined
Length: 30min 23sec (1823 seconds)
Published: Sat Jul 27 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.