Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newest Micropython and ST7789 plus examples and Wifi Library #46

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
149 changes: 149 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
name: T-Display-Pico C3

permissions:
contents: write

on:
push:
tags:
- 'v*'
schedule:
- cron: '0 0 1 * *'

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Clone repo
uses: actions/checkout@v4

- name: Clone Micropython
run: git clone --recurse-submodules https://github.com/micropython/micropython.git

- name: Clone st7789_mpy
run: git clone https://github.com/russhughes/st7789_mpy.git

- name: Clone TPicoESPC3 Wifi module
run: git clone https://github.com/PIBSAS/TPicoESPC3.git

- name: Copy tft_config, tft_buttons and some fonts like frozen modules
run: |
ls -R $GITHUB_WORKSPACE/st7789_mpy/
cp "$GITHUB_WORKSPACE/st7789_mpy/examples/configs/t-picoc3/tft_config.py" "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp "$GITHUB_WORKSPACE/st7789_mpy/examples/configs/tdisplay_rp2040/tft_buttons.py" "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/examples/chango/chango_16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/examples/chango/chango_32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/examples/chango/chango_64.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/astrol.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/gotheng.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/greekc.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/italict.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/lowmat.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/marker.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/music.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romancs.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_8x8.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_8x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_16x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_16x32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_bold_16x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga1_bold_16x32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
cp $GITHUB_WORKSPACE/st7789_mpy/fonts/truetype/NotoSerif_32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/examples/chango/chango.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/truetype/NotoSans_32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/truetype/NotoSansMono_32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_8x8.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_8x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_16x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_16x32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_bold_16x16.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/bitmap/vga2_bold_16x32.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/cyrilc.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/gothger.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/gothita.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/greekcs.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/greekp.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/greeks.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/italcc.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/italiccs.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/meteo.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romanc.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romand.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romanp.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romans.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/romant.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/scriptc.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/scripts.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/symbol.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"
# cp $GITHUB_WORKSPACE/st7789_mpy/fonts/vector/uppmat.py "$GITHUB_WORKSPACE/micropython/ports/rp2/modules/"

- name: Copy TPicoESPC3 like frozen module
run: |
cp $GITHUB_WORKSPACE/TPicoESPC3/TPicoESPC3.py $GITHUB_WORKSPACE/micropython/ports/rp2/modules/

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-none-eabi libssl-dev python3 python3-pip python3-venv build-essential libffi-dev git pkg-config

- name: Build MicroPython for RP2040
run: |
cd micropython
make -C mpy-cross
cd ports/rp2
make USER_C_MODULES=$GITHUB_WORKSPACE/st7789_mpy/st7789/micropython.cmake
make submodules
make

- name: Move .uf2 files to artifacts
run: |
mkdir -p ./artifacts
cp micropython/ports/rp2/build-RPI_PICO/*.uf2 ./artifacts/RP2040.uf2

- name: Get MicroPython Version from mpconfig.h
run: |
cd micropython/
MAJOR=$(grep -oP '(?<=#define MICROPY_VERSION_MAJOR )[0-9]+' py/mpconfig.h)
MINOR=$(grep -oP '(?<=#define MICROPY_VERSION_MINOR )[0-9]+' py/mpconfig.h)
MICRO=$(grep -oP '(?<=#define MICROPY_VERSION_MICRO )[0-9]+' py/mpconfig.h)
PRERELEASE=$(grep -oP '(?<=#define MICROPY_VERSION_PRERELEASE )[0-9]+' py/mpconfig.h)

if [ "$PRERELEASE" -eq 1 ]; then
MPY_VERSION="$MAJOR.$MINOR.$MICRO-preview"
else
MPY_VERSION="$MAJOR.$MINOR.$MICRO"
fi

echo "MPY_VERSION=$MPY_VERSION" >> $GITHUB_ENV

- name: Generate Tag
id: tag
run: echo "TAG_NAME=release-$(date +'%Y%m%d-%H%M')" >> $GITHUB_ENV

- name: GH Release
uses: softprops/[email protected]
with:
tag_name: ${{ env.TAG_NAME }}
name: "MicroPython + ST7789 Display Driver for LilyGo T-PicoC3 Display Release version ${{ env.MPY_VERSION }} (Build ${{ env.TAG_NAME }})"
body: |
Automated release for MicroPython.
## How to Flash the Firmware
### Windows, Linux:
1. Download the .uf2 file from the release.
2. Press and hold the BOOT button on the RP2040 and press RESET button or connect it to your computer via USB.
3. Release the button. The RP2040 will appear as a removable drive.
4. Drag and drop the .uf2 file onto the drive..
5. The RP2040 will reboot and run MicroPython..

## Examples Usage
Please use the examples located in the [examples folder of the st7789_mpy repository](https://github.com/russhughes/st7789_mpy/tree/master/examples).

New Examples in [TPicoESPC3 module repo](https://github.com/PIBSAS/TPicoESPC3/tree/main/examples) and remake to micropython vendor's codes.
draft: false
prerelease: false
files: ./artifacts/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@
# Quick start:

## Notice
### In TYPE-C, you can determine whether the current connection is PICO or ESP32C3 through positive and negative access.
### In TYPE-C, you can determine whether the current connection is PICO or ESP32C3 through positive and negative access.

<br>

![](image/usb-pico.png)

**Blue LED indicating RP2040 side.**

---

![](image/usb-esp32c3.png)

**Green LED indicating ESP32 C3 side.**

### When connecting, the onboard LED lamp will be indicated according to the connected chip (due to cable problems, it is possible that the indicator light is opposite to the actual connected chip, or even two LED lights at the same time, please replace another cable when two led lights up at the same time), the main judgment is that the currently connected device is displayed in the serial port name.


![](image/select-pico.png)
![](image/select-esp32c3.png)
- Selected RP2040 on Arduino IDE

<br>

![](image/select-esp32c3.png)
- Selected ESP32 C3 on Arduino IDE

## RP2040 :
### Arduino
Expand Down
17 changes: 17 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Get Latest Raspberry Pi Pico-Series C/C++ SDK:
[![C SDK](/doc/cover/rp2_C_SDK.png)](https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf)

## Get Latest Raspberry Pi Pico-Series Python SDK:
[![Python SDK](/doc/cover/rp2_Python_SDK.png)](https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf)

## Get Latest ESP32 C3 Technical Reference Manual CN:
[![Reference Manual CN](/doc/cover/esp32-c3_technical_reference_manual_cn.png)](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_cn.pdf)

## Get Latest ESP32 C3 Technical Reference Manual EN:
[![Technical Reference Manual EN](/doc/cover/esp32-c3_technical_reference_manual_en.png)](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf)

## ESP32 C3 Wireless Adventure
[![ESP32 C3 Wireless Adventure](/doc/cover/ESP32_C3_Wireless_Adventure.png)](https://www.espressif.com/sites/default/files/documentation/ESP32-C3%20Wireless%20Adventure.pdf)

## Get Started with Micropython:
[![Get Started with Micropython](/doc/cover/Started_Guide.png)](https://hackspace.raspberrypi.com/books/micropython-pico)
Binary file added doc/cover/ESP32_C3_Wireless_Adventure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/cover/Started_Guide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/cover/rp2_C_SDK.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/cover/rp2_Python_SDK.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/esp32-c3_technical_reference_manual_cn.pdf
Binary file not shown.
Binary file added doc/esp32-c3_technical_reference_manual_en.pdf
Binary file not shown.
Binary file modified doc/raspberry-pi-pico-c-sdk.pdf
Binary file not shown.
Binary file modified doc/raspberry-pi-pico-python-sdk.pdf
Binary file not shown.
33 changes: 33 additions & 0 deletions example/Micropython/examples/I2C_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from machine import I2C, Pin
import time

# Definir los pines SDA y SCL
I2C_SDA = 12
I2C_SCL = 13

# Crear el objeto I2C
i2c = I2C(0, scl=Pin(I2C_SCL), sda=Pin(I2C_SDA), freq=400000)

# Función de configuración inicial
def setup():
print("\n\nI2C scanner. Scanning... SDA", I2C_SDA, "SCL", I2C_SCL)
time.sleep(0.5)

# Función principal para escanear dispositivos I2C
def loop():
while True:
devices = i2c.scan()
count = len(devices)

if count == 0:
print("No I2C devices found")
else:
print("Found", count, "device(s):")
for device in devices:
print("Device found at address:", hex(device))

time.sleep(4)

# Ejecución
setup()
loop()
35 changes: 35 additions & 0 deletions example/Micropython/examples/blink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from machine import Pin
import time
import st7789, tft_config
import chango_16 as font

tft = tft_config.config(0)
tft.init()
# Define the built-in LED pin
LED_BUILTIN = 25
led = Pin(LED_BUILTIN, Pin.OUT)

# Initial setup
def setup():
led.value(0) # Initialize the LED off

# Main loop
def loop():
try:
while True:
led.value(1) # Turn on the LED
tft.fill(st7789.BLACK)
tft.write(font, "ON", 50, 50)
time.sleep(1) # Wait for 1 second
led.value(0) # Turn off the LED
tft.fill(st7789.BLACK)
tft.write(font, "OFF", 50, 50)
time.sleep(1) # Wait for 1 second
except KeyboardInterrupt:
led.value(0) # Turn off the LED on exit
tft.fill(st7789.BLACK) # Clear the display
print("Program stopped by the user.")

# Execution
setup()
loop()
17 changes: 17 additions & 0 deletions example/Micropython/examples/blink_screen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import st7789
from time import sleep
from tft_config import config

tft = config(0)
tft.init()

try:
while True:
# Turn off screen
tft.on()
sleep(1)
# Turn on screen
tft.off()
sleep(1)
except Exception as e:
print("Plug in the board, man!", e)
9 changes: 9 additions & 0 deletions example/Micropython/examples/button_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import machine
import time

button1 = machine.Pin(6, machine.Pin.IN, machine.Pin.PULL_UP)
button2 = machine.Pin(7, machine.Pin.IN, machine.Pin.PULL_UP)

while True:
print("Button1:", button1.value(), "Button2:", button2.value())
time.sleep(0.1)
21 changes: 21 additions & 0 deletions example/Micropython/examples/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import st7789, tft_config, time

tft =tft_config.config(1)
tft.init()
for i in range(8):
tft.fill(st7789.RED)
time.sleep(1)
tft.fill(st7789.GREEN)
time.sleep(1)
tft.fill(st7789.BLACK)
time.sleep(1)
tft.fill(st7789.BLUE)
time.sleep(1)
tft.fill(st7789.WHITE)
time.sleep(1)
tft.fill(st7789.MAGENTA)
time.sleep(1)
tft.fill(st7789.CYAN)
time.sleep(1)
tft.fill(st7789.YELLOW)
time.sleep(1)
71 changes: 71 additions & 0 deletions example/Micropython/examples/getAP_MultiScroll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Import the TPicoESPC3 class
from TPicoESPC3 import ESPC3
import st7789, tft_config, time
import vga1_8x16 as font

tft = tft_config.config(3)
tft.init()
tft.fill(st7789.BLACK)

# Initialize the ESP32C3 module
esp = ESPC3() # Debug can be enabled by passing the parameter debug=True

# Get the list of access points
try:
ap_list = esp.get_AP()
initial_y_position = 16 # Initial Y position
screen_width = 240 # Width of the screen
fixed_time = 1 # Fixed time to display the text without scrolling
scroll_speed = 5 # Scrolling speed in pixels

print("Available access points:")
tft.text(font, "Available access points:", 0, 0, st7789.YELLOW)

y_positions = [] # List to store the Y positions of each line
texts = [] # List to store each line of text

# Display all networks statically first
y_position = initial_y_position

for ap in ap_list:
print("SSID:", ap[1], "RSSI:", ap[2], "MAC:", ap[3], "Channel:", ap[4],
"Scan type:", ap[5], "Min scan time:", ap[6],
"Max scan time:", ap[7], "Pairwise cipher:", ap[8],
"Group cipher:", ap[9], "802.11 support:", ap[10], "WPS:", ap[11],
"Security:", ap[0])

text = (f"SSID:{ap[1]}, RSSI:{ap[2]}, MAC:{ap[3]}, Channel:{ap[4]}, "
f"Scan type:{ap[5]}, Min scan time:{ap[6]}, "
f"Max scan time:{ap[7]}, Pairwise cipher:{ap[8]}, "
f"Group cipher:{ap[9]}, 802.11 support:{ap[10]}, WPS:{ap[11]}, "
f"Security:{ap[0]}")

# Store text and position for later
texts.append(text)
y_positions.append(y_position)

# Display the text statically
tft.text(font, text, 0, y_position, st7789.CYAN)
y_position += 16 # Increment Y for the next network

# Keep the results fixed for 2 seconds
time.sleep(fixed_time)

# Now scroll all lines at the same time
for scroll in range(0, max(len(text) * 8 for text in texts) - screen_width + 1, scroll_speed):
for i, text in enumerate(texts):
tft.fill_rect(0, y_positions[i], screen_width, 17, st7789.BLACK) # Clear the previous line
tft.text(font, text, -scroll, y_positions[i], st7789.CYAN) # Draw the scrolled text
time.sleep(0.05) # Adjust the scrolling speed

# After scrolling, display the lines again statically for 2 seconds
tft.fill(st7789.BLACK) # Clear the screen
for i, text in enumerate(texts):
tft.text(font, "Available access points:", 0, 0, st7789.YELLOW)
tft.text(font, text, 0, y_positions[i], st7789.CYAN)

time.sleep(fixed_time)

except Exception as e:
print("Error getting access points:", e)
tft.text(font, f"Error connecting to Wi-Fi: {e}", 0, 100)
Loading