For use with an 8-bit parallel TFT touchscreen using micropython

Overview

ILI9341-parallel-TFT-driver-for-micropython

For use with an 8-bit parallel TFT touchscreen using micropython. Many thanks to prenticedavid and his MCUFriend TFT library, written in C code and from which I derived this micropython driver. Thank you also to Roberthh on the micropython forum for all his very instructive posts about the use of the micropython viper decorator. This helped me much !

You'll find 2 different ILI9341 drivers for micropython in this repository :
ILI9341_ESP32 -> for use with standard ESP32 microcontroller
ILI9341_RP2 -> for use with Raspberry PICO microcontroller

For the ESP32, it's working well but I sometime have memory issues, in this case use of gc.collect() might be usefull

Both libraries have been fully tested using micropython 1.17

These libraries are exclusively purposed for an 8bit parallel Touchscreen using the ILI9341 driver. Like the ones you find on this page : http://www.lcdwiki.com/2.8inch_Arduino_Display

image image

These libraries include 3 different fonts.

The libraries use micropython_viper decorator to improve speed and achieve reasonable graphic display speed

How to use the files in the repository :

1. After installing micropython on your device:

copy the full content of the corresponding folder to the root directory (using Thonny, Rshell or wathever software you usually use)

2. Short description of the files :

ILI9341.py : Main LCD display library, must be imported in full in the py program in order to use all the features, from this library you can declare a "screen" class object

ILI9341_touch.py : Touchscreen library, must be imported if you need to use the touch feature of the display, from this library you can declare a "touchscreen" class object

ILI9341_char.py : Used to draw characters from the font libraries

sdcard.py : Library to use for SD card access (The ILI9341 parallel display has an integrated micro SD card reader)

FreeMono12pt7b.py : Big fonts
FreeMono9pt7b.py : Medium fonts
FreeSansSerif7pt7b.py : Small fonts

main.py : First example; loaded by default, a test of various routines and a mesaure of the display time
mainfull.py : The example above + touchscreen calibration
scroll.py : An example of a scrolling text (The ILI9341 parallel display has a hardware scrolling feature)

SdcardTimerTest.py : An example to set and display the time and print on screen the content of the SDcard

All the examples above start by setting the pins connected to the display (and if needed to the SD card pins)

3. Pin definition

3.1 Pin definition for the LCD display

LCD_RD = 2
LCD_WR = 4
LCD_RS = 32 # RS & CS pins must be ADC and OUTPUT
LCD_CS = 33 # for touch capability -> For ESP32 only pins 32 & 33 - For PICO only pins 26,27 & 28
LCD_RST = 22
LCD_D0 = 12
LCD_D1 = 13
LCD_D2 = 26
LCD_D3 = 25
LCD_D4 = 17
LCD_D5 = 16
LCD_D6 = 27
LCD_D7 = 14

3.2 Pin definition for the touchscreen

XP = LCD_D0 #
YM = LCD_D1 # Those four pins are used for the touchscreen
YP = LCD_CS # Please note that CS and RS are the same as for the display above
XM = LCD_RS #

Except for the RS and CS pins, you can choose any I/O pin, but be aware that to use the SDcard you will need an available SPI, so save at least one set of SPI pins for this !

4. Touchsceen calibration procedure

Once you have loaded the "main_full_test_LCD_TOUCH.py" file, after a few tests you'll see on screen the calibration procédure. It is a basic set of green crosses you have to touch and when it's done calcultations are made to interpolate the x and y position with the ADC values. Once it is complete you'll find the results giving a set of parameters:

Cal. result : Pos(pixel) = a * ADC_val + b

Short direction ->  a = -0.005244441
                    b = 292.7332

Long direction  ->  a = 0.006892291
                    b = -72.781

Touch anywhere to test !

What you have to do is copy these paramters in the ILI9341_touch.py library :

self.coeff_short = results above for Short direction a
self.const_short = results above for Short direction b
self.coeff_long = results above for Long direction a
self.const_long = results above for Long direction b

and that's it ! See a full video of the process :https://drive.google.com/file/d/1L7yVWag6e606RgQF5fxj9b6aB8_0982Q/view?usp=sharing

5. Using the routines

5.1 Display routines

Once you've declared your "screen" class object using tft=ILI9341.screen(LCD_RD,LCD_WR,LCD_RS,LCD_CS,LCD_RST,LCD_D0,LCD_D1,LCD_D2,LCD_D3,LCD_D4,LCD_D5,LCD_D6,LCD_D7)

the following commands are availabe :

tft.begin() : You have to start with this one, this initiates and resets the display
tft.fillscreen(Color) : Fill the entire screen with the corresponding color (16-bit color value)
tft.setrotation(0) : 0 an 2 are portrait mode, 1 and 3 are landscape mode
tft.fillRect(start x,start y, width, height ,color) : Draw a filled rectangle
tft.drawFastVLine(start x,start y, length, color) : Draw a vertical line
tft.drawFastHLine(start x,start y, length, color) : Draw an horizontal line
tft.drawLine(start x,start y, end x, end y, color) : Draw any other type of line
tft.drawPixel(x, y, color) : Draw a Pixel
tft.drawCircle(x, y, r, color) : Draw a circle, x,y = center position, r = radius in pixels
tft.fillDisk(x, y, r, color) : Draw a completely filled disk x,y = center position, r = radius in pixels
tft.drawDisk(x, y, y, r1, r2, color) : Draw a ring x,y = center position, r1 = inner radius in pixels, r2 = outer radius in pixels

tft.SetFont(i) : i 1 or 2 or 3 at the moment since only 3 fonts are available - A font MUST BE SET in order to use the following text features
tft.setTextColor(color) : Sets the characters color (16-bit value)
tft.setTextCursor(x,y) : Position the text cursor at the desired value - This position is the lowest-left pixel to start character printing
tft.printh(String) : Print the string, add a "\n" character at the end for linefeed
tft.prints(String) : Same as printh, but with a very cool scrolling additional feature (only in portrait mode) ! (see example)

5.2 Touch routines

Once you've declared your "screen" class object using ts = ILI9341_touch.touchscreen(XP, YP, XM, YM)

the following commands are availabe :
ts.Pin_reset() :
This is an important function. in every methods you want to implement, you have to do this reset before every call to a tft (display) routine (remember: CS and RS Pins are shared between the LCD display and the touchscreen interface, if the pins are not reset the screen functions will not work).

ts.pressure() : Return a value corresponding to the pressing strength - Mostly used to detect a touch
ts.getPoint() : Return the (x,y) position of the touch (provided the touchscreen has been correctly calibrated, see #4)
ts.Point_Listen() : Use with care, this loop returns the (x,y) touch value after the user has stopped touching (when removing the pencil). Used in the calibration function if you want to see it working.

Python script: Enphase Envoy mqtt json for Home Assistant

A Python script that takes a real time stream from Enphase Envoy and publishes to a mqtt broker. This can then be used within Home Assistant or for other applications. The data updates at least once

29 Dec 27, 2022
Designed a system that can efficiently sort recyclables and transfer them to corresponding bins using Python, a Raspberry Pi, and Quanser Labs.

System for Sorting and Recycling Containers - Project 3 Table of contents Overview The challenge Screenshot My process Built with Code snippets What I

Mit Patel 2 Dec 02, 2022
Lenovo Legion 5 Pro 2021 Linux RGB Keyboard Light Controller

Lenovo Legion 5 Pro 2021 Linux RGB Keyboard Light Controller This util allows to drive RGB keyboard light on Lenovo Legion 5 Pro 2021 Laptop Requireme

36 Dec 16, 2022
It is a serial communicator(controller, receiver...), communicate with sensor LP20 which is a laser ranger.

Intro It is a serial communicator(controller, receiver...), communicate with sensor LP20 which is a laser ranger. Its datasheet is contained in this r

3 Sep 19, 2022
Raspberry Pi Pico support for VS Code

Pico-Go VS Code Extension Pico-Go provides code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REP

Chris Wood 114 Dec 28, 2022
Setup DevTerm to be a cool non-GUI device

DevTerm hobby project I bought this amazing device: DevTerm A-0604. It has a beefy ARM processor, runs a custom version of Armbian, embraces Open Sour

Alex Shteinikov 9 Nov 17, 2022
This repository contains all the code and files needed to simulate the notspot quadrupedal robot using Gazebo and ROS.

Notspot robot simulation - Python version This repository contains all the files and code needed to simulate the notspot quadrupedal robot using Gazeb

50 Sep 26, 2022
Open-Source board for converting RaspberryPI to Brain-computer interface

The easiest way to the neuroscience world with the shield for RaspberryPi - PIEEG (website). Open-source. Crowdsupply This project is the result of se

Ildaron 436 Jan 01, 2023
Controlling fireworks with micropython

Controlling-fireworks-with-micropython How the code works line 1-4 from machine

Montso Mokake 1 Jan 08, 2022
Jarvis: a personal assistant which can help you to manage your system

Jarvis Jarvis is personal AI based assistant which can help you to manage stuff in your computer. This is demo but I decided to make it more better so

2 Jun 02, 2022
A simple program to make MSI Modern 15 speaker and microphone mute led work.

MSI Modern 15 sound led fixup for linux A simple program to fix the MSI Modern 15 speaker and microphone mute LEDs. Installation Requirements pulsectl

Seyed Danial Movahed 4 Oct 18, 2022
Cascade Drone Swarm Physical Demonstration Project

Cascade Drone Swarm Physical Demonstration Project Table of Contents About The Project Built With Getting Started Prerequisites Installation About The

3 Aug 24, 2022
Authentication provider using Synology DSM users for Home Assistant

Authentication provider using Synology DSM users for Home Assistant The Synology authentication provider lets you authenticate using the users in your

Sam Debruyn 5 Oct 06, 2022
Ansible tools for operating and managing fleets of Blinksticks in harmony using the Blinkstick Python library.

Ansible tools for operating and managing fleets of Blinksticks in harmony using the Blinkstick Python library.

Greg Robinson 3 Aug 10, 2022
The main aim of this project is to avoid the accidents in shredding ( Waste Recycling Industry )

shredder-Machine-Hand-Safety The main aim of this project is to avoid the accidents in shredding ( Waste Recycling Industry ) . The Basic function of

Shubham Chaudhari 1 Nov 15, 2021
Using a raspberry pi, we listen to the coffee machine and count the number of coffee consumption

A typical datarootsian consumes high-quality fresh coffee in their office environment. The board of dataroots had a very critical decision by the end of 2021-Q2 regarding coffee consumption.

dataroots 51 Nov 21, 2022
View your medication from Medisafe Cloud in Home Assistant

Medisafe View your medication from Medisafe Cloud in Home Assistant. This integration adds sensors for today's upcoming, taken, skipped, and missed do

Sam Steele 12 Dec 27, 2022
This is a Virtual Keyboard which is simple yet effective to use.

Virtual-Keyboard This is a Virtual KeyBoard which can track finger movements and lets you type anywhere ranging from notepad to even web browsers. It

Jehan Patel 3 Oct 01, 2021
Python implementation of ZMP Preview Control approach for biped robot control.

ZMP Preview Control This is the Python implementation of ZMP Preview Control app

Chaobin 24 Dec 19, 2022
Better support for Nuki devices to the Home Assistant

Another attempt to add a better support for Nuki devices to the Home Assistant Features: Lock interface implementation Uses local webhook from bridge

Konstantin 105 Jan 07, 2023