ESP32 basic configuration and hello world
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.8 KiB

  1. # Testing the ESP32 and Arduino IDE
  2. ## Introduction
  3. This repository shows the basic usage of the Arduino IDE with the ESP32 development board by implementing a blinking LED and serial communication.
  4. # Programming the ESP32 Board
  5. For this example course, we are going to use the ESP32-S WROOM, **please check what board you are using**.
  6. ![](./esp32swroom.jpg)
  7. then, we need to install the Arduino IDE to program the ESP32.
  8. ## Installing the Arduino IDE
  9. The Arduino IDE can be installed on *Windows, MacOS, or GNU Linux*, the Windows and MacOS installation is commonly using the installer. In the case of the *GNU Linux* it is highly recommended to use the distribution's package manger. In my case, the ArchLinux manager is *pacman*, thus use:
  10. ```
  11. sudo pacman -Sy arduino
  12. [sudo] password for gmarx:
  13. :: Synchronizing package databases...
  14. core 157.9 KiB 235 KiB/s 00:01 [####################################] 100%
  15. extra 1710.6 KiB 3.66 MiB/s 00:00 [####################################] 100%
  16. community 6.7 MiB 7.49 MiB/s 00:01 [####################################] 100%
  17. warning: arduino-1:1.8.19-1 is up to date -- reinstalling
  18. resolving dependencies...
  19. looking for conflicting packages...
  20. Packages (1) arduino-1:1.8.19-1
  21. Total Installed Size: 59.36 MiB
  22. Net Upgrade Size: 0.00 MiB
  23. :: Proceed with installation? [Y/n]
  24. ```
  25. **Note: The Arduino IDE requires Java jdk8 and jre8 installed on the OS.**
  26. **Note: You can install a Dark theme by [following these instructions]()**
  27. ## Adding the ESP32 Boards
  28. The addition of the ESP32 boards requires to include a URL to download a *Board Manager* by clicking on `File -> Preferences` and pasting the URL `https://dl.espressif.com/dl/package_esp32_index.json` in the field *Additional Boards Manager URLs*:
  29. ```
  30. https://dl.espressif.com/dl/package_esp32_index.json
  31. ```
  32. ![](./board.png)
  33. Next, we can install the ESP32 board on Arduino IDE by `Tools -> Board -> Boards Manager ...`, and writte `ESP32` to install the tools required to work with:
  34. ![](./install-board.png)
  35. # Sample code to test ESP32
  36. Before start programming the ESP32 board we have to select the proper board in the `Board` tool. Thus, again open and select the `Tools -> Bord -> DOIT ESP32 DEVKIT V1`. Then, paste the next code segtion to test the ESP32 board; the code is also the `blinking-serial.ino`file:
  37. ```
  38. /*
  39. *
  40. * Example code for ESP32-S:
  41. * The code blinks the onboard LED (at D2 in GPIO 02) every 0.500 seconds.
  42. * The code also prints by serial communcation the word "Hello" during the
  43. * ON stage of the LED, and then prints "World" during the OFF.
  44. * Gerardo Marx 19/Jul/2022
  45. */
  46. // this variable is defined in pins_arduino.h for DOIT ESP32 DEVKIT V1
  47. // int LED_BUILTIN = 02;
  48. int LED_ONBOARD = 02;
  49. void setup() {
  50. // put your setup code here, to run once:
  51. pinMode(LED_BUILTIN, OUTPUT);
  52. //serial monitor setup
  53. Serial.begin(115200);
  54. }
  55. void loop() {
  56. // put your main code here, to run repeatedly:
  57. Serial.print("ON");
  58. digitalWrite(LED_BUILTIN, HIGH);
  59. delay(500);
  60. // after delay
  61. Serial.print(" - OFF\n");
  62. digitalWrite(LED_BUILTIN, LOW);
  63. delay(500);
  64. ```
  65. next, press `Crt-u` to compile and upload the code generated into the board.
  66. ## The error `no module named serial`
  67. If you get an error like this:
  68. ```
  69. ModuleNotFoundError: No module named 'serial'
  70. exit status 1
  71. Error compiling for board DOIT ESP32 DEVKIT V1.
  72. ```
  73. then, it is necessary to install in python:
  74. ```
  75. pip3 install pyserial
  76. ```
  77. and must probably you will requiere pip3 python package manager:
  78. ```
  79. sudo pacman -Sy python-pip
  80. ```
  81. ## `Permission denied: '/dev/ttyUSB0'`
  82. ```
  83. ls -l /dev/ttyUSB0
  84. crw-rw---- 1 root uucp 188, 0 Aug 7 14:50 /dev/ttyUSB0
  85. ```
  86. ```
  87. sudo usermod -a -G uucp $USER
  88. groups
  89. libvirt uucp gmarx
  90. ```
  91. **Note: you need to relogin into you session.**