Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ili9341.py
uFT6336U.py
78 changes: 78 additions & 0 deletions demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Raspberry Pi Pico + LCD

MicroPython setup, wiring, drivers, and test scripts

## 1. Install MicroPython on Raspberry Pi Pico

1. Download the MicroPython UF2 for Pico:
[https://micropython.org/download/rp2-pico](https://micropython.org/download/rp2-pico)
2. Hold **BOOTSEL** while plugging in the Pico.
3. Drag the `.uf2` file onto the Pico drive.
4. Pico reboots into MicroPython.

---

## 2. Using Raspberry Pi Pico in Visual Studio Code (MicroPython)

### Steps

1. Connect Pico via USB
2. Open Visual Studio Code
3. Press **Ctrl + Shift + P**
4. Select **Pico: Configure Project**
5. Choose the correct COM port
6. Open REPL
7. Upload your `.py` files to the Pico
8. Run scripts directly from Visual Studio Code or REPL

---

## 3. Wiring (Pico → LCD + Touch)

### Pin Mapping Table

| **Pico Pin** | **Pico Physical Pin** | **LCD Pin** | **Signal** |
| ------------ | --------------------- | ----------- | ------------------------- |
| GP5 | 5 | 5 | LCD_RS |
| GP6 | 6 | 12 | SDA (Touch) |
| GP7 | 7 | 10 | SCL (Touch) |
| GP12 | 12 | 4 | LCD_RST |
| GP14 | 14 | 7 | SCK (SPI) |
| GP15 | 15 | 6 | MOSI (SPI) |
| GP16 | 16 | 9 | MISO (SPI) |
| GND | 18 | 2 | GND |
| GP20 | 20 | 3 | LCD_CS |
| GP31 | 31 | 13 | CTS_INT (Touch Interrupt) |
| 3.3V | 36 | 11 | +3.3V |
| 5V | 39 | 1 | +5V |

---

## 4. Drivers

### ILI9341 Display Driver

Save as: **`ili9341.py`**

**Source link:**
[https://github.com/rdagger/micropython-ili9341](https://github.com/rdagger/micropython-ili9341)

---

### FT6336U Touch Driver

Save as: **`uFT6336U.py`**

**Source link:**
[https://github.com/fantasticdonkey/uFT6336U](https://github.com/fantasticdonkey/uFT6336U)

---

## 5. Test Code

1. Run **`demo_setup.bat`** from the `demos` folder to download the driver files.
2. Connect the Pico to Visual Studio Code and upload **`ili9341.py`** and **`uFT6336U.py`** to the Pico.
3. To test the LCD, open **`shapes_demo.py`**, upload it to the Pico, and run the current file. The display should show colored lines, rectangles, polygons, circles, and ellipses.
4. To test the touchscreen, open **`touch_demo.py`**, upload it to the Pico, and run the current file. Touch coordinates should appear in the Visual Studio Code REPL.

---
3 changes: 3 additions & 0 deletions demos/demo_setup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This batch file downloads the ili9341.py and uFT6336U.py files from their respective GitHub repositories and saves them in the current directory.
curl -L -o ili9341.py https://raw.githubusercontent.com/rdagger/micropython-ili9341/refs/heads/master/ili9341.py
curl -L -o uFT6336U.py https://raw.githubusercontent.com/fantasticdonkey/uFT6336U/refs/heads/master/uFT6336U.py
85 changes: 85 additions & 0 deletions demos/shapes_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""ILI9341 demo (shapes)."""

from time import sleep

import uFT6336U
from ili9341 import Display, color565
from machine import I2C, SPI, Pin # type: ignore


def test():
"""Test code."""
# Baud rate of 40000000 seems about the max
spi = SPI(1, baudrate=40000000, sck=Pin(10), mosi=Pin(11), miso=Pin(12))
display = Display(spi, dc=Pin(3), cs=Pin(15), rst=Pin(9))

i2c_bus = I2C(sda=Pin(4), scl=Pin(5), freq=400000)
touch = uFT6336U.FT6336U(i2c_bus)

touch.get_positions()

display.clear(color565(64, 0, 255))
sleep(1)

display.clear()

display.draw_hline(10, 319, 229, color565(255, 0, 255))
sleep(1)

display.draw_vline(10, 0, 319, color565(0, 255, 255))
sleep(1)

display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255))
sleep(1)

display.draw_hline(0, 0, 222, color565(255, 0, 0))
sleep(1)

display.draw_line(127, 0, 64, 127, color565(255, 255, 0))
sleep(2)

display.clear()

coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]]
display.draw_lines(coords, color565(0, 255, 255))
sleep(1)

display.clear()
display.fill_polygon(7, 120, 120, 100, color565(0, 255, 0))
sleep(1)

display.fill_rectangle(0, 0, 15, 227, color565(255, 0, 0))
sleep(1)

display.clear()

display.fill_rectangle(0, 0, 163, 163, color565(128, 128, 255))
sleep(1)

display.draw_rectangle(0, 64, 163, 163, color565(255, 0, 255))
sleep(1)

display.fill_rectangle(64, 0, 163, 163, color565(128, 0, 255))
sleep(1)

display.draw_polygon(3, 120, 286, 30, color565(0, 64, 255), rotate=15)
sleep(3)

display.clear()

display.fill_circle(132, 132, 70, color565(0, 255, 0))
sleep(1)

display.draw_circle(132, 96, 70, color565(0, 0, 255))
sleep(1)

display.fill_ellipse(96, 96, 30, 16, color565(255, 0, 0))
sleep(1)

display.draw_ellipse(96, 256, 16, 30, color565(255, 255, 0))

sleep(5)
display.cleanup()


test()
23 changes: 23 additions & 0 deletions demos/touch_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""uFT6336U demo (touch)."""

import time

import uFT6336U
from machine import I2C, Pin

i2c = I2C(0, scl=Pin(5), sda=Pin(4))

t = uFT6336U.FT6336U(i2c)

print("Touch test (polling)")
print("Touch the screen to see coordinates printed in REPL")

while True:
np = t.get_points()
if np > 0:
print(t.get_p1_x(), t.get_p1_y(), end=" ")
if np > 1:
print(t.get_p2_x(), t.get_p2_y(), end=" ")
if np > 0:
print()
time.sleep(0.1)
2 changes: 1 addition & 1 deletion format.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
@echo off

if not exist ".venv" (
echo Creating virtual environment...
Expand Down