GNU/Linux & USB - Accessing USB Out Endpoints in Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the episode of make News slash Linux and USB tutorials in my last video we have implemented our first endpoint on this at megaforial to you for microcontroller and in today's video I want to show you how to access this bulk endpoint over python and I have to mention my last video I make two major mistakes it might be firmware for this microcontroller here so please check up or check out the latest version of GitHub where I fixed these issues here Okay cool so what are we going to do today first I will list all USB devices found on my system and here this device here is our app Mega 32u for USB device and when I take a look at the endpoint which are implemented on this device I can see we have one endpoint and this endpoint um is from the type bot transfer so bot transfer is what you would use for a USB Mass Storage to transfer data without any latency or guaranteed bandwidth it's from the direction is out so this means the data is sent from the PC to the device and the size is 8 bytes and with these or with this endpoint I can control up to 8 gpio output pins of this microcontroller and here on this table here on the spreadsheet here I have um specify the interface so we have eight bytes and over each byte we can change the value of uh um of the output value of the GPI open and here bit 0 means if bit 0 is set to 0 this means I will not change the output status of this gpio open but if it's set to 1 this is a command for change the output value to the value which is stored in bit 1 here so in bit 1 if you write a 1 to it we can turn an LED on if we write the zero to it we will turn the LED off and the same is true for all the other um for all the other bytes here and bit 2 to 7 of each byte is unused right now but later when we Implement more functionality we will also use them here okay so now we need what we need so now we know what we need to do so let me fire up iPhone and let's write a small script to turn some LEDs on or off okay so from I will import usb.core to access my USB device and the first thing I will do is I will search for a USB device with the vendor ID or ID vendor yeah is zero free EP and uh ID product is equal to one okay so let's check if we found a device yes we found a device here cool and now let's get the configuration of this device therefore I will execute the get active configuration function here and if I look at this configuration we see it's configuration one and um this configuration is bus powered and can use up to 500 milliampere of current okay and now I want to get my endpoint to get my endpoint I will use my configuration and here I will get so what does this mean here so each configuration has interfaces attached to them and here I want to get the interface with index 0 and with the alternate settings index of zero so now I should have oh this is a interface not a endpoint and if I look at interface I see I have a render specific interface here and of this interface I want to get the first endpoint and this is input the endpoint one I've implemented on this controller okay now we already have everything we need now all we have to do is we have to execute the right function and then we can set the value of the gpos but first I will declare a byte array with eight bytes three and now let's say we want to set all the LEDs to one okay therefore I will do the following I have only connected four LEDs here so I can only set for LEDs so for I in range 4 data I is free so this means change the value of the GPA open and set it to 1. okay so this is how our battery looks like right now and I will execute the right function and I want to write my battery out yes and you can see all the LEDs are turned on now to turn let's say we want to turn two LEDs off again let's say I want to turn LED one and three off again so I will set the data field here to one so this means change the value but set it to zero and I will do the same for Led free so let's do transfer again and now you can see these two LEDs are turned off now Okay cool so that's how to access endpoints or USB out and points over python so I hope you've enjoyed the video and learned something in case you want to support my work you can buy me a coffee on buy my coffee.com Johannes for Linux so that's it for today thanks for watching and goodbye
Info
Channel: Johannes 4GNU_Linux
Views: 2,221
Rating: undefined out of 5
Keywords:
Id: Pig-M6zHX54
Channel Id: undefined
Length: 6min 23sec (383 seconds)
Published: Mon Nov 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.