how to share lcd spi?



  • Hi guys! this is my first post on this forum, I have some experience with the esp8266 and c and c++ but the esp32 and micropython are new to me. So please try to be nice with me and and I apologize in advance for my English skill ;)

    I am on a m5stack core basic so i don't have psram, and right now I'm using the firmware fork of the lobo. link
    For what I understand so far this is not the latest firmware, it is no longer updated, but it is official and does not have a lot of uiflow stuff. (which I don't use, and I don't understand why I should want to use it) For now i am using upycraft as IDE, which is simple but it does its job.

    Sorry for this long introduction... XD
    I would like to use a simple SPI digital potentiometer (MCP41010) and the LCD.
    With something like this, calling the "cs_write" method, I can easily change the resistance of the potentiometer:

    from machine import SPI,Pin
    from time import sleep

    CS_PIN = const(2)

    spi = SPI(2, baudrate=2600000, polarity=0, phase=0, bits=8, firstbit=SPI.MSB, sck=Pin(18), mosi=Pin(23), miso=Pin(19)) #spihost=SPI.VSPI

    p0 = Pin(CS_PIN, Pin.OUT)
    p0.value(1)
    sleep(0.5)

    def cs_write(value):
    buf=bytearray(2)
    buf[0]=17 #b'\x11' 0001 0001
    buf[1]=value
    p0.value(0)
    spi.write(buf)
    p0.value(1)

    and with something like this I can print on screen:

    from m5stack import lcd
    lcd.tft_writecmd(0x21) #I have not completely understood why but to have the right colors I have to put this
    lcd.clear(lcd.RED)
    lcd.setCursor(100, 50)
    lcd.font(lcd.FONT_DejaVu24)
    lcd.print("Hello")

    but if I run the two codes together when the second try to initialize the spi throw something like this:

    E (225533) spi_master: spi_bus_initialize(95): dma channel already in use
    E (225534) [SPI_UTILS]: spi bus initialization failed with rc=0x103
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    OSError: Error initializing display

    I could actually de-initialize the first spi and initialize the second every time but it's not the cleanest way and it takes more than a second each time to initialize the display.
    how can i do it? is there a way to have the spi instance from the display module and work on that by manually adjusting the cs pins?

    Any advice is welcome, thank you for reading, patience and any response



  • I feel alone ... a little help? :(


  • M5Stack

    maybe you could commit a issues to lobo github. and if you want to use multi SPI device control we suggest you use Arduino to program it