Hi all.
I was trying to use a digital potentiometer (MCP4131) to control the brightness of a LED using a clone UNO.
I followed this Tutorial (Code 2):
I hooked up my MCP4131 using this datasheet:
I used this Code:
#include <SPI.h>
byte address = 0x00;
int CS= 10;
void setup()
{
pinMode (CS, OUTPUT);
SPI.begin();
}
void loop()
{
for (int i = 0; i <= 128; i++)
{
digitalPotWrite(i);
delay(10);
}
delay(10);
for (int i = 128; i >= 0; i--)
{
digitalPotWrite(i);
delay(10);
}
}
int digitalPotWrite(int value)
{
digitalWrite(CS, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH);
}
... and I got just a dim glowing LED that was reluctant at best to change brightness -- or it would do nothing.
AS I WAS CHECKING MY CONNECTIONS, it magically started working. I was happy, BUT then I removed my finger and it stopped working. After playing with the wires for a minutes, I discovered the culprit was the wire connecting the SDI/SDO of the MCP4131 to the MOSI (pin 11) of the UNO.... SO, I pressed on the wire again, thinking maybe I had a bad connection, and it started working, I pulled my hand back and it stopped working.
I changed holes in the breadboard to see if that would help, but got the same result: as long as I had my finger on the INSULATED wire, it worked - but only if my finger was on the insulated wire.
Thinking I was adding some vague resistance in some way to the wire, I decided to put a 330-ohm resistor in the MOSI/SDI wire then connect to the UNO - didn't work.
My next thought is maybe my finger was creating a ground in the wire, so I wrapped the INSULATED wire with one leg of a tube resistor, then connected the other leg to ground -- WOW!! THAT works perfectly.
Someone want tell me what's going on? I KNOW this is NOT a viable circuit, so how do I correct it? Meanwhile, she's working perfectly -- perfectly weird!