Posts

Showing posts with the label code.MicroPython

ESP32S3 (MicroPython) + MAX98357 I2S Audio Amplifier to play tones

Image
This post exercise on ESP32-S3-DevKitC-1 running MicroPython v1.24.1, to play tones using MAX98357 I2S Audio Amplifier. Connection between MAX98357 and ESP32-S3-DevKitC-1: MAX98357 ESP32-S3-DevKitC-1 ================================== VCC 3V3 GND GND MAX98357_LRC GPIO17 MAX98357_BCLK GPIO16 MAX98357_DIN GPIO15 MAX98357_GAIN GND mpy_s3_max98357.py , a simple MicroPython to play single tone on MAX98357 I2S Audio Amplifier. """ ESP32-S3-DevKitC-1 running MicroPython v1.24.1 Play single tone output to MAX98357. """ import math import array import time from machine import I2S, Pin print("Start") MAX98357_LRC = 17 MAX98357_BCLK = 16 MAX98357_DIN =15 i2s = I2S(0, sck=Pin(MAX98357_BCLK), ws=Pin(MAX98357_LRC), sd=Pin(MAX98357_DIN), mode=I2S.TX, bits=16, format=I2S.MONO, rate=44100, ibuf=44100, ) pr...

ESP32S3/MicroPython display bmp on ili9341 LCD

Image
Last post introduced setup and basic of ESP32-S3-DevKitC-1 running MicroPython v1.24.1 using 3.2" 320x240 IPS LCD (ILI9341 SPI) with Cap. Touch (FT6336U) and Micro SD Slot . This post further exercise to load 240x240 RGB888/RGB565 bmp from device/SD, display on ILI9341 LCD. Remark for ESP32-S3-DevKitC-1: For ESP32-S3-DevKitC-1 with Octal SPI flash/PSRAM memory, use the "spiram-oct" variant such as ESP32_GENERIC_S3-SPIRAM_OCT-20241129-v1.24.1.bin (ref:  https://micropython.org/download/ESP32_GENERIC_S3/ ). If use a in-correct firmware such as ESP32_GENERIC_S3-20241129-v1.24.1.bin, "MemoryError: memory allocation failed" will be raised. For boards with Octal SPI flash/PSRAM memory embedded ESP32-S3-WROOM-1/1U modules, and boards with ESP32-S3-WROOM-2 modules, the pins GPIO35, GPIO36 and GPIO37 are used for the internal communication between ESP32-S3 and SPI flash/PSRAM memory, thus not available for external use. (ref:  https://docs.espressif.c...

ILI9341/FT6336U/SD on ESP32S3/MicroPython

Image
Exercise of MicroPython v1.24.1 running on  ESP32-S3-DevKitC-1 , display on  3.2" 320x240 IPS LCD (ILI9341 SPI) with Cap. Touch (FT6336U) and Micro SD Slot . In the exercises, all the three parts of the display module have been tested: ILI9341 SPI LCD, FT6336U cap. touch, and MicroSD card slot. Connection: ESP32-S3-DevKitC-1 ILI9341 SPI display module +-----USB--UART-----+ |GND           GND | GND |GND           5V0 | |IO19 IO14| LCD_CS |IO20 IO13| LCD_RST |IO21 IO12| LCD_RS |IO47 IO11| SDI(MOSI) |IO48 IO10| SCK |IO45 IO9 | LED |IO0 IO46| |IO35 IO3 | |IO36 IO8 | SDO(MISO) |IO37 IO18| SD_CS |IO38 IO17| |IO39 IO16| |IO40 IO15| |IO41 IO7 | CTP_SCL |IO42 IO6 | CTP_RST |IO2 IO5 | CTP_SDA |IO1 IO4 | CTP_INT |IO44 RST | |IO43 3V3 | |GND 3V3 | VCC +-------------------+ Libraries: In the exercise...

Control onboard LED of Raspberry Pi Pico 2/2W using MicroPython/CircuitPython

Image
The onboard LED on Raspberry Pi Pico and Pico 2 is connected to GPIO25. On Pico W and Pico 2 W, it's connected to the wireless chip. Following are exercise to control the onboard LED using MicroPython/CircuitPython, tested on Pico 2 and Pico 2 W. mpy_rp2_led.py """ MicroPython on Raspberry Pi Pico 2/2W to control onboard LED """ import os, sys import time #import board #from digitalio import DigitalInOut, Direction sys_info_text = sys.implementation[0] + " " + os.uname()[3] +\ "\nrun on " + os.uname()[4] print("=======================================") print(sys_info_text) print("=======================================") led = machine.Pin("LED", machine.Pin.OUT) print("led:", led) # Control onboard led using led.on() and led.off() while True: led.on() time.sleep(0.5) led.off() time.sleep(0.5) """ # Toggle onboard led using led.togg...

Raspberry Pi Pico 2/MicroPython display bmp images on 240x240 ST7789 SPI Display

Image
Previous exercise " Raspberry Pi Pico 2/MicroPython read bmp images and draw on ST7789 display pixel-by-pixel " is a slow approach. Because it draw in pixel-by-pixel, each involve a write sequency. But it help me understand bmp much more. Here is another approach, form a bytearray passing to st7789pt blit_buffer() method, such that the driver write the whole buffer in one sequency to improve the speed much more. For connection and installing st7789py_mpy on Raspberry Pi Pico 2/MicroPython, read: https://coxxect.blogspot.com/2024/10/raspberry-pi-pico-2micropython-display.html To prepare 240x240 RGB565/RGB888 bmp using Python or GIMP, read: https://coxxect.blogspot.com/2024/11/resize-jpg-and-convert-to-bmp-in-rgb888.html Exercise code: mpy_pico2_bmp_buffer.py """ Raspberry Pi Pico/MicroPython exercise to display on 1.54" IPS 240x240 with SPI ST7789 driver Read, decode bmp in /images/ directory, and disply on 240x240 SPI ST77...

Raspberry Pi Pico 2/MicroPython read bmp images and draw on ST7789 display pixel-by-pixel.

Image
Follow the former exercises of  Raspberry Pi Pico 2/MicroPython display on 1.54" 240x240 ST7789 SPI IPS and  Python code to read .bmp info from header (work on Desktop Python and MicroPython) , this exercise read bmp images, and draw on ST7789 display pixel-by-pixel. Exercise code: mpy_pico2_bmp.py """ Raspberry Pi Pico/MicroPython exercise to display on 1.54" IPS 240x240 with SPI ST7789 driver Pixel-by-Pixel Read, decode bmp in /images/ directory, and disply on 240x240 SPI ST7789 display. Target: - 240x240 RGB565 .bmp - 240x240 RGB888 .bmp ref: Using library: russhughes/st7789py_mpy https://github.com/russhughes/st7789py_mpy to install st7789py_mpy on Raspberry Pi Pico 2/MicroPython, https://coxxect.blogspot.com/2024/10/raspberry-pi-pico-2micropython-display.html to know more about bmp structure: https://coxxect.blogspot.com/2024/10/python-code-to-read-bmp-info-from.html to convert jpg to RGB565/RGB888 bmp using GIMP, read the...