Lepeshka92 / micropython-esp8266-st7920

Micropython driver for 128x64 ST7920 display.
GNU General Public License v3.0
7 stars 0 forks source link

Needs delays for fast processors #2

Open vpatron opened 3 years ago

vpatron commented 3 years ago

Hi, this would not work with a Raspberry Pi Pico.

I found out it needs delays. I put sleep(0.000_072) after each SPI write because the datasheet says the commands can take up to 72 microseconds and it works fine now.

    def _write(self, cmd, data):
        self.cmd[0] = cmd
        self.cmd[1] = (data & 0xF0)
        self.cmd[2] = ((data << 4) & 0xF0)
        self.spi.write(self.cmd)
        sleep(0.000_072)   # Most st7920 commands need 72 us delay

    def init(self):
        if self.rst:
            self.rst(0)
            sleep(0.1)
            self.rst(1)
        for cmd in (ST7920_BASIC,
                    ST7920_CLEAR_SCREEN,
                    ST7920_DISPLAY_CTRL,
                    ST7920_EXTEND,
                    ST7920_EXTEND | 0x02):
            self._write(ST7920_CMD, cmd)
            sleep(0.000_072)
        self.show()

Thanks for posting this program. It's a good simple example and I found it very useful.

Lepeshka92 commented 3 years ago

Thank you. I add delay to _write method