I'm very new in electronic stuff. I'm used to develop for desktop and mobile applications not for hardware products.
I try to wire up my Raspberry Pi board with an MCP4131 digital potentiometer. But it's not very easy to understand. I tried to build the projects from this previous thread. But Chris (the original posted in that thread) hasn't supplied a schematic of the wiring nor the successful running source code - so I tried my best to find out by myself:
What's the meaning if P0A, P0W, P0B? I tried to measure the voltage across P0A and P0B but it's always 0V. To which connectors should a LED, buzzer, ... be connected to regulate? (P0A-P0W or P0B-P0W)
My Python code look likes the following (tried to adapt the hint with writing out eight 0's before the value):
import time
import RPi.GPIO as GPIO
SPI_CS_PIN = 17
SPI_CLK_PIN = 23
SPI_SDISDO_PIN = 22 # mosi
GPIO.setmode(GPIO.BCM)
GPIO.setup(SPI_CS_PIN, GPIO.OUT)
GPIO.setup(SPI_CLK_PIN, GPIO.OUT)
GPIO.setup(SPI_SDISDO_PIN, GPIO.OUT)
def set_value(value):
print "here"
GPIO.output(SPI_CS_PIN, True)
GPIO.output(SPI_CLK_PIN, False)
GPIO.output(SPI_CS_PIN, False)
b = '{0:016b}'.format(value)
for x in range(0, 16):
print 'x:' + str(x) + ' -> ' + str(b[x])
GPIO.output(SPI_SDISDO_PIN, int(b[x]))
GPIO.output(SPI_CLK_PIN, True)
GPIO.output(SPI_CLK_PIN, False)
GPIO.output(SPI_CS_PIN, True)
while True:
for level in range(0, 128):
print 'level:' + str(level)
set_value(level)
time.sleep(0.1)
for level in range(127, -1, -1):
print 'level:' + str(level)
time.sleep(0.1)
Is there an easier way to use the MCP4131? I know the RPi supports the SPI protocol, but I'm not sure how to handle the multiplexing, because the RPi has one dedicated pin for SDI and SDO.