Wednesday, April 24, 2019

MCP42100 - 100K with Raspberry Pi 3 model B+ - using spi

MCP42100 is a 100K variable resister controlled using spi interface. The only issue with this one is that it has a very high variation in resistance (high tolerance ) can vary from 70K to 130K

Data sheet - http://ww1.microchip.com/downloads/en/devicedoc/11195c.pdf




Python code for controlling this with SPI


import time
import spidev
import RPi.GPIO as gpio

gpio.setmode(gpio.BCM)
gpio.setup(4,gpio.OUT)

#if you need to open circuit 
#gpio.output(4, gpio.LOW) # Open circuit
#gpio.output(4, gpio.HIGH) # Closed circuit, resistor working


bus = 0 
device = 0

spi = spidev.SpiDev()
spi.open(bus, device)

spi.max_speed_hz = 500000
spi.mode = 0

# try 0 that will set resistance to the min value
res = input("value?")

x = spi.xfer2([19,res])

print(x)


No comments: