russhughes / ili9342c_mpy Goto Github PK
View Code? Open in Web Editor NEWILI9342C Fast 'C' Driver for MicroPython (M5Stack Core)
License: Other
ILI9342C Fast 'C' Driver for MicroPython (M5Stack Core)
License: Other
Thanks for the great mpy extensions for ST7789 and ILI9342. They are great!
The ILI9342 also works on ILI9341 displays which are almost identical. The difference is they are 240x320 and not 320x240, the colors are inverted and your rotation modes are flipped, so mirror modes an normal modes are reverse: 1-4 <-> 5-8
So with this in mind the following will work on a ili9341:
def main():
spi = SPI(
2,
baudrate=60000000,
sck=Pin(18),
mosi=Pin(23))
# initialize display
tft = ili9342c.ILI9342C(
spi,
240,
320,
reset=Pin(33, Pin.OUT),
cs=Pin(26, Pin.OUT),
dc=Pin(5, Pin.OUT),
rotation=5)
tft.init()
tft.inversion_mode(False)
tft.rotation(5)
tft.fill(ili9342c.BLACK)
row = 0
tft.write(font, "abcdefghijklmnopqrstuvwxyz", 0, row)
row += font.HEIGHT
tft.fill_rect(0, row, 100, 100, ili9342c.RED)
Would it be possible to solve this in an elegant way? e.g. pass as parameter to init? Or even better merge the ST7789 and ILI9342 into one DISPLAY extension that servers all 3 types?
If you want I can give you a hand.
Have you ever looked at the mpy fork from Loboris and his display implementation? (see https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/display ). Many people love the loboris fork but it now outdated and he abandoned the project. Loboris stuff is not easy to update and also it is near to impossible to extract stuff from it. His implementation is more a less a separate port for esp32
@russhughes quick question?
Do you have a C lib working with MicroPython just like this for the ILI9341?
as the question
Hi, congratulations for your excellent job.
I have installed your ST7789 firmware on my TTGO T-Display and it is marvellous.
I am trying to use your ili9342c firmware with the TTGO T4, and found some issues that I have solved.
The connection of the pins that appears in the TTGO web is not correct.
This one works:
MOSI 23
CLK 18
CS 27
DC 32 (THIS IS WRONG IN THE INFO OF THE MODULE)
RST 5
Backlight Pin 4
(You have to use your library option backlight=Pin(4, Pin.OUT))
Now the screen works, but colours and screen are inverted.
I have used your library option
tft.inversion_mode(0)
and the colours now are ok.
But the screen is still inverted.
Is there any solution for that?
Thanks in advance, congratulations for your wonderful job and keep on helping us!
spi = SPI(
2,
baudrate=40000000,
polarity=1,
phase=1,
sck=Pin(18),
mosi=Pin(23))
# initialize display
tft = ili9342c.ILI9342C(
spi,
240,
320,
reset=Pin(5, Pin.OUT),
cs=Pin(27, Pin.OUT),
dc=Pin(32, Pin.OUT),
backlight=Pin(4, Pin.OUT),
rotation=0
)
tft.init()
tft.inversion_mode(0)
Hi @russhughes great library.
I'm trying to compile with the latest version and I'm getting some compile errors.
Firstly
ERROR: Call to MP_REGISTER_MODULE(MP_QSTR_ili9342c, mp_module_ili9342c, 1) should be MP_REGISTER_MODULE(MP_QSTR_ili9342c, mp_module_ili9342c)
Which I can resolve easily by changing to
MP_REGISTER_MODULE(MP_QSTR_ili9342c, mp_module_ili9342c)
However this triggers a bunch of other errors:
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c: In function 'write_spi':
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:119:39: error: 'mp_obj_type_t' {aka 'const struct _mp_obj_type_t'} has no member named 'protocol'
119 | ((mp_machine_spi_p_t *) spi_obj->type->protocol)->transfer(spi_obj, len, buf, NULL);
| ^~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c: At top level:
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1312:3: error: 'mp_obj_type_t' {aka 'const struct _mp_obj_type_t'} has no member named 'print'
1312 | .print = ili9342c_ILI9342C_print,
| ^~~~~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1312:13: error: initialization of 'unsigned char' from 'void (*)(const mp_print_t *, void *, mp_print_kind_t)' {aka 'void (*)(const struct _mp_print_t *, void *, enum <anonymous>)'} makes integer from pointer without a cast [-Werror=int-conversion]
1312 | .print = ili9342c_ILI9342C_print,
| ^~~~~~~~~~~~~~~~~~~~~~~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1312:13: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_make_new')
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1312:13: error: initializer element is not computable at load time
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1312:13: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_make_new')
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1313:3: error: 'mp_obj_type_t' {aka 'const struct _mp_obj_type_t'} has no member named 'make_new'
1313 | .make_new = ili9342c_ILI9342C_make_new,
| ^~~~~~~~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1313:15: error: initialization of 'unsigned char' from 'void * (*)(const mp_obj_type_t *, size_t, size_t, void * const*)' {aka 'void * (*)(const struct _mp_obj_type_t *, unsigned int, unsigned int, void * const*)'} makes integer from pointer without a cast [-Werror=int-conversion]
1313 | .make_new = ili9342c_ILI9342C_make_new,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1313:15: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_print')
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1313:15: error: initializer element is not computable at load time
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1313:15: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_print')
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1314:3: error: 'mp_obj_type_t' {aka 'const struct _mp_obj_type_t'} has no member named 'locals_dict'
1314 | .locals_dict = (mp_obj_dict_t *) &ili9342c_ILI9342C_locals_dict,
| ^~~~~~~~~~~
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1314:17: error: initialization of 'unsigned char' from 'mp_obj_dict_t *' {aka 'struct _mp_obj_dict_t *'} makes integer from pointer without a cast [-Werror=int-conversion]
1314 | .locals_dict = (mp_obj_dict_t *) &ili9342c_ILI9342C_locals_dict,
| ^
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1314:17: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_call')
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1314:17: error: initializer element is not computable at load time
/home/patrick/esp/usercmodule/ili9342c/ili9342c.c:1314:17: note: (near initialization for 'ili9342c_ILI9342C_type.slot_index_call')
Any ideas?
Thanks
I managed to compile v1.17 and it works like a charm :)
However I wasn't able to include in the firmware the font modules. Why is that? What is the bit that makes the fonts to get frozen into the firmware? I haven't seen any references to that in the firmware. Any pointers on how to fix this are welcome :)
After building the micropython firmware I can't import it inside a mpy script. The "ili9342c.o" and "ili9342c.P" seem to be compiled (they're available inside the build-GENERIC/src directory).
If I compile micropython with just "make" I get a firmware.bin that works. But when I use "make USER_C_MODULES=../../../ili9342c_mpy/ all" it works, but it complains about the ili9342c module not being there when I try your examples. It also complained about the fonts not being there when I tried mono_fonts.py. The size of the .bin file is exactly the same as when I make it without the USER_C_MODULES and there isn't anything in the build directory for ili9342c.
I tried your firmware.bin file and it went bonkers complaining about partition 3 being invalid; I was using the esptool.py command given on the micropython site. I then saw what m5stack uses and changed my command to the following and then it worked. Yay, I got to see the flying toasters! But I'd like to know why my build isn't "flying".
esptool.py \
--chip esp32 \
--port ${PORT} \
--baud ${BAUD} \
--flash_mode dio \
--flash_freq 80m \
--flash_size detect \
write_flash -z 0x1000 \
${BIN}
When using the M5Stack, initializing the display prevents the SD card from working properly afterwards.
For example, the following code:
import machine
import os
import ili9342c
from machine import Pin, SPI
dac = machine.DAC(machine.Pin(25)) # Just to silence speaker buzz, pretty sure it doesn't have any affect
dac.write(0)
sd = machine.SDCard(slot=3, miso=19, mosi=23, sck=18, cs=4)
# sd.info()
os.mount(sd, '/sd')
# I read from two different paths because if you do two, it seems to cache if you call the same one twice in a row
print(os.listdir("/sd/")) # This one does have a '/' on the end. If it doesn't, I get a ENOENT error
print(os.listdir("/sd/Snakey")) # For reference, this is the line 40 described in the below error. Also, if this one doesn't have a '/' on the end I get a EINVAL error
print("SD card mounted succesfully")
tft = ili9342c.ILI9342C( # Basic default screen configuration, afaik
SPI(2, baudrate=60000000, sck=Pin(18), mosi=Pin(23)),
320,
240,
reset=Pin(33, Pin.OUT),
cs=Pin(14, Pin.OUT),
dc=Pin(27, Pin.OUT),
backlight=Pin(32, Pin.OUT),
rotation=0,
buffer_size=16*32*2)
tft.init()
print(os.listdir("/sd/"))
print(os.listdir("/sd/Snakey"))
print("But it fails when the display is initiliaized")
Produces the following result:
... Generic intro info ...
Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead
['System Volume Information', 'Snakey', 'Tetris', 'Quail Escape', '3D Demo']
['main.py']
SD card mounted succesfully
E (1610) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
['main.py']
Traceback (most recent call last):
File "boot.py", line 40, in <module>
OSError: [Errno 2] ENOENT
... Kicks to REPL ...
For reference, I've got the m5stack faces kit with the gameboy face on, but the same error occurs with the faces backplate disconnected. I've got no reason to suspect the card, which is a 16GB PNY card, and both parts (the SD card and display) seem to work flawlessly individually.
Any help is greatly appreciated. Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.