Closed usamabashir82 closed 1 year ago
@usamabashir82 Can you provide an example to demonstrate this issue?
In general, the usage of u2if with CircuitPython libraries via Blinka only uses the firmware hosted in this repository - everything in the firmware
directory. Nothing in the source
directory is actually used.
@caternuson Sorry if i was unable to provide a clear description.
Here is how i came across this.
I wanted to read temperature from a MAX31855K sensor over spi. The example implemented in the examples/lcd_ball_ssd1306_spi.py explains the usage as `spi = SPI(spi_index=0) spi.init(baudrate=10000000)
reset = Pin(u2if.GP8, Pin.OUT, value=Pin.LOW) dc = Pin(u2if.GP9, Pin.OUT, value=Pin.LOW) cs = Pin(u2if.GP17, Pin.OUT, value=Pin.HIGH)
oled = SSD1306_SPI(128, 64, spi, dc, reset, cs)` I tried using this implementation with https://github.com/adafruit/Adafruit_CircuitPython_MAX31855 this is the code i used.
import adafruit_max31855 from machine import I2C, SPI, u2if, Pin
spi = SPI(spi_index=0) spi.init(baudrate=10000000) cs = Pin(u2if.GP17, Pin.OUT, value=Pin.HIGH) max31855 = adafruit_max31855.MAX31855(spi, cs) print('Temperature: {} degrees C'.format(max31855.temperature))
This generated 2 errors.
I figured that the spi object used in adafruit_max31855 is expected to have try_lock() and unlock() functions which actually get inherited from Lockable. So i implemented the functions of the Lockable class in spi class. Now in hindsight i realize should have just inherited that class.
Do let me know if there is something i missed entirely or anything needs adding. Thanks
edit: I am sorry i am unable to figure out these code blocks. I'll try to fix them tomorrow🙃
Thanks for the additional information. It helps figure out what's going on.
If you are wanting to use the library: https://github.com/adafruit/Adafruit_CircuitPython_MAX31855 you'll want to follow this guide: https://learn.adafruit.com/circuitpython-libraries-on-any-computer-with-raspberry-pi-pico for getting things set up.
It can be confusing, because there are several software components that all work together. This repo is a fork of the original repo here: https://github.com/execuc/u2if and that project had a slightly different goal overall. The firmware was just one part of the whole project. However, for using CircuitPython libraries, it is only the firmware that is used. The examples in this repo were not written for that use case, so can not be used in conjunction with CircuitPython libraries.
Once you've gone through the setup in the guide linked above, you should be able to run the examples from the MAX31855 repo without any code changes: https://github.com/adafruit/Adafruit_CircuitPython_MAX31855/blob/main/examples/max31855_simpletest.py
Closing. Hopefully information above clarified things.
Was testing adafruit_max31855 with this. The SPI file does not have lockable implemented in it. Wanted to inherit the module from adafruit blinka but that one creates an MPO error. Pin module had a missing function necessary for control as a chip select pin with spi.