ESP32-S2 New Arduino USB Functionality: Cool Combination with WiFi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
up till now emulating a keyboard or a mouse was only possible with an arduino micro or a usb host shield with the new arduino support for the esp32 s2 i will show you how it can be done with our darling in addition we will add wi-fi to create remote locking to excel or other pc software if you have evil thoughts you can also use it as a wireless rubber ducky to hack other pcs or play a trick with your colleagues as a bonus we will deepen our knowledge of how usb works gritsy youtubers here is the guy with the swiss accent with a new episode and fresh ideas around sensors and microcontrollers remember if you subscribe you will always sit in the first row most of our boards have a usb connector so why is it not possible to emulate a keyboard or a mouse with them why is it possible with the arduino micro or the esp32 s2 how is it done and how can we remotely control it via wi-fi all valid questions which will be answered in this video the first question why are not all usb connections the same a usb connection needs two roles a host and one or many peripherals or devices each host can create multiple ports to offer a separate connection to each device the logical connection between a host and an end point in a device is called pipe more than one connection over the same cable is possible a webcam for example offers a video stream on one connection and an audio stream on the second one most of our devices have a usb to serial chip which only offers one usb device role and one endpoint the pc or the usb hub then is the host and we have a valid usb configuration but still we cannot emulate a keyboard or mouse with such a usb to serial adapter chip google says we need a host shield strange the keyboard is definitely a device and the pc is the host and still everybody writes that it does not work unless we use either a host shield with a max 34 e-chip or an arduino micro with a built-in usb function but we do not need host chips we only need chips that not only offer the device class communications and cdc control for serial communication moreover we need chips that also offer the human interface device or hid class because keyboards and mice belong to this class as a coincidence chips that offer these device classes also offer the host mode this is why i thought i need a host chip to emulate a hid for a long time now i know better anyway keyboard and mouse libraries for the host shield and for the micro exist for a long time i used these libraries already in video number 9 to create a locker to fill out excel sheets on a pc other than the original esp32 the s2 has a usb block included the new version 2.0.0 of the arduino framework supports this chip including the usb function it also supports the smaller c3 version by the way the c3 only offers the serial device like other usb to serial chips therefore it cannot emulate an hid we uncovered the myth of the keyboard as a host let's continue with another detail the two data pins of a usb connector are not rx and tx as many would expect instead they are called d plus and d minus and both are bi-directional but why do they use two wires for the same signal one would be sufficient if we use it in both directions because usb cables can be as long as 5 meters or 16 feet they can pick up a lot of noise to avoid negative impact the engineers used a trick they transmit the same signal on two wires instead of only one does this help no it would not help without the trick they reverse the polarity of one signal therefore the d plus and d minus lines the receiver subtracts one from the other and gets the original signal noise on the other hand is picked by both cables with the same polarity therefore it is eliminated when both signals are subtracted indeed a cool trick by the way do you know how you can create usb cables longer than 5 meters you include a range extender in the middle of the cable such an extender is a hub with only one port now your cable is already 10 meters long good to know if you need it enough about usb now we have to ask ourselves how can we use the esp32 s2 here i have a few boards with this chip the original from expressive one from ttgo and one from the unexpected maker or adafruit both are the same by the way for this video i will use the saula board from espressif all others should work the same all boards have one micro or usbc connector and we see that those two boards have a usb to serial chip and the usb connectors are connected to this chip the feather is different and has no such chip what the hell happened with the versatile usb function of the chip on these two boards we have to connect a female usb connector to gpio19 and 20. for all who saw my rtl8720 headache video expressive also has a confusing pin numbering the silk screen on the top has numbers from 0 to 46 the pin out diagram has two times numbers from 1 to 21 and the gpios are numbered in a third way because i'm now used to this crap i stay calm and continue i urge you to pay attention when connecting your new usb connector to gpio pins 19 and 20 because they have precisely the opposite numbering on the silk screen what a coincidence you can be sure i searched a while till i found the error in my cabling and please do not connect vcc of the new usb connector or if you do not trust me at least to the 5 volt pin and never to 3.3 volts now we have two usb connectors one more than with the arduino micro very convenient with only one connector you can become nearly crazy if you do not pay attention during keyboard emulation projects even arduino wants you to pay attention of course this warning is not needed if you work with two cables then you can always unplug the keyboard cable to stop if your sketch goes crazy let's continue with the programming i assume you already have installed the newest esp32 support in the arduino ide check if you have at least version 2.0.0 if you select the s2 dev module you find many examples let's have a look at this one it simply locks you out later we will see how you can drive your colleague crazy if we pimp it a bit if we look at the sketch we see that we need these two libraries plus the definition of this usb hid keyboard then we have to start the keyboard as well as the usb functionality that's it now our sketch can press and release keys as we would on the keyboard we can even press more than one key simultaneously like the control alt delete of windows they keep pressing until we release them cool we can also print whole sentences or whole values measured by our sensor with keyboard right you can include all ascii characters which exist on a keyboard you can open or close windows for example here is where your imagination starts so far everything is only on paper how do we get it into the esp as usual by upload it via the serial connector if we select usb cdc on boot our second usb connector acts as a keyboard if we connect it with our computer we hear a typical sound and we see the new serial connection if this does not happen you most probably mix pin 19 and 20 as i did also here i discovered a caveat if we select the cdc option serial does no more work on the standard port at least in my case not good because we lose the possibility for debugging maybe you know a trick to keep it working if your board does not have a usb to serial converter you should select this option and upload through their internal usb like with the arduino micro it enables to create smaller ports but as usual on this channel we want more all we saw up till now we could do with an old arduino micro now i want to combine what we learned with mqtt like that we can for example insert values measured by sensors into excel or we can log out our colleagues on their pcs from remote if you plug one of your prepared esp32 s2s somewhere hidden in a pc you have complete control over the keyboard they will love you my sketch is nicer it transfers temperature values from my weather station if i put the focus on an empty excel it is automatically filled over the air much better than with the arduinos you find this sketch on my github one thing however is not easy if you use a non-us keyboard you have to do some translation of characters otherwise you get some gibberish i create the mqtt messages in node-red all strings sent to the topic remote keyboard will end as keystrokes on the pc you could also use this telnet example and combine it with a usb keyboard function it then transfers all keystrokes of your keyboard directly to a remote pc this was my application what is your idea one more thing because the s2 also supports the mass storage device class it can be programmed to appear as a usb drive with this example file your s2 is recognized as a disk drive they even included a file on this disk and this file reveals us another secret they used the tiny usb library micro python uses this feature too to create a slick user interface as shown in video number 240. as always you find all the relevant links in the description i hope this video was useful or at least interesting for you if true please consider supporting the channel to secure its future existence thank you bye
Info
Channel: Andreas Spiess
Views: 86,718
Rating: undefined out of 5
Keywords: AliExpress, arduino, arduino project, diy, do-it-yourself, eevblog, electronics, esp32, esp32 datasheet, esp32 project, esp32 tutorial, esp8266 datasheet, Field Effect Transistor, greatscott, guide, hack, hobby, how to, iot, lora, lorawan, n-channel, nodemcu, npn, p-channel, pnp, project, simple, smart home, ttgo, tutorial, wemos, wifi, Raspberry Pi, Zoom, Microsoft, Teams, Home Assistant, Docker, Aliexpress, Amazon, Banggood, RTOS tutorial, rtos, freertos, freertos tutorial, freertos esp32, ESP32-S2, USB, HID
Id: XnqDEV21BSA
Channel Id: undefined
Length: 12min 31sec (751 seconds)
Published: Sun Nov 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.