Brancher des périphériques USB sur un ESP8266 : Différence entre versions

Ligne 46 : Ligne 46 :
 
Malheureusement avant de pouvoir brancher notre USB Host, il va nous falloir '''régler plusieurs problèmes''' sinon '''cela ne marchera pas.'''
 
Malheureusement avant de pouvoir brancher notre USB Host, il va nous falloir '''régler plusieurs problèmes''' sinon '''cela ne marchera pas.'''
 
|Step_Picture_00=Brancher_des_périphériques_USB_sur_un_ESP8266_3V3_only.png
 
|Step_Picture_00=Brancher_des_périphériques_USB_sur_un_ESP8266_3V3_only.png
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Régler le problème d'alimentation
 +
|Step_Content=If you buy a '''clone of the USB Host Mini''', there is no jumper for VBUS.This means your '''USB devices''' will be '''powered with 3.3v''', which didn't works with any of my devices who all require '''5V.'''
 +
 +
You can find more details here: https://ht-deko.com/arduino/shield_usbhost_mini.html (in japanese)
 +
 +
You will have to cut this trace, to fix this.I used a '''small screw driver''' to do this, but you probably should use a '''small cutter instead.'''
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Brancher l'USB Host
 +
|Step_Content=OK, I hope you didn't break your board! Now it is time to plug it!
 +
 +
I used a '''Wemos Mini D1''' with my USB Host Mini device, here is how to plug it.
 +
 +
{{Info|Je n'ai pas relier la broche INT, car celle-ci ne semble pas nécessaire au fonctionnement}}<br />
 +
 +
* D3 -- SS
 +
* D7 -- MISO
 +
* D6 -- MOSI
 +
* D5 -- SCK
 +
* RST -- RST
 +
 +
<br />
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Régler le problème avec la bibliothèque USB Host
 +
|Step_Content=You may have notice SS (Chip Select/CS) is plugged on '''D3 instead of D8.'''
 +
 +
I run into an issue where the USB Host set my Wemos Mini in '''firmware flashing''' mode, which '''stop the sketch from running.'''https://github.com/felis/USB_Host_Shield_2.0/issues/457
 +
 +
In order to '''change the SS pin,''' we need to change a line in the library.
 +
 +
Download '''USB Host Shield Library 2.0'''
 +
 +
Open '''UsbCore.h''' in '''libraries/USB_Host_Shield_Library_2.0''' and change this line
 +
<code>#elif defined(ESP8266)typedef MAX3421e<P15, P5> MAX3421E; // ESP8266 boards
 +
</code>
 +
With this line
 +
<code>#elif defined(ESP8266)typedef MAX3421e<P0, P5> MAX3421E; // ESP8266 boards
 +
</code>
 +
Notice we used '''P0''' instead of '''D3,''' it is because '''GPIO0''' is '''D3''' on the '''Wemos Mini'''.https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Downgrader ESP8266
 +
|Step_Content=OK, we are almost done, if you try to compile an example from the library, '''it will not works.'''
 +
 +
'''''Note''''' '': This was recently fix, so this step is only required if your version of '''USB Host Shield Library 2.0''' is '''1.3.2 or lower'''.''
 +
 +
It is because the library is not compatible with Arduino ESP8266 2.5, '''you need to downgrade it to 2.4.2'''https://github.com/felis/USB_Host_Shield_2.0/issues/449
 +
 +
Go to '''Tools / Boards / Boards Manager''' and change your version to '''2.4.2.'''
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Test l'USB Host
 +
|Step_Content=There is a lot of examples in '''''USB Host Shield Library 2.0'''In'' order to test that everything is working correctly, you should first try '''USB_desc.'''
 +
 +
* '''Upload''' USB_desc
 +
* Open '''Serial Monitor''' (115200)
 +
* '''Plug an USB device'''
 +
* '''Reset your board''' (ESP8266)
 +
 +
''Note: You can't hot-plug your USB device (at least in the examples), you need to '''reset the board''' each times you '''unplug, plug''' your device.''
 +
 +
You should see a message like this:
 +
 +
<br />
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Exemple : Manette XBOX360
 +
|Step_Content=If you have an '''XBOX360 for PC,''' use the example '''XBOX/XBOXUSB'''
 +
 +
* '''L2/R2''' vibrates when you press it.
 +
* L2/R2 : 0/255
 +
* Stick (Hat) X/Y : -32768 / 32768
 +
* Led can also be control ! (use the '''pad''' / '''back''' / '''start''' / '''xbox''' buttons to try it)
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Exemple : Souris
 +
|Step_Content=I didn't manage to make my mouse works.The example is in '''HID/USBHIDBootMouse'''
 +
}}
 +
{{ {{tntn|Tuto Step}}
 +
|Step_Title=Exemple : Contrôleur Midi
 +
|Step_Content=Open '''USBH_MIDI/USBH_MIDI_dump''' example
 +
 +
Most Midi devices, will only use a small part of the buffer ('''bufMidi''')
 +
 +
<code>00001679: 64: 09 90 2F 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code>
 +
 +
<code>0000174A: 64: 08 80 2F 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00</code>
 +
 +
* bufMidi[0] : Note ON (9) / Note OFF (8)
 +
* bufMidi[2] : Note
 +
* bufMidi[3] : Velocity
 +
 +
=== Summary ===
 +
Using USB devices open up a lot of possibilities for our microcontroller, we only touch the surface of all the thing we can do with this USB Host device.
 +
 +
* You can use a '''USB Hub''' to use multiple USB devices.
 +
* There are a lot of pins on the USB Host, it is because there are GPIO on it! You can plug '''buttons''' / '''leds''' even an '''LCD screen''' on it!
 +
* You can also use '''USB drive.'''
 
}}
 
}}
 
{{ {{tntn|Notes}}
 
{{ {{tntn|Notes}}

Version du 21 avril 2019 à 13:50

Auteur avatarRémi Sarrailh (µsini) | Dernière modification 9/11/2020 par Madnerd

Brancher des périphériques USB sur un ESP8266 usbhost wiki.jpg
Saviez vous que vous pouvez brancher des périphériques USB sur un Arduino ou un ESP ? Que ce soit un clavier, une souris, un manette de jeu ou un contrôleur MIDI, c'est possible !

Introduction

Je jouais avec Mozzi, une bibliothèque de synthèse audio (https://sensorium.github.io/Mozzi/), quand je me suis rendu compte que si je voulais vraiment pouvoir exploiter tout le potentiel de cette bibliothèque, j'allais devoir faire un contrôleur.

Si seulement, je pouvais brancher un clavier, ou un contrôleur midi, ça serait carrément plus simplement ! Mais attends ?! C'est possible en fait!

Video d'introduction

Matériaux

  • Un microcontrôleur 3.3v (par ex: Wemos Mini)
  • Un USB Host Mini

Outils

Un petit tournevis plat / Un cutter fin

Étape 1 - Choisir l'USB Host

Merci à CircuitatHome pour la création de l'USB Host https://www.circuitsathome.com/usb-host-shield-hardware-manual/

Dans ce tutoriel nous allons utilisé un clone de l'USB Host Mini.

La puce sur celle-ci est un MAX3421E qui ne fonctionne quand 3.3v

Si vous voulez utiliser un microcontrôleur en 5v (comme l'Arduino Uno / Nano) utiliser le Shield USB Host plutôt.

Malheureusement avant de pouvoir brancher notre USB Host, il va nous falloir régler plusieurs problèmes sinon cela ne marchera pas.




Étape 2 - Régler le problème d'alimentation

If you buy a clone of the USB Host Mini, there is no jumper for VBUS.This means your USB devices will be powered with 3.3v, which didn't works with any of my devices who all require 5V.

You can find more details here: https://ht-deko.com/arduino/shield_usbhost_mini.html (in japanese)

You will have to cut this trace, to fix this.I used a small screw driver to do this, but you probably should use a small cutter instead.

Étape 3 - Brancher l'USB Host

OK, I hope you didn't break your board! Now it is time to plug it!

I used a Wemos Mini D1 with my USB Host Mini device, here is how to plug it.

Je n'ai pas relier la broche INT, car celle-ci ne semble pas nécessaire au fonctionnement

  • D3 -- SS
  • D7 -- MISO
  • D6 -- MOSI
  • D5 -- SCK
  • RST -- RST


Étape 4 - Régler le problème avec la bibliothèque USB Host

You may have notice SS (Chip Select/CS) is plugged on D3 instead of D8.

I run into an issue where the USB Host set my Wemos Mini in firmware flashing mode, which stop the sketch from running.https://github.com/felis/USB_Host_Shield_2.0/issues/457

In order to change the SS pin, we need to change a line in the library.

Download USB Host Shield Library 2.0

Open UsbCore.h in libraries/USB_Host_Shield_Library_2.0 and change this line

#elif defined(ESP8266)typedef MAX3421e<P15, P5> MAX3421E; // ESP8266 boards

With this line

#elif defined(ESP8266)typedef MAX3421e<P0, P5> MAX3421E; // ESP8266 boards

Notice we used P0 instead of D3, it is because GPIO0 is D3 on the Wemos Mini.https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/

Étape 5 - Downgrader ESP8266

OK, we are almost done, if you try to compile an example from the library, it will not works.

Note : This was recently fix, so this step is only required if your version of USB Host Shield Library 2.0 is 1.3.2 or lower.

It is because the library is not compatible with Arduino ESP8266 2.5, you need to downgrade it to 2.4.2https://github.com/felis/USB_Host_Shield_2.0/issues/449

Go to Tools / Boards / Boards Manager and change your version to 2.4.2.

Étape 6 - Test l'USB Host

There is a lot of examples in USB Host Shield Library 2.0In order to test that everything is working correctly, you should first try USB_desc.

  • Upload USB_desc
  • Open Serial Monitor (115200)
  • Plug an USB device
  • Reset your board (ESP8266)

Note: You can't hot-plug your USB device (at least in the examples), you need to reset the board each times you unplug, plug your device.

You should see a message like this:


Étape 7 - Exemple : Manette XBOX360

If you have an XBOX360 for PC, use the example XBOX/XBOXUSB

  • L2/R2 vibrates when you press it.
  • L2/R2 : 0/255
  • Stick (Hat) X/Y : -32768 / 32768
  • Led can also be control ! (use the pad / back / start / xbox buttons to try it)

Étape 8 - Exemple : Souris

I didn't manage to make my mouse works.The example is in HID/USBHIDBootMouse

Étape 9 - Exemple : Contrôleur Midi

Open USBH_MIDI/USBH_MIDI_dump example

Most Midi devices, will only use a small part of the buffer (bufMidi)

00001679: 64: 09 90 2F 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

0000174A: 64: 08 80 2F 7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

  • bufMidi[0] : Note ON (9) / Note OFF (8)
  • bufMidi[2] : Note
  • bufMidi[3] : Velocity

Summary

Using USB devices open up a lot of possibilities for our microcontroller, we only touch the surface of all the thing we can do with this USB Host device.

  • You can use a USB Hub to use multiple USB devices.
  • There are a lot of pins on the USB Host, it is because there are GPIO on it! You can plug buttons / leds even an LCD screen on it!
  • You can also use USB drive.

Commentaires

Draft