Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Trinket M0 + MCP41010 via SPI
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket M0 + MCP41010 via SPI

by GeorgeM987 on Thu Nov 25, 2021 8:30 am

Hi All,

Just started with the likes of trinket boards and CircuitPython in general and as a project I kind of want to migrate from the Arduino world would be controlling a digipot(i.e. MCP41010) with the Trinket M0 via SPI.

MCP41010:
https://docs.rs-online.com/e6b5/0900766b81380c8b.pdf

I guess want I'm really interested in, is if anyone had any experience trying to control a device via SPI with the Trinket M0?!
I've tried doing it manually and with the library with no luck:
Code: Select all | TOGGLE FULL SIZE
from adafruit_bus_device.spi_device import SPIDevice


Regards,
George M.

GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Re: Trinket M0 + MCP41010 via SPI

by GeorgeM987 on Thu Nov 25, 2021 9:37 am

And this is the code for the manual setup:
Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
from time import sleep


cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.OUTPUT

spi = busio.SPI(board.SCK, board.MOSI)

while not spi.try_lock():
    pass
try:
    spi.configure(baudrate=5000000, phase=0, polarity=0)
    cs.value = False
    result = bytearray(256)
    spi.write(result)
    sleep(1)
    cs.value = True
finally:
    spi.unlock()


...and with the library:
Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
from time import sleep
from adafruit_bus_device.spi_device import SPIDevice

SIZE = [0, 128, 256]

spi = busio.SPI(board.SCK, board.MOSI)
cs = digitalio.DigitalInOut(board.D2)
cs.direction = digitalio.Direction.OUTPUT
cs.value = False

device = SPIDevice(spi, cs, baudrate=100000, polarity=0, phase=0)


with device:
    spi.write(bytearray(256))
    sleep(1)
    cs.value = True
   

GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Re: Trinket M0 + MCP41010 via SPI

by GeorgeM987 on Fri Nov 26, 2021 9:52 am

Also tried a software SPI version with no success:

Code: Select all | TOGGLE FULL SIZE
import board
import digitalio
from adafruit_bitbangio import adafruit_bitbangio as bitbangio
from time import sleep


SIZE = [0, 128, 256]

SCLK_PIN = board.D4
MOSI_PIN = board.D3
CS_PIN = board.D2

cs = digitalio.DigitalInOut(CS_PIN)
cs.switch_to_output(value=True)
spi = bitbangio.SPI(SCLK_PIN, MOSI_PIN)
cs.value = 0

while not spi.try_lock():
    pass
spi.write([0xD0])
sleep(1)
spi.unlock()
cs.value = 1

GeorgeM987
 
Posts: 3
Joined: Thu Nov 25, 2021 8:12 am

Please be positive and constructive with your questions and comments.