时间显示 基于ssd1306 I2C 调用开源库 事半功倍
简介
FireBeetle 2 ESP32-S3可以使用Arduino IDE、ESP-IDF、MicroPython进行编程,C语言、python都可以轻松的操纵硬件。我选择以vscode为主,插件platformio,需要安装python3.
Purple Pi开发板通过J12排针提供了丰富的GPIO接口,包括UART、SPI、I2C、GPIO等(还包括DC5V、DC3.3V、GND)。
引脚概述
- GPIO:常规引脚
- Analog:模拟输入引脚
- ADC:模数转换
- TOUCH:触摸引脚
- SPI:SPI接口
- I2C:I2C接口
- UART:UART接口
- USB:USB接口
- JTAG:调试接口
- 3V3:3.3V稳压电源输出
- VCC:电源输入/输出
- 输入:5V DC输入为FireBeetle供电(无法为锂电池充电)
- 输出:5V-USB 供电时输出USB电压,3.7V-锂电池供电时输出锂电池电压
- GND:公共地引脚
引脚示意图
这次连接ssd1306 对应关系:
board |
ssd1306 |
---|
3V3 |
VDD |
GND |
GND |
IO2/SCL |
SCK |
IO1/SDA |
SDA |
克隆开源库
mkdir ~/01SHOWTIME
cd ~/01SHOWTIME
[env:dfrobot_firebeetle2_esp32s3] >> platformio.ini
platform = espressif32 >> platformio.ini
board = dfrobot_firebeetle2_esp32s3 >> platformio.ini
framework = arduino >> platformio.ini
lib_deps = /
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.4.0 /
paulstoffregen/Time@^1.6.1 >> platformio.ini
pio check
cp ".pio/libdeps/dfrobot_firebeetle2_esp32s3/ESP8266 and ESP32 OLED driver for SSD1306 displays/examples/SSD1306ClockDemo/images.h" ./src
cp ".pio/libdeps/dfrobot_firebeetle2_esp32s3/ESP8266 and ESP32 OLED driver for SSD1306 displays/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino" ./src/main.c
pio run
下载工具并编译
> ~/.platformio/penv/Scripts/platformio.exe run --target upload
Processing dfrobot_firebeetle2_esp32s3 (platform: espressif32; board: dfrobot_firebeetle2_esp32s3; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Tool Manager: Installing platformio/tool-mkspiffs @ ~2.230.0
Downloading [
Unpacking [
Tool Manager: tool-mkspiffs@2.230.0 has been installed!
Tool Manager: Installing platformio/tool-mklittlefs @ ~1.203.0
Downloading [
Unpacking [
Tool Manager: tool-mklittlefs@1.203.210628 has been installed!
Tool Manager: Installing platformio/tool-mkfatfs @ ~2.0.0
Downloading [
Unpacking [
Tool Manager: tool-mkfatfs@2.0.1 has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/dfrobot_firebeetle2_esp32s3.html
PLATFORM: Espressif 32 (6.3.2) > DFRobot Firebeetle 2 ESP32-S3
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny,
tumpa)
PACKAGES:
- framework-arduinoespressif32 @ 3.20009.0 (2.0.9)
- tool-esptoolpy @ 1.40501.0 (4.5.1)
- tool-mkfatfs @ 2.0.1
- tool-mklittlefs @ 1.203.210628 (2.3)
- tool-mkspiffs @ 2.230.0 (2.30)
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
- toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 35 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ESP8266 and ESP32 OLED driver for SSD1306 displays @ 4.4.0
|-- Time @ 1.6.1
|-- Wire @ 2.0.0
Building in release mode
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/src/main.cpp.o
Building .pio/build/dfrobot_firebeetle2_esp32s3/bootloader.bin
Generating partitions .pio/build/dfrobot_firebeetle2_esp32s3/partitions.bin
esptool.py v4.5.1
Creating esp32s3 image...
Merged 1 ELF section
Successfully created esp32s3 image.
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/libec9/Wire/Wire.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/lib071/ESP8266 and ESP32 OLED driver for SSD1306 displays/OLEDDisplay.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/lib071/ESP8266 and ESP32 OLED driver for SSD1306 displays/OLEDDisplayUi.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/lib9f8/Time/DateStrings.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/lib9f8/Time/Time.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/Esp.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/FirmwareMSC.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/HWCDC.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/IPv6Address.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/MD5Builder.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/Print.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/StreamString.cpp.o
Archiving .pio/build/dfrobot_firebeetle2_esp32s3/libec9/libWire.a
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/Tone.cpp.o
Indexing .pio/build/dfrobot_firebeetle2_esp32s3/libec9/libWire.a
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/USB.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/USBCDC.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/USBMSC.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/WMath.cpp.o
Archiving .pio/build/dfrobot_firebeetle2_esp32s3/lib9f8/libTime.a
Indexing .pio/build/dfrobot_firebeetle2_esp32s3/lib9f8/libTime.a
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/WString.cpp.o
Archiving .pio/build/dfrobot_firebeetle2_esp32s3/lib071/libESP8266 and ESP32 OLED driver for SSD1306 displays.a
Indexing .pio/build/dfrobot_firebeetle2_esp32s3/lib071/libESP8266 and ESP32 OLED driver for SSD1306 displays.a
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/base64.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/cbuf.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-adc.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-bt.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-cpu.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-dac.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-gpio.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-i2c-slave.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-i2c.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-ledc.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-matrix.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-misc.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-psram.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-rgb-led.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-rmt.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-sigmadelta.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-spi.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-time.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-timer.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-tinyusb.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-touch.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/esp32-hal-uart.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/firmware_msc_fat.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/libb64/cdecode.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/libb64/cencode.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/main.cpp.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/stdlib_noniso.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/wiring_pulse.c.o
Compiling .pio/build/dfrobot_firebeetle2_esp32s3/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/dfrobot_firebeetle2_esp32s3/libFrameworkArduino.a
Indexing .pio/build/dfrobot_firebeetle2_esp32s3/libFrameworkArduino.a
Linking .pio/build/dfrobot_firebeetle2_esp32s3/firmware.elf
Retrieving maximum program size .pio/build/dfrobot_firebeetle2_esp32s3/firmware.elf
Checking size .pio/build/dfrobot_firebeetle2_esp32s3/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [= ] 6.1% (used 20136 bytes from 327680 bytes)
Flash: [== ] 23.4% (used 307341 bytes from 1310720 bytes)
Building .pio/build/dfrobot_firebeetle2_esp32s3/firmware.bin
esptool.py v4.5.1
Creating esp32s3 image...
Merged 2 ELF sections
Successfully created esp32s3 image.
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM6
Uploading .pio/build/dfrobot_firebeetle2_esp32s3/firmware.bin
esptool.py v4.5.1
Serial port COM6
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 34:85:18:41:90:98
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00003fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x0005bfff...
Compressed 15040 bytes to 10331...
Writing at 0x00000000... (100 %)
Wrote 15040 bytes (10331 compressed) at 0x00000000 in 0.2 seconds (effective 526.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 146...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (146 compressed) at 0x00008000 in 0.1 seconds (effective 355.6 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 641.7 kbit/s)...
Hash of data verified.
Compressed 307712 bytes to 170902...
Writing at 0x00010000... (9 %)
Writing at 0x0001b817... (18 %)
Writing at 0x00027413... (27 %)
Writing at 0x0002c8f6... (36 %)
Writing at 0x000325fb... (45 %)
Writing at 0x00037d21... (54 %)
Writing at 0x0003d326... (63 %)
Writing at 0x0004298d... (72 %)
Writing at 0x00047f49... (81 %)
Writing at 0x00050633... (90 %)
Writing at 0x000589c7... (100 %)
Wrote 307712 bytes (170902 compressed) at 0x00010000 in 2.1 seconds (effective 1157.4 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
==================================================================================== [SUCCESS] Took 83.34 seconds ====================================================================================
演示
show-time
|