Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
share lcd SPI
#1
before starting I would like to thank mr. loboris, thanks Boris for your remarkable work!

i wrote this on the m5stack community forum, but no one has even tried to answer it so i try and hope here:

Quote:    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 Wink

    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")
   

    that file called "m5stack" only serves to initialize the various peripherals, as far as the LCD is concerned, it only does this:

   

    import display as lcd
    import machine
    lcd = lcd.TFT()
    lcd.init(lcd.M5STACK, width=240, height=320, speed=40000000, rst_pin=33,
             miso=19, mosi=23, clk=18, cs=14, dc=27, bgr=True,invrot=3,
             expwm=machine.PWM(32, duty=0, timer=1))
    lcd.setBrightness(30)
    lcd.clear()
    lcd.setColor(0xCCCCCC)
   

    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 "", line 1, in
        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 understood that the problem is on the spi dma channel and I understood broadly what it does and what it is used for, what I didn't understand is how to try to acquire that bus in pyhon. Can you help me?

like before, any advice is welcome, thank you for reading, patience and any response.
Reply
#2
Wink 
the m5stack community was unable to help me and told me to ask here, and it was m5stack directly who told me that  Sad
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)