Difference between revisions of "Template:ESP32 S2 Guide"

From Waveshare Wiki
Jump to: navigation, search
(Created page with "==Development Languages== ESP32-S2-Pico, ESP32-S2-LCD-0.96 can use CircuitPython, MicroPython, C/C++(Arduino, ESP-IDF) to develop products rapidly. The following are the brief...")
 
 
(72 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
==Development Languages==
 
==Development Languages==
ESP32-S2-Pico, ESP32-S2-LCD-0.96 can use CircuitPython, MicroPython, C/C++(Arduino, ESP-IDF) to develop products rapidly. The following are the brief introductions of three development manners.
+
ESP32-S2-Pico, ESP32-S2-LCD-0.96 can use CircuitPython, MicroPython, and C/C++(Arduino, ESP-IDF) to develop products rapidly. The following are brief introductions of three development manners.
 
===CircuitPython===
 
===CircuitPython===
As a programming language,[https://circuitpython.org/ CircuitPython] is designed to simplify coding experimentation and learning on low-cost microcontroller boards, is an open-source derivative of the MicroPython programming language that aimed at students and beginners, and developed and maintained by Adafruit Industries.
+
As a programming language, [https://circuitpython.org/ CircuitPython] is designed to simplify coding experimentation and learning on low-cost microcontroller boards, is an open-source derivative of the MicroPython programming language that is aimed at students and beginners, and developed and maintained by Adafruit Industries.
 
*Circuitpython's related application development reference [https://docs.micropython.org/en/latest/ Development Documentation]
 
*Circuitpython's related application development reference [https://docs.micropython.org/en/latest/ Development Documentation]
 
*[https://github.com/adafruit/Adafruit_CircuitPython_Bundle Github] library of Circuitpython can be recompiled for custom development.
 
*[https://github.com/adafruit/Adafruit_CircuitPython_Bundle Github] library of Circuitpython can be recompiled for custom development.
 
*[https://micropython.org/download/?mcu=esp32s2 Related firmware] of Circuitpython for different ESP32-S2 core boards.
 
*[https://micropython.org/download/?mcu=esp32s2 Related firmware] of Circuitpython for different ESP32-S2 core boards.
 +
 
===MicroPython===
 
===MicroPython===
Micropython is a lean and efficient implementation of the Python 3 programming language that includes a small portion of the Python standard library and is optimized to run on microcontrollers and constrained environments.
+
[https://micropython.org/ Micropython] is a lean and efficient implementation of the Python 3 programming language that includes a small portion of the Python standard library and is optimized to run on microcontrollers and constrained environments.
*Micropython related application development reference [https://docs.micropython.org/en/latest/ Development Documentation]
+
*Micropython-related application development reference [https://docs.micropython.org/en/latest/ Development Documentation].
*[https://github.com/micropython/micropython Github library] of Micropython can be recompiled for custom development
+
*[https://github.com/micropython/micropython Github library] of Micropython can be recompiled for custom development.
*[https://micropython.org/download/?mcu=esp32s2 Related firmware] of Micropython on different ESP32-S2 core boards
+
*[https://micropython.org/download/?mcu=esp32s2 Related firmware] of Micropython on different ESP32-S2 core boards.
 +
 
 
===C/C++ (Arduino, ESP-IDF)===
 
===C/C++ (Arduino, ESP-IDF)===
 
Espressif official  C/C++ library is easy for quick installment, please check the links below:
 
Espressif official  C/C++ library is easy for quick installment, please check the links below:
*[https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html Arduino development manual] of ESP32-S2
+
*[https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html Arduino development manual] of ESP32-S2.
*[https://docs.espressif.com/projects/esp-idf/en/stable/esp32s2/get-started/index.html ESP-IDF development manual] of ESP32-S2
+
*[https://docs.espressif.com/projects/esp-idf/en/stable/esp32s2/get-started/index.html ESP-IDF development manual] of ESP32-S2.
  
 
==Setup Environment==
 
==Setup Environment==
The environment is set under the Windows 10 system, the users can develop by using Arduino or ESP-IDF and Visual Studio Code as IDE. For Mac/Linux operating system users, please refer to the official instruction.
+
The environment is set under the Windows 10 system, the users can develop by using Arduino or ESP-IDF and Visual Studio Code as IDE. For Mac/Linux operating system users, please refer to [https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/index.html the official instruction].
 
===Arduino===
 
===Arduino===
 
; 1. Downloading and installing [https://www.arduino.cc/en/software Arduino IDE], please pay attention to the default configuration and the full English path.
 
; 1. Downloading and installing [https://www.arduino.cc/en/software Arduino IDE], please pay attention to the default configuration and the full English path.
 
:[[File:ESP32_One_020.jpg|400px]]
 
:[[File:ESP32_One_020.jpg|400px]]
; 2, Arduino install ESP32 library, detail install process is shown below, please refer to [https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html related information] for more information.
+
; 2. Arduino installs the ESP32 library, the detailed install process is shown below. Please refer to [https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html related information] for more information.
 
<pre>
 
<pre>
 
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
 
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Line 27: Line 29:
 
</pre>
 
</pre>
 
:[[File:ESP32-S2-Pico_005.jpg|400px]] [[File:ESP32-S2-Pico_006.jpg|400px]]
 
:[[File:ESP32-S2-Pico_005.jpg|400px]] [[File:ESP32-S2-Pico_006.jpg|400px]]
; 3, Open the VSCode, install Arduino and C/C++plugin (Microsoft Publisher)  
+
; 3. Open the VSCode, install Arduino and C/C++plugin (Microsoft Publisher)  
 
:[[File:ESP32_One_021.jpg|400px]]
 
:[[File:ESP32_One_021.jpg|400px]]
; 4, After installing plugin ,press F1 to enter Preferences Open Settings(UI),press Enter to find Arduino plugin setting.
+
; 4. After installing the plugin, press F1 to enter Preferences Open Settings(UI), press Enter to find the Arduino plugin setting.
 
:[[File: ESP32_One_024.jpg|400px]]
 
:[[File: ESP32_One_024.jpg|400px]]
; 5, Press F1 to enter Arduino Board Config, then press Enter.
+
; 5. Press F1 to enter Arduino Board Config, then press Enter.
 
:[[File:ESP32_One_025.jpg|400px]]
 
:[[File:ESP32_One_025.jpg|400px]]
  
 
===ESP-IDF===
 
===ESP-IDF===
1, Download and install the latest offline version of [https://dl.espressif.com/dl/esp-idf esp-idf-tools-setup], and place in the full English path and use the default configuration (automatic installation of ESP-IDF, Python, Git, and setting environment variables), place the path of ESP-IDF elsewhere.
+
1. Download and install the latest offline version of [https://dl.espressif.com/dl/esp-idf esp-idf-tools-setup], and place it in the full English path and use the default configuration (automatic installation of ESP-IDF, Python, Git, and setting environment variables), place the path of ESP-IDF elsewhere.
 
:[[File:ESP32-S2-Pico_007.jpg|400px]]
 
:[[File:ESP32-S2-Pico_007.jpg|400px]]
2, Download and install VS Code, place in the full English path, and use the default configuration.
+
2. Download and install [https://code.visualstudio.com/ VS Code], place in the full English path, and use the default configuration.
 
:[[File:ESP32_One_002.jpg|400px]]
 
:[[File:ESP32_One_002.jpg|400px]]
3, Open VS Code,press Ctrl+P,enter ext esp-idf-extension to install configuration plugin.
+
3. Open VS Code,press Ctrl+P, enter ext esp-idf-extension to install configuration plugin.
 
:[[File:ESP32_One_003.jpg|400px]]
 
:[[File:ESP32_One_003.jpg|400px]]
4, Press F1 in VSCode, enter Configure ESP-IDF extension to open the configure screen, and then choose USE EXISTING SETUP.
+
4. Press F1 in VSCode, enter Configure ESP-IDF extension to open the configure screen and then select USE EXISTING SETUP.
 
:[[File:ESP32_One_004.jpg|400px]]
 
:[[File:ESP32_One_004.jpg|400px]]
 
:[[File:ESP32_One_014.jpg|400px]]
 
:[[File:ESP32_One_014.jpg|400px]]
Line 47: Line 49:
 
:[[File:ESP32_One_007.jpg|400px]]
 
:[[File:ESP32_One_007.jpg|400px]]
  
 +
===CircuitPython===
 +
1. Download and install the latest [https://thonny.org/ Thonny IDE], open Thonny IDE -> Configure interpreter..., as shown below:<br/>
 +
[[File: CircuitPython Thonny01.jpg]]<br/>
 +
2. Press and hold the BOOT button on the board, and then connect the USB cable. Find the corresponding COM port or the device manager. Download and run the demo. See the Hardware Connections section for details.</br>
 +
3. Follow the steps in the figure below to select the CircuitPython firmware download for ESP32-S2. The Flash content of ESP32-S2-Pico will be cleared before the download, and the whole download process will last about 1 minute.<br/>
 +
[[File: CircuitPython Thonny02.jpg]]<br/>
 +
4. Please refer to [https://docs.circuitpython.org/en/latest/README.html CircuitPython Documentation] to program.<br/>
 +
<!--
 +
4. Modify the COM port enumerated by the user's computer in the following command, and enter the following command to clear the flash.
 +
esptool.py --chip esp32-s2 --port COM96 erase_flash
 +
5. Put the following bootloader.bin and other files ([https://www.waveshare.net/w/upload/6/69/ESP32-S2-Pico_Code.zip sample demo]) into the directory where esp-idf is installed, and then enter the following command, pay attention to the COM port enumerated by the user's computer.
 +
esptool.py --chip esp32s2 -p COM96 -b 460800 --before=default_reset --after=no_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x8000 partition-table.bin 0xe000 ota_data_initial.bin 0x1000 bootloader.bin 0x2d0000 tinyuf2.bin
 +
6. Then the disk will appear, and then drag CircuitPython's uf2 firmware to the disk.</br>
 +
7. Install and open Thonny[https://thonny.org/], select Tools->Options and set as shown below:
 +
[[File:thony.png]]
 +
-->
 +
 +
===MicroPython===
 +
1. Download and install the latest [https://thonny.org/ Thonny IDE], open Thonny IDE -> Configure interpreter..., as shown below:<br/>
 +
[[File: CircuitPython Thonny06.jpg]]<br/>
 +
2. Press and hold the BOOT button on the board, and then connect the USB cable. Find the corresponding COM port or the device manager. Download and run the demo. See the Hardware Connections section for details.</br>
 +
3. Follow the steps in the figure below to select the ESP32-S2 online MPY firmware download. The Flash content of ESP32-S2-Pico will be cleared before the download, and the whole download process will last about 1 minute.</br>
 +
[[File: CircuitPython Thonny03.jpg]]<br/>
 +
4. If you need to download [https://files.waveshare.com/upload/6/69/ESP32-S2-Pico_Code.zip offline firmware ESP32_S2_WROVER-20220117-v1.18.bin] on the Thonny IDE, you should operate it according to the following figure. Choose one from Step 3 and Step 4. It is recommended to follow Step 4.<br/>
 +
[[File: CircuitPython Thonny04.jpg]]<br/>
 +
5. Refer to [https://github.com/micropython/micropython/releases/tag/v1.18 MicroPython documentation] and [https://github.com/micropython/micropython/releases/tag/v1.18 releases note].
 +
 +
<!--
 +
4. Modify the COM port enumerated by the user's computer in the following command, and enter the following command to clear the flash.<br/>
 +
esptool.py --chip esp32-s2 --port COM96 erase_flash
 +
5. Put the following bin file ([https://files.waveshare.com/upload/6/69/ESP32-S2-Pico_Code.zip demo]) into the directory where esp-idf is installed, then enter the following command, pay attention to the COM port in the computer.<br/>
 +
esptool.py --chip esp32s2 --port COM96 write_flash -z 0x1000 ESP32_S2_WROVER-20220117-v1.18.bin
 +
6. Install and open [https://thonny.org/ Thonny], select Tools->Options, and set as shown below:<br/>
 +
 +
[[File:Thonny.png]]<br/>
 +
-->
 +
 +
<!--
 
==Hardware Connection==
 
==Hardware Connection==
*Connect the Raspberry Pi Pico expansion board to ESP32-S2-Pico or ESP32-S2-LCD-0.96 in a stacked manner, be careful to avoid pin cross-use, such as serial expansion board of GPIO pins in the same position
+
*Connect the Raspberry Pi Pico expansion board to ESP32-S2-Pico or ESP32-S2-LCD-0.96 in a stacked manner, be careful to avoid pin cross-use, such as serial expansion board of GPIO pins in the same position.
*Do not block the antenna part of ESP32-S2-Pico or ESP32-S2-LCD-0.96, and it's necessary to adjust the board orientation if the Wifi signal is poor.
+
*Do not block the antenna of ESP32-S2-Pico or ESP32-S2-LCD-0.96, and it's necessary to adjust the board orientation if the Wifi signal is poor.
*To download the program, you need to press and hold the BOOT button and then press the RESET button to release, Or disconnect the USB, then press and hold the BOOT button to power on. At this time, the UART0 (GPIO43, GPIO44) and USB of ESP32-S2 can be used for flash programs
+
*To download the program, you need to press and hold the BOOT button and then press the RESET button to release, or disconnect the USB, then press and hold the BOOT button to power on. At this time, the UART0 (GPIO43, GPIO44) and USB of ESP32-S2 can be used for flash programs.
*ESP32-S2-Pico or ESP32-S2-LCD-0.96 will print the status information of ESP32-S2 when powered on by default. If you want to cancel, you need to write parameters to the register as shown in the figure below. Note that it cannot be restored after modifying.
+
[[File:ESP32 S2 Guide010.jpg]]<br/>
 +
*ESP32-S2-Pico or ESP32-S2-LCD-0.96 will print the status information of ESP32-S2 when powered on by default. If you want to cancel, you need to write parameters to the register as shown in the figure below. Note that it cannot be restored after modification.
 +
-->
  
 
==Examples==
 
==Examples==
This section combines Arduino, Raspberry Pi Pico expansion board, using AD/DA, SPI, I2C, WiFi, and other peripherals of ESP32-S2.
+
===Arduino Example===
===ADC/DAC===
+
*In this section, we will combine Arduino, and the [https://www.waveshare.com/catalogsearch/result/?q=Pico- Pico expansion board], and utilize ESP32-S2's peripherals such as AD/DA, SPI, I2C, WiFi, etc.
*Be careful to configure as shown in the following below, enable USB CDC, and select USB update mode
+
*Please note that USB virtual serial port output requires selecting the option shown in the diagram below. Additionally, include the code to enable the USB virtual serial port in your program. You can refer to File->Examples->USB->USBSerial for code.
 +
 
 +
====ADC/DAC====
 +
*Be careful to configure as shown in the below, enable USB CDC, and select USB update mode.
 
*If there is an error in the download as shown in the figure below, indicating that you need to manually reset the board to run the program after downloading.
 
*If there is an error in the download as shown in the figure below, indicating that you need to manually reset the board to run the program after downloading.
 
:[[File:ESP32-S2-Pico_008.jpg|400px]]
 
:[[File:ESP32-S2-Pico_008.jpg|400px]]
; Codes
+
====='''Codes'''=====
*definite four AD, one DA macro, initialize the DA value of 127, and the USB serial output in the setup() function.
+
*Definite four AD, one DA macro, initialize the DA value of 127, and the USB serial output in the setup() function.
 
<pre>
 
<pre>
 
#define adc0 6
 
#define adc0 6
Line 72: Line 117:
  
 
void setup() {
 
void setup() {
   // put your setup code here, to run once:
+
   //Put your setup code here, to run once:
 
   HWSerial.begin(115200);
 
   HWSerial.begin(115200);
 
   HWSerial.setDebugOutput(true);
 
   HWSerial.setDebugOutput(true);
Line 86: Line 131:
 
}
 
}
 
</pre>
 
</pre>
*DA increases 1 every 5 seconds and loops from 0 until 255. Use one of the AD pins to connect DA to detect the operation of DA. Lines 28 to 30 are battery voltage detection.
+
*DA increases by 1 every 5 seconds and loops from 0 until 255. Use one of the AD pins to connect DA to detect the operation of DA. Lines 28 to 30 are battery voltage detection.
  
===UART===
+
====UART====
 
*Need to select configuration options as shown in AD_DA demo download, enable USB CDC, and select USB update mode
 
*Need to select configuration options as shown in AD_DA demo download, enable USB CDC, and select USB update mode
 
*If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the program.
 
*If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the program.
 
*UART demo combined with [https://www.waveshare.com/pico-gps-l76b.htm Pico-GPS-L76B] to read NMEA, parse and convert the coordinate system and output, etc.
 
*UART demo combined with [https://www.waveshare.com/pico-gps-l76b.htm Pico-GPS-L76B] to read NMEA, parse and convert the coordinate system and output, etc.
; Codes
+
====='''Codes'''=====
*Include NMEA0183 library, instantiate NMEA0183Msg, NMEA0183, specify the pin of serial 1
+
*Include NMEA0183 library, instantiate NMEA0183Msg, NMEA0183, specify the pin of serial 1.
*Specify the NMEA0183 data stream serial and baud rate in the NMEA0183.Begin() function, initialize the USB serial function, The loop() function polls the NMEA0183 data stream and then receives it
+
<pre>
===SPI===
+
/*
*You need to select the configuration, as shown in the  AD_DA routine download, enable USB CDC, and select update mode
+
* NMEA0183 library is from https://github.com/ttlappalainen/NMEA0183
*If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the program.
+
* Thanks to ttlappalainen
*This example tests the LCD of ESP32-S2-LCD-0.96 and scans WiFi hotspot information and then prints it
+
*/
; Codes
+
#include "NMEA0183.h"
Initiate USB serial and the STA mode of Wifi in setup(), turn on the LCD display in the loop() function, and print out the scanned WiFi information of the USB serial.
+
#include "NMEA0183Msg.h"
 +
#include "NMEA0183Messages.h"
 +
#include "USB.h"
 +
 
 +
#if ARDUINO_USB_CDC_ON_BOOT
 +
#define HWSerial Serial0
 +
#define USBSerial Serial
 +
#else
 +
#define HWSerial Serial
 +
USBCDC USBSerial;
 +
#endif
 +
 
 +
tNMEA0183Msg NMEA0183Msg;
 +
tNMEA0183 NMEA0183;
 +
 
 +
#define RXD2 3
 +
#define TXD2 2
 +
</pre>
 +
*Specify the NMEA0183 data stream serial and baud rate in the NMEA0183.Begin() function, initialize the USB serial function, The loop() function polls the NMEA0183 data stream and then receives it.
 +
<pre>
 +
void setup() {
 +
  // put your setup code here, to run once:
 +
  Serial1.begin(9600,SERIAL_8N1,RXD2,TXD2);
 +
  NMEA0183.Begin(&Serial1,1, 9600);
 +
 
 +
  HWSerial.begin(115200);
 +
  HWSerial.setDebugOutput(true);
 +
 
 +
  USB.onEvent(usbEventCallback);
 +
  USBSerial.onEvent(usbEventCallback);
 +
 
 +
  USBSerial.begin();
 +
  USB.begin();
 +
 
 +
  delay(4000);
 +
}
 +
 
 +
void loop() {
 +
  // put your main code here, to run repeatedly:
 +
  tNMEA0183Msg NMEA0183Msg;
 +
  while (NMEA0183.GetMessage(NMEA0183Msg)) {
 +
  USBSerial.printf(NMEA0183Msg.Sender());
 +
  USBSerial.printf(NMEA0183Msg.MessageCode());
 +
  for (int i=0; i < NMEA0183Msg.FieldCount(); i++) {
 +
    USBSerial.printf(NMEA0183Msg.Field(i));
 +
  }
 +
  USBSerial.printf("\n");
 +
 
 +
  /*
 +
    * To Be Done
 +
    * WGS84 coordinate convert to GCJ02 coordinate
 +
    */
 +
   
 +
  }
 +
}
 +
</pre>
 +
 
 +
====I2C====
 +
Take care to select configuration options as shown in the AD_DA demo download, enable USB CDC, and select USB update mode.
 +
 
 +
There is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after the download is complete to run the program.
 +
 
 +
This demo uses I2C to read the accelerometer, gyroscope, geomagnetometer, and barometer data on the Pico-10DOF-IMU and then fuses the data to calculate the current attitude. When powering on, please place the sensor according to the serial port information for local geomagnetic calibration.
 +
 
 +
After the demo download is complete, press the reset button, open the [https://files.waveshare.com/upload/b/b3/Sscom5.13.1.zip sscom serial port assistant], select the corresponding COM port, select DTR, and wait for the serial port to output the corresponding information for calibration.
 +
 
 +
[[File:SERIAL.png]]
 +
<div class="wiki-pages jet-green-color">
 +
====SPI====
 +
*You need to select the configuration, as shown in the  AD_DA demo download, enable USB CDC, and select update mode.
 +
*If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the demo.
 +
*This example tests the LCD of ESP32-S2-LCD-0.96 and scans the WiFi hotspot and then prints it.
 +
====='''Codes'''=====
 +
Initiate the USB serial and the STA mode of Wifi in setup(), turn on the LCD in the loop() function, and print out the scanned WiFi information of the USB serial.
 +
<div class="mw-collapsible-content">
 +
<pre>
 +
void setup() {
 +
  HWSerial.begin(115200);
 +
  HWSerial.setDebugOutput(true);
 +
 
 +
  USB.onEvent(usbEventCallback);
 +
  USBSerial.onEvent(usbEventCallback);
 +
 
 +
  USBSerial.begin();
 +
  USB.begin();
 +
 
 +
  WiFi.mode(WIFI_STA);
 +
  WiFi.disconnect();
 +
  delay(100);
 +
 
 +
  USBSerial.printf("Setup done");
 +
}
 +
 
 +
void loop() {
 +
//  USBSerial.printf("This is a test\r\n");
 +
 
 +
  led_init();
 +
  led_test();
 +
 
 +
  lcd_dev.lcd_init();
 +
  lcd_dev.lcd_test();
 +
 
 +
  USBSerial.printf("scan start\r\n");
 +
 
 +
    // WiFi.scanNetworks will return the number of networks found
 +
    int n = WiFi.scanNetworks();
 +
    USBSerial.printf("scan done\r\n");
 +
    if (n == 0) {
 +
        USBSerial.printf("no networks found\r\n");
 +
    } else {
 +
        USBSerial.printf("%d",n);
 +
        USBSerial.printf(" networks found\r\n");
 +
        for (int i = 0; i < n; ++i) {
 +
            // Print SSID and RSSI for each network found
 +
            USBSerial.printf("%d",i + 1);
 +
            USBSerial.printf(": ");
 +
            USBSerial.printf("%s",WiFi.SSID(i));
 +
            USBSerial.printf(" (");
 +
            USBSerial.printf("%d",WiFi.RSSI(i));
 +
            USBSerial.printf(")\r\n");
 +
            delay(10);
 +
        }
 +
    }
 +
    USBSerial.printf("\r\n");
 +
 
 +
    // Wait a bit before scanning again
 +
    delay(3000);
 +
}
 +
</pre>
 +
</div>
 +
</div>
 +
<div class="wiki-pages jet-green-color">
 +
====LCD====
 +
The LCD driver on ESP32-S2-LCD-0.96 uses [https://files.waveshare.com/upload/e/e2/ST7735S_V1.1_20111121.pdf ST7735], this summary uses TFT_eSPI library for display, pay attention to install arduino-esp32, TFT_eSPI and other libraries in advance.<br/>
 +
Open the User_Setup_Select.h and User_Setups/Setup43_ST7735.h files in the TFT_eSPI library folder (the default installation location, pay attention to the path in the figure below) and modify them as shown in the figure.<br/>
 +
[[File:ESP32-S2-Pico-lcd.png]]<br/>
 +
Add the initialization of the backlight pin to the setup() function of the example file of TFT_eSPI.<br/>
 +
[[File:ESP32-S2-Pico-lcd2.png]]<br/>
 +
 
 +
====e-Paper====
 +
Herein we use ESP32-S2-Pico or ESP32-S2-LCD-0.96 and Pico-ePaper-2.13 to demonstrate the [https://www.waveshare.com/catalogsearch/result/?q=Pico-eP Pico-ePaper] family of products. <br/>
 +
Download and unzip the examples\esp32-waveshare-epd folder in the [https://files.waveshare.com/upload/3/3d/E-Paper_ESP32_Driver_Board_Code.zip e-Paper ESP32 Driver Board] to the Arduino\libraries folder, then open the Arduino\libraries\esp32-waveshare-epd\src\DEV_Config.h file to change the relevant pins, as the picture shows:<br/>
 +
[[File:pico-epaper.png]]<br/>
 +
Open Arduino IDE, select the model in File -> Examples -> waveshare-e-Paper, and compile and download, as shown in the figure:
 +
[[File:pico-epaper2.png]]<br/>
 +
 
 +
===MPY Example===
 +
MPY stands for MiroPython, and in this section, we combine MPY, the [https://www.waveshare.com/catalogsearch/result/?q=Pico- Pico expansion board], with detailed examples in the MicroPython folder of [https://files.waveshare.com/upload/6/69/ESP32-S2-Pico_Code.zip the sample demo], see [https://docs.micropython.org/en/latest/esp32/quickref.html#pins-and-gpio Micropython Documents].

Latest revision as of 08:48, 22 January 2024

Development Languages

ESP32-S2-Pico, ESP32-S2-LCD-0.96 can use CircuitPython, MicroPython, and C/C++(Arduino, ESP-IDF) to develop products rapidly. The following are brief introductions of three development manners.

CircuitPython

As a programming language, CircuitPython is designed to simplify coding experimentation and learning on low-cost microcontroller boards, is an open-source derivative of the MicroPython programming language that is aimed at students and beginners, and developed and maintained by Adafruit Industries.

MicroPython

Micropython is a lean and efficient implementation of the Python 3 programming language that includes a small portion of the Python standard library and is optimized to run on microcontrollers and constrained environments.

C/C++ (Arduino, ESP-IDF)

Espressif official C/C++ library is easy for quick installment, please check the links below:

Setup Environment

The environment is set under the Windows 10 system, the users can develop by using Arduino or ESP-IDF and Visual Studio Code as IDE. For Mac/Linux operating system users, please refer to the official instruction.

Arduino

1. Downloading and installing Arduino IDE, please pay attention to the default configuration and the full English path.
ESP32 One 020.jpg
2. Arduino installs the ESP32 library, the detailed install process is shown below. Please refer to related information for more information.
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
https://www.arduino.cn/package_esp32_dev_index.json
ESP32-S2-Pico 005.jpg ESP32-S2-Pico 006.jpg
3. Open the VSCode, install Arduino and C/C++plugin (Microsoft Publisher)
ESP32 One 021.jpg
4. After installing the plugin, press F1 to enter Preferences Open Settings(UI), press Enter to find the Arduino plugin setting.
ESP32 One 024.jpg
5. Press F1 to enter Arduino Board Config, then press Enter.
ESP32 One 025.jpg

ESP-IDF

1. Download and install the latest offline version of esp-idf-tools-setup, and place it in the full English path and use the default configuration (automatic installation of ESP-IDF, Python, Git, and setting environment variables), place the path of ESP-IDF elsewhere.

ESP32-S2-Pico 007.jpg

2. Download and install VS Code, place in the full English path, and use the default configuration.

ESP32 One 002.jpg

3. Open VS Code,press Ctrl+P, enter ext esp-idf-extension to install configuration plugin.

ESP32 One 003.jpg

4. Press F1 in VSCode, enter Configure ESP-IDF extension to open the configure screen and then select USE EXISTING SETUP.

ESP32 One 004.jpg
ESP32 One 014.jpg
ESP32 One 006.jpg
ESP32 One 007.jpg

CircuitPython

1. Download and install the latest Thonny IDE, open Thonny IDE -> Configure interpreter..., as shown below:
CircuitPython Thonny01.jpg
2. Press and hold the BOOT button on the board, and then connect the USB cable. Find the corresponding COM port or the device manager. Download and run the demo. See the Hardware Connections section for details.
3. Follow the steps in the figure below to select the CircuitPython firmware download for ESP32-S2. The Flash content of ESP32-S2-Pico will be cleared before the download, and the whole download process will last about 1 minute.
CircuitPython Thonny02.jpg
4. Please refer to CircuitPython Documentation to program.

MicroPython

1. Download and install the latest Thonny IDE, open Thonny IDE -> Configure interpreter..., as shown below:
CircuitPython Thonny06.jpg
2. Press and hold the BOOT button on the board, and then connect the USB cable. Find the corresponding COM port or the device manager. Download and run the demo. See the Hardware Connections section for details.
3. Follow the steps in the figure below to select the ESP32-S2 online MPY firmware download. The Flash content of ESP32-S2-Pico will be cleared before the download, and the whole download process will last about 1 minute.
CircuitPython Thonny03.jpg
4. If you need to download offline firmware ESP32_S2_WROVER-20220117-v1.18.bin on the Thonny IDE, you should operate it according to the following figure. Choose one from Step 3 and Step 4. It is recommended to follow Step 4.
CircuitPython Thonny04.jpg
5. Refer to MicroPython documentation and releases note.


Examples

Arduino Example

  • In this section, we will combine Arduino, and the Pico expansion board, and utilize ESP32-S2's peripherals such as AD/DA, SPI, I2C, WiFi, etc.
  • Please note that USB virtual serial port output requires selecting the option shown in the diagram below. Additionally, include the code to enable the USB virtual serial port in your program. You can refer to File->Examples->USB->USBSerial for code.

ADC/DAC

  • Be careful to configure as shown in the below, enable USB CDC, and select USB update mode.
  • If there is an error in the download as shown in the figure below, indicating that you need to manually reset the board to run the program after downloading.
ESP32-S2-Pico 008.jpg
Codes
  • Definite four AD, one DA macro, initialize the DA value of 127, and the USB serial output in the setup() function.
#define adc0 6
#define adc1 7
#define adc2 8
#define adc3 1
#define dac_pin 17

uint16_t adc_Value = 0;    // variable to store the value coming from the sensor
uint8_t dac_value = 127; //DA output value

void setup() {
  //Put your setup code here, to run once:
  HWSerial.begin(115200);
  HWSerial.setDebugOutput(true);
  
  USB.onEvent(usbEventCallback);
  USBSerial.onEvent(usbEventCallback);
  
  USBSerial.begin();
  USB.begin();

  delay(4000);
//  USBSerial.printf("Setup done");
}
  • DA increases by 1 every 5 seconds and loops from 0 until 255. Use one of the AD pins to connect DA to detect the operation of DA. Lines 28 to 30 are battery voltage detection.

UART

  • Need to select configuration options as shown in AD_DA demo download, enable USB CDC, and select USB update mode
  • If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the program.
  • UART demo combined with Pico-GPS-L76B to read NMEA, parse and convert the coordinate system and output, etc.
Codes
  • Include NMEA0183 library, instantiate NMEA0183Msg, NMEA0183, specify the pin of serial 1.
/*
 * NMEA0183 library is from https://github.com/ttlappalainen/NMEA0183
 * Thanks to ttlappalainen 
 */
#include "NMEA0183.h"
#include "NMEA0183Msg.h"
#include "NMEA0183Messages.h"
#include "USB.h"

#if ARDUINO_USB_CDC_ON_BOOT
#define HWSerial Serial0
#define USBSerial Serial
#else
#define HWSerial Serial
USBCDC USBSerial;
#endif

tNMEA0183Msg NMEA0183Msg;
tNMEA0183 NMEA0183;

#define RXD2 3
#define TXD2 2
  • Specify the NMEA0183 data stream serial and baud rate in the NMEA0183.Begin() function, initialize the USB serial function, The loop() function polls the NMEA0183 data stream and then receives it.
void setup() {
  // put your setup code here, to run once:
  Serial1.begin(9600,SERIAL_8N1,RXD2,TXD2);
  NMEA0183.Begin(&Serial1,1, 9600);

  HWSerial.begin(115200);
  HWSerial.setDebugOutput(true);
  
  USB.onEvent(usbEventCallback);
  USBSerial.onEvent(usbEventCallback);
  
  USBSerial.begin();
  USB.begin();

  delay(4000);
}

void loop() {
  // put your main code here, to run repeatedly:
  tNMEA0183Msg NMEA0183Msg;
  while (NMEA0183.GetMessage(NMEA0183Msg)) {
  USBSerial.printf(NMEA0183Msg.Sender());
  USBSerial.printf(NMEA0183Msg.MessageCode());
  for (int i=0; i < NMEA0183Msg.FieldCount(); i++) {
    USBSerial.printf(NMEA0183Msg.Field(i));
  }
  USBSerial.printf("\n");

   /*
    * To Be Done
    * WGS84 coordinate convert to GCJ02 coordinate
    */
    
  }
}

I2C

Take care to select configuration options as shown in the AD_DA demo download, enable USB CDC, and select USB update mode.

There is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after the download is complete to run the program.

This demo uses I2C to read the accelerometer, gyroscope, geomagnetometer, and barometer data on the Pico-10DOF-IMU and then fuses the data to calculate the current attitude. When powering on, please place the sensor according to the serial port information for local geomagnetic calibration.

After the demo download is complete, press the reset button, open the sscom serial port assistant, select the corresponding COM port, select DTR, and wait for the serial port to output the corresponding information for calibration.

SERIAL.png

SPI

  • You need to select the configuration, as shown in the AD_DA demo download, enable USB CDC, and select update mode.
  • If there is an error message in the download, as shown in the AD_DA demo download, and it needs to be reset manually after downloading to run the demo.
  • This example tests the LCD of ESP32-S2-LCD-0.96 and scans the WiFi hotspot and then prints it.
Codes

Initiate the USB serial and the STA mode of Wifi in setup(), turn on the LCD in the loop() function, and print out the scanned WiFi information of the USB serial.

void setup() {
  HWSerial.begin(115200);
  HWSerial.setDebugOutput(true);
  
  USB.onEvent(usbEventCallback);
  USBSerial.onEvent(usbEventCallback);
  
  USBSerial.begin();
  USB.begin();

  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  USBSerial.printf("Setup done");
}

void loop() {
//  USBSerial.printf("This is a test\r\n");

  led_init();
  led_test();
  
  lcd_dev.lcd_init();
  lcd_dev.lcd_test();

  USBSerial.printf("scan start\r\n");

    // WiFi.scanNetworks will return the number of networks found
    int n = WiFi.scanNetworks();
    USBSerial.printf("scan done\r\n");
    if (n == 0) {
        USBSerial.printf("no networks found\r\n");
    } else {
        USBSerial.printf("%d",n);
        USBSerial.printf(" networks found\r\n");
        for (int i = 0; i < n; ++i) {
            // Print SSID and RSSI for each network found
            USBSerial.printf("%d",i + 1);
            USBSerial.printf(": ");
            USBSerial.printf("%s",WiFi.SSID(i));
            USBSerial.printf(" (");
            USBSerial.printf("%d",WiFi.RSSI(i));
            USBSerial.printf(")\r\n");
            delay(10);
        }
    }
    USBSerial.printf("\r\n");

    // Wait a bit before scanning again
    delay(3000);
}

LCD

The LCD driver on ESP32-S2-LCD-0.96 uses ST7735, this summary uses TFT_eSPI library for display, pay attention to install arduino-esp32, TFT_eSPI and other libraries in advance.
Open the User_Setup_Select.h and User_Setups/Setup43_ST7735.h files in the TFT_eSPI library folder (the default installation location, pay attention to the path in the figure below) and modify them as shown in the figure.
ESP32-S2-Pico-lcd.png
Add the initialization of the backlight pin to the setup() function of the example file of TFT_eSPI.
ESP32-S2-Pico-lcd2.png

e-Paper

Herein we use ESP32-S2-Pico or ESP32-S2-LCD-0.96 and Pico-ePaper-2.13 to demonstrate the Pico-ePaper family of products.
Download and unzip the examples\esp32-waveshare-epd folder in the e-Paper ESP32 Driver Board to the Arduino\libraries folder, then open the Arduino\libraries\esp32-waveshare-epd\src\DEV_Config.h file to change the relevant pins, as the picture shows:
Pico-epaper.png
Open Arduino IDE, select the model in File -> Examples -> waveshare-e-Paper, and compile and download, as shown in the figure: Pico-epaper2.png

MPY Example

MPY stands for MiroPython, and in this section, we combine MPY, the Pico expansion board, with detailed examples in the MicroPython folder of the sample demo, see Micropython Documents.