SPI conflict? LCD backpack & MAX31865

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
michaelmcs
 
Posts: 17
Joined: Wed Aug 26, 2020 9:10 pm

SPI conflict? LCD backpack & MAX31865

Post by michaelmcs »

This has been cross posted to the CircuitPython forum.

setup:
Adafruit CircuitPython 7.2.5 on 2022-04-06; FeatherS2 with ESP32S2
I2C/SPI LCD backpack
PT 1000 amplifier

I started using the I2C bus for the LCD backpack, but it was way too slow. I switched over to the SPI bus and it was vastly improved. However, I can't get both the PT1000 amplifier and the LCD display to work at the same time.

I can get a good display up until I check the temperature, then I get garbage on the display.

I print the temperature to REPL, and the results are reasonable (room temperature until I hold the sensor, then it goes up).

Code: Select all

    import gc
    import sys
    import time
    import board
    import digitalio
    import busio
    import adafruit_max31865
    import adafruit_character_lcd.character_lcd_spi as character_lcd
    def display(string):
            lcd.clear()
            lcd.message = string

    lcd_columns = 20
    lcd_rows = 5
    spi = busio.SPI(board.SCK, MOSI=board.MOSI)
    latch = digitalio.DigitalInOut(board.D5)
    lcd = character_lcd.Character_LCD_SPI(spi, latch, lcd_columns,
                                        lcd_rows)

    spi = busio.SPI(board.SCK, MOSI=board.MOSI,MISO=board.MISO)
    cs = digitalio.DigitalInOut(board.D9)
    adafruit_max31865.MAX31865(spi, cs, wires=3,
                    rtd_nominal=1000.0, ref_resistor=4300.0)

    lcd.backlight = True
    lcd.clear()

    def temp():
        try:
            t= temperature * 9 / 5 + 32
            return(int(t))
        except:
            return(0)


    currentTemp = 22
    setTemp = 55

    while True:
        previousTemp = currentTemp
        currentTemp = sensor1.temp()
        currentTemp = 55
        display("%d / %d" % (round(currentTemp), round(setTemp)))
        time.sleep(5)
        setTemp += 1
I assumed that the library functions would handle locking and unlocking the SPI bus. Am I mistaken?

Thanks in advance for any help.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI conflict? LCD backpack & MAX31865

Post by mikeysklar »

I don't see the MAX31865 or CharLCD library managing the CS pin for you.

Try manually pulling it HIGH to disable a device and pulling the requested device CS low when ready to use the next one.

https://github.com/adafruit/Adafruit_Ci ... ax31865.py

User avatar
michaelmcs
 
Posts: 17
Joined: Wed Aug 26, 2020 9:10 pm

Re: SPI conflict? LCD backpack & MAX31865

Post by michaelmcs »

I changed the 'display' and 'readTemp' functions to set the cs/latch pin high before accessing and low after.

Still garbage after the first 'readTemp' call.

Code: Select all

def readTemp():
    try:
         cs.value = False
         t= sensor.temperature * 9 / 5 + 32
         cs.value = True
         return(int(t))
     except:
         return(0)

Code: Select all

def display(string):
    latch.value = False
    lcd.clear()
    lcd.message = string
    latch.value = True
    time.sleep(2)
Just to be sure, I then commented out all the MAX31865 code. The display then looks great.

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: SPI conflict? LCD backpack & MAX31865

Post by mikeysklar »

The code snippets you shared look correct, but there is a note in the guide that this character LCD:
This library does not use the Hardware SPI library, which means you can use any 3 pins! However, if you are using the hardware SPI port (such as for Ethernet, WiFi, an LCD, etc. etc) you cannot share those pins with this LCD!
https://learn.adafruit.com/i2c-spi-lcd- ... no-spi-use

If you want to switch the character_lcd back to i2c you could try bumping up the bus speed.

; 400Hz
busio.I2C(board.SCL, board.SDA, frequency=400000)

; 1MHz
busio.I2C(board.SCL, board.SDA, frequency=1000000)

User avatar
michaelmcs
 
Posts: 17
Joined: Wed Aug 26, 2020 9:10 pm

Re: SPI conflict? LCD backpack & MAX31865

Post by michaelmcs »

Thank-you. I hadn't noticed that caveat

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”