Raspberry Pi Pico - USB HID Auto Clicker with Circuit Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys it's don here from nova spare tech and welcome back to the channel and today we are going to be doing some usb hid on the raspberry pi pico so let's get started now before we begin if you haven't watched my previous video on the micro python for the raspberry pi pico i recommend doing so because i have some environments that i set up on my ubuntu desktop that you guys might want to check out which is the tawny and all that other stuff so let's begin first thing we need to do before coding anything you actually need some sort of project so what we're going to be doing today is actually playing egg incorporated so if you check out the screen over here you're going to notice that i have this game up and all you do is a clicker game so the more chickens you press the more it comes out and then there are multipliers that helps you increase your income flow now you might also notice that every time when i press it this little bar on top decreases which means i can only press it for a limited amount of time before it kind of depletes itself and then i would have to stop clicking it so it could grow back or increase back so this is the game we're going to be playing and we're going to be using the raspberry pi pico to do all the mouse movements and clicking so let's pop into my desktop and let me show you what we're working with now you're going to notice the micropython is blinking because that's from our previous project and we're going to need to pop over to tawny oh i also have a multiplication thing going on so i'm going to stop this and one thing i'm going to show you guys is if i do help modules you're going to notice that one thing is missing that we need that is very crucial is usb underscore hid it it's not actually in their micro python library so i actually can't interface with the usb hid on the raspberry pi pico using micro python but circuit python actually has it built into their version of their python library so if i head over to their website which is circuitpython.org i'm going to go over to downloads and search for pico which is let me just type it in pico right over here you could actually download their 6.2 release which is a uf2 file and from our previous video and we could just load it onto the raspberry pi pico so what i'm going to do is download this hit save reboot this by holding the boot select and it's going to pop with a mass storage device that i could actually load in the filezip so i'm going to pop into this the file that i downloaded i'm going to drag this over to that folder it's going to reboot once it's done transferring it to reboot there you go reboot it and now if i hop back into tawny let me go stop it should be different see circuit python now if i go into help modules you're going to notice now i have usb hid and a bunch of other libraries that we can now use including frame buffer gamepad a bunch of other stuff which is great now because i can now use the board for hid but there's also another library you would need to download unless you want to write your own complete library this is a much easier option and google adafruit circuit python underscore hid and it'll bring you to their library let me see where's the github let me uh go over to github okay here you go and here's the library we're going to be using for this mouse clicking thing that we're going to be doing so i'm going to head over to release and download now you can see there's different versions the mpy and there's a regular py version you want the mpy version because it's actually a compressed version of the micro python and dealing with the board that just has limited space you do want to use the compressed version now once i am done downloading this i can extract this and inside i will have everything that the github had before which is all this stuff just compressed okay it actually mounts it as a little device on the side so you could actually pop over and see what's inside like if i was to go open circuit python device lib boot out and code you could see it's the same thing so what that means or what that allows me to do is transfer the library that i need so i'm going to head over to adafruit lib and adafruit hid and i'm going to transfer it into this lib folder you see that now so now i have all the libraries and the modules that i need to run the mouse so let's start coding something so first off what i'm going to do is see if it works so i'm going to do something like a blinky basically it's going to click multiple times and see if it's going to click so i'm going to import usb hid which is the module from python i'm just moving my keyboard a little now i'm going to also import actually from ada fruit hid dot mouse import mouse so now i have the library that i could use to use the mouse buttons so now i'm also going to do mouse equals capital mouse because that's what we named it from the import usb underscore hid dot devices and because if i click once you guys are probably not going to see it happen so what i'm going to do is while true and here i'm going to do mouse click mouse dot left button and that will basically infinitely click on the left mouse button now because i think it's going to click too fast i'm also going to import time and put like a little sleep feature in this i'm going to do time sleep 0.5 so every half a second it's going to click i'm going to save this and in circuit python it's not called main.py for it to boot the board with it so you want to save it over to code.py that will actually save it and now i can run the code and what it's going to do is just click you can see how the cursor is just moving to where i needed to every half a second it's going to click so i now i know it's definitely working so i'm going to stop this it is time to test it out on our egg incorporated game so i'm going to unplug this and pop it into my phone and see what happens all right so you see the mouse come up and it's already clicking it doesn't even actually give me a chance to cancel this so let me can't cancel can't there you go first you're going to notice that it's in the wrong position it's clicking but it's in the wrong position i needed to move it down to the bottom for it to click over here and all the other stuff that we talked about in the beginning of how this is gonna work we're basically draw it out so let's unplug this and pop it back into the computer all right now we know that it works with the android phone it pops up as a device we do have to put some sort of sleep timer because i need to be able to cancel out of that spot so the mouse can move down so now we know what we need to do so i'm going to pop into coding this and let's uh also make it so when it's running we would actually see the led light up and then when it's off it's going to be not lighting up so let's import a couple more modules so import board import digital io and we should have all the modules that we need now we know we have to call the mouse we also need to set up the gpio so we're going to do led equals digital io dot digital in out and it's in this case it's called gp25 and in our last video remember 25 is actually the led for the board in circuit python if it's gpio you call it gp if it's digital pin it's d if it's analog it's a so it's a25 or d25 so gp means for gpio now we also have to set the direction so we're going to do led led dot direction equals digital io dot direction dot output that's what we need and you know what just to make sure that it's gonna turn off we're gonna turn off the led in the beginning so here's gonna be the setup part so we're going to do led dot value equals false okay we also know we need to sleep it so we're going to sleep time that sleep for five seconds because this gives me time to press the cancel button when i plug it into my phone uh we're also going to do mouse move and we're going to move it y we're going to move it down by 400 okay and we are ready this is the little setup make sure the led is off sleep so i can press the cancel button mouse move 400 afterwards so we could actually go to the red chicken button and now this is our main loop that we need to edit now i know that we have to click 500 times after 500 times we can't click any more that's that's the base of it so we're going to do click equals 500. then we're going to put a condition here so we're going to do while click is greater than zero now we do this stuff over here which is mouse click left button and the timer we're gonna switch to a really fast click okay the faster it is the better and then we're also gonna start decreasing the number of clicks so we're gonna do click equals click minus one we're also gonna turn on the led so we're gonna do led value equals true now that we're done with the clicking and it's going to go through it 500 times here we could now tell it once it's done clicking 500 times we're going to set the value of the light to false and time dot sleep for 30 seconds because that's gonna give it the time to replenish the chicken coops so basically that's it if you minus the spaces which i have three spaces this line of code was only about 20 lines of code so let's save this i'm going to unplug this and pop it into my little phone all right gives me five seconds to cancel that the mouse didn't show up yet which is fine and there we have it it's clicking the mouse is uh it's coming in the led is on so i know it's running and as soon as that runs out and that runs out it stops for 30 seconds it lets it replenish i get the max [Music] so let's give it another 30 seconds over here and see if it um refreshes and clicks on it again because the while loop should kick back in after 30 seconds so let's see right about now it should start clicking and i i'm just waiting for the led to come back on oh there you go and it's clicking led is on chicken's coming back out there we have it guys we basically just created our own little uh auto clicker with the raspberry pi pico using their usb hid interface anyway if you guys enjoyed this video please hit that like button if you guys have any other project ideas you want me to test with the raspberry pi pico let me know down in the comments below and if you guys are new to this channel consider subscribing and also hit that bell notification icon so you know when the next video is going to be out and as a saying my nerd cave hack to lit hearts
Info
Channel: Novaspirit Tech
Views: 75,041
Rating: undefined out of 5
Keywords: novaspirit, tech, pico micropython, raspberry pi pico, micropython, rshell, thonny, raspberry pi, pico, circuitpython, raspberry pi pico micropython, raspberry pi pico projects, pico projects, rpi pico, micropython for raspberry pi pico, micropython for raspberry pi, circuit python, python, usb hid, usb_hid, adafruit_circuitpython_hid, auto clicker, clicker
Id: onBkPkaqDnk
Channel Id: undefined
Length: 11min 52sec (712 seconds)
Published: Tue Feb 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.