0

There are a couple of old posts with example code and wiring schematics for Pi and MCP4130 digital pots. I've tried using these code examples and believe I have wired it up correctly but my LED does nothing. I've verified the LED works. I verified the GPIO Pins are changing to OUT using GPIO readall while the script is running. I've verified through various tutorials and posts that SPI is active and working properly. I'm new with Pi so I'm sure I'm missing something. If someone could take a look at my wiring and the code from a past post and let me know if you see anything or if you have your own example code I would appreciate any help.
enter image description here

Link to the data sheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf

And the code from previous post:

import sys
import time
import RPi.GPIO as GPIO
import spidev


SPI_CS_PIN = 17
SPI_CLK_PIN = 22
SPI_SDISDO_PIN = 23

def sleep(a = .5):
    time.sleep(a)

def wait_a_key():
    print "waiting..."
    #raw_input()

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)

GPIO.output(SPI_CLK_PIN, False)
GPIO.output(SPI_SDISDO_PIN, False)
GPIO.output(SPI_CS_PIN, False)

print "Setup"
GPIO.output(SPI_CS_PIN, True)
GPIO.output(SPI_CLK_PIN, False)
GPIO.output(SPI_CS_PIN, False)
wait_a_key()

def set_value(b):
    b = "0000" "00" "{0:010b}".format(b)

GPIO.output(SPI_CS_PIN, False)
for x in b:
    GPIO.output(SPI_SDISDO_PIN, int(x))
    GPIO.output(SPI_CLK_PIN, True)
    #sleep()
    GPIO.output(SPI_CLK_PIN, False)
    #sleep()

wait_a_key()

GPIO.output(SPI_CS_PIN, True)
sleep()

try:
    for i in range(0, 100, 10):
        print 'set_value:' + str(i)
        set_value(i)
        sleep()

finally:
    GPIO.cleanup()
    print "GPIO Cleanup"

This code was used with an MCP4131 digital pot so would that be an issue using this with a 41010? I'm new enough at all this so I could easily be missing something. And another NOOB question, on the Pi 3 pinout, CE0 is BCM Pin 8, MOSI is BCM Pin 10, and the clock pin is BCM 11 which is how I have it wired but I have seen wiring to other available GPIO pins and just defined those pins as CS, CLK, and SDI/SDO. Is either way correct or am I doing it incorrectly? I've tried both ways with the same result but I'm curious anyway.

Thanks for any help. I've enjoyed learning from those on this site.

migrated from electronics.stackexchange.com May 14 '17 at 21:52

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 2
    Please flag to reject this migration. The problem has nothing to do with RPi. – cde May 14 '17 at 22:56
  • Why not use hardware SPI rather than that rather strange bit bang approach? Do you need to use special GPIO? A clear photo would be more useful than a schematic. There is no way to tell if you have implemented the schematic properly without a clear photo. You should also link to the device specs in your question. – joan May 15 '17 at 7:58
  • Here is the ultimate goal: I want to vary the resistance of the input voltage of a gas cell (CO, CO2, O2) for zero and span adjustments. The Qt GUI has buttons that I want to be able to push for increased and decreased resistance in some increment that I set. I'm open to any suggestions that you may have. I'm new at this and there likely is a better way. I didn't burn out the Digital Pots, they are still working. I found a bit of code last night and it is functioning as wired. The LED starts full on then dims little by little. I can post that code if you wish. Thanks for your time. – kjohns May 15 '17 at 14:33
  • @kjohns whats the gas cell part and data sheet link? – cde May 17 '17 at 3:01
2

Measure the resistance at PW0 and PA0. Is it changing when you tell it to change?

Likely not. The MCP41xxx has a maximum wiper current of 1mA. More than that and you likely burn out the wiper. Digital pots are not meant to be used for actual loads, they are meant to be used for reference applications (like controlling a voltage regulator's Adjust pin).

I figure you damaged the part.

  • Ok, thanks for the reply. I guess I'm not sure that I understand. This setup has worked for others on this site and elsewhere. So a digital pot can't dim and brighten an LED? Is it because I wired something wrong or the wrong digital pot? – kjohns May 14 '17 at 17:13
  • Only if the current through the wiper is less than 1 mA. It's a physical limit of the construction of the pot What others, link please? – cde May 14 '17 at 17:30
  • I've used this: – kjohns May 14 '17 at 17:43
  • Sorry, this site takaitra.com/posts/503 – kjohns May 14 '17 at 17:43
  • 1
    Not by much the mcp41xx has 2.5 mA max on the wipers. Most digital pots are similar. If you need led brightness control, look for PWM solutions. A digital pot is not the solution. There are plenty of i2c controllable led controllers. – cde May 14 '17 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.