spi on fopy

  • Want to use mosi on the fipy but it says it's a external antenna switch. What is this pin for and can I use this pin for spi?

  • @misterlisty From the docs "(spi_)id can only be 0". And you have to specify the MISO pin

  • chain = WS2812(spi_bus=2,ledNumber=3)
    data = [
         (255, 0, 0),    # red
         (0, 255, 0),    # green
        (0, 0, 255)    # blue
    #modified part of ws2812
     def __init__(self, spi_bus=0, ledNumber=1, intensity=1):
        * spi_bus = SPI bus ID (1 or 2)
        * led_count = count of LEDs
        * intensity = light intensity (float up to 1)
        self.led_count = ledNumber
        self.intensity = intensity
        # prepare SPI data buffer (4 bytes for each color)
        self.buf_length = self.led_count * 3 * 4
        self.buf = bytearray(self.buf_length)
        # SPI init
        self.spi = SPI(spi_bus, SPI.MASTER, baudrate=3200000, polarity=0, phase=1, pins=('P23','P22')) #modified
        # turn LEDs off

    Get an error on line 56..resource not available...

    line 56= self.spi = SPI(spi_bus, SPI.MASTER, baudrate=3200000, polarity=0, phase=1, pins=('P23','P22'))

  • @misterlisty You would at least need CLK and MOSI. But if you want to change only one Pin, you could specify the default values for the others.

  • thanks, when i setup SPI, what if i just want to setup MOSI pin? is this possible? The syntax appears to want clk, mosi, miso

  • @misterlisty Since this P12 is used for the antenna switch, you cannot use it for MISO. But you can use any other Pin for SPI. P12 is just the default setting. You can specify these Pins in the constructor of the SPI object (see the docs: https://docs.pycom.io/chapter/firmwareapi/pycom/machine/SPI.html). Please consider, that P13 to P18 are input only, so they cannot be used for MOSI or CLK, and P15, P17 and P18 are used for the LTE modem.
    That's the downside of the many functions: fewer Pins available for own usage.


Pycom on Twitter