Skip to content
JT edited this page Aug 4, 2024 · 4 revisions

Welcome to the MicroPython_CYD_ESP32-2432S028R wiki!

This higher-level library allows MicroPython users to easily access all the features of the ESP32-2432S028R, more commonly known as the Cheap Yellow Display (CYD). There are many boards labeled ESP32-2432S028R, and they are not all built the same. The most common difference is the display orientation. Luckily there is a quick fix for that when you implement the CYD() Class.

Implementation

Follow MicroPython's installation instructions to get your CYD board ready. Use your preferred MicroPython IDE (e.g. Thonny) to transfer cydr.py, boot.py, ili9341.py, and xpt2046.py to your CYD board.

Using this library is easy. Simply import the CYD class from the library module and then use it by...

from cydr import CYD
cyd = CYD()

or if you want to change a default setting use

from cydr import CYD
cyd = CYD(rgb_pmw=False, speaker_gain=512,
          display_width=240, display_height=320,
          wifi_ssid = None, wifi_password = None)
'''
Args:
    rgb_pmw (Default = False): Sets RGB LED to static mode. (on/off), if false
                               Sets RGB LED to dynamic mode. (16.5+ million color combination), if true
                               Warning: RGB LED never completely turns off in dynamic mode.

    speaker_gain (Default = 512): Optional - Sets speaker's volume. The full gain range is 0 - 1023.
    display_width (Default = 240): Optional - Reset if needed.
    display_height (Default = 320): Optional - Reset if needed.
    wifi_ssid (Default = None): Optional easy WIFI setup - Name of WIFI network you want to connect to.
    wifi_password (Default = None): Optional easy WIFI setup - Password to the WIFI network.
'''

If your display isn't lining quite right, swap the values of display_width and display_height.

Pinouts

  PINS   FUNCTIONS		     - DESIGNATION  
     0   Boot Button
     1   Connector P1                - TX
     2   Display                     - TFT_RS / TFT_DC
     3   Connector P1                - RX
     4   RGB LED                     - Red
     5   SD Card                     - SS [VSPI]
     6   Unpopulated Pad U4: pad 6   - SCK / CLK
     7   Unpopulated Pad U4: pad 2   - SDO / SD0
     8   Unpopulated Pad U4: pad 5   - SDI / SD1
     9   Unpopulated Pad U4: pad 7   - SHD / SD2
    10   Unpopulated Pad U4: pad 3   - SWP / SD3
    11   Unpopulated Pad U4: pad 1   - SCS / CMD
    12   Display ili9341             - TFT_SDO / TFT_MISO [HSPI]
    13   Display ili9341             - TFT_SDI / TFT_MOSI [HSPI]
    14   Display ili9341             - TFT_SCK [HSPI]
    15   Display ili9341             - TFT_CS [HSPI]
    16   RGB LED                     - Green
    17   RGB LED                     - Blue
    18   SD Card                     - SCK [VSPI]
    19   SD Card                     - MISO [VSPI]
    21   Display & Connector P3      - TFT_BL (BackLight) / I2C SDA
    22   Connector P3 & CN1          - I2C SCL
    23   SD Card                     - MOSI [VSPI]
    25   Touch XPT2046               - CLK [Software SPI]
    26   Speaker                     - !!!Speaker ONLY! Connected to Amp!!!
    27   Connector CN1               - Can be used as a capacitive touch sensor pin.
    32   Touch XPT2046               - MOSI [Software SPI]
    33   Touch XPT2046               - CS [Software SPI]
    34   LDR Light Sensor            - !!!Input ONLY!!!
    35   P3 Connector                - !!!Input ONLY w/ NO pull-ups!!!
    36   Touch XPT2046               - IRQ !!!Input ONLY!!!
    39   Touch XPT2046               - MISO !!!Input ONLY!!! [Software SPI]

CYD Class Functions

    cyd.display.ili9341_function_name()             # Use to access ili9341 functions.

    cyd.touches()
        '''
        Returns last stored touch data.

        Return:
            x: x coordinate of finger 1
            y: y coordinate of finger 1
        '''

    cyd.double_tap(x, y, error_margin = 5)
        '''
        Returns whether or not a double tap was detected.

        Return:
            True: Double-tap detected.
            False: Single tap detected.
        '''

    cyd.rgb(color)
        '''
        Set RGB LED color.

        Args:
            color: Array containing three int values (r,g,b).
                    if rgb_pmw == False, then static mode is activated.
                        r (0 or 1): Red brightness.
                        g (0 or 1): Green brightness.
                        b (0 or 1): Blue brightness.
                    if rgb_pmw == True, then dynamic mode is activated.
                        r (0-255): Red brightness.
                        g (0-255): Green brightness.
                        b (0-255): Blue brightness.
        '''

    cyd.light()
        '''
        Gets light sensor value (Measures darkness)

        Return: a value from 0.0 to 1.0
        '''

    cyd.button_boot()
        '''
        Gets the Boot button's current value
        '''

    cyd.backlight(value)
        '''
        Sets TFT Backlight Off/On

        Arg:
            val: 0 or 1 (0 = off/ 1 = on)
        '''

    cyd.play_tone(freq, duration, gain=0)
        '''
        Plays a tone (Optional speaker must be attached!)

        Args:
            freq: Frequency of the tone.
            duration: How long does the tone play for.
            gain: volume
        '''

    cyd.mount_sd()                                  # Mounts SD card

    cyd.unmount_sd()                                # Unmounts SD card.

    cyd.wifi_connect(ssid, password)
        '''
        Connects to a WLAN network.
        The CYD (client) can connect to an existing WLAN network (station).
        
        Args:
            ssid: The name of the network you want to connect to.
            password: The network password for the ssid you are connecting to.
        '''

    cyd.wifi_isconnected()
        '''
        Checks to see that the wifi connection is connected.
        
        Returns:
            True: Device connected to a network.
            False: Device not connected to a network.
        '''

    cyd.wifi_ip()
        '''
        Get the CYD's IPv4 address on your WLAN.
        
        Returns: The IP address of your device.
        '''

    cyd.wifi_create_ap(_ssid)
        '''
        Creates an Access Point (AP) WLAN network.
        Other devices (clients) can connect to this CYD (station) via wifi.
        
        Args:
            _ssid: The name of your new AP. This is the wifi id that client devices are going to connect to.
        '''

    cyd.open_terminal()                             # Replaces the displayed content with a read-only terminal.

    cyd.close_terminal()                            # Closes read-only terminal.

    cyd.shutdown()                                  # Safely shutdown CYD device.
Clone this wiki locally