I have a few MCP4151 digitpots, I have used them with Arduino uno and the library (attached) and they work really well. I needed to shrink down to a ATtiny85, I grabbed the TinySPI library and tested regular SPI commands on the Tiny and the UNO but it doesn't work at all. I also tried changing the DigiPots library to TinySpi but it still didn't set. The digipot has a Multiplexed SDI and SDO pin but i had no problems on the UNO. I think using SPI commands would be simple but the Pots library makes me think otherwise but I don't know much about SPI so im at a loss. :~
This is the UNO code using the Library, it sets a LED brightness according the the Pots value
I was planning on controlling a speaker systems volume via remote, as an example:
/*
DigiPot LED dimmer
and volume changer
Cr:06/03/2014
LM:11/03/2014
V: 0.10
*/
#include <SPI.h>
#include <mcp4xxx.h>
#include <EEPROM.h>
#include <IRremote.h>
MCP4XXX* pot;
int LED = 6; // LED that gets dimmed
int OnLED = 7; // comes on when volume is 0
int RECV_PIN = 3; // IR recevier pin
IRrecv irrecv(RECV_PIN); // IR receiver lib stuff
decode_results results; // IR receiver lib stuff
// Vars
int VOLsav = 0; // Saves the current volume level to this EPPROM address
int VOLlevel = 0; // Current Volume level
int potValue = 0; // Current pot value, 0 to 256
int POTsav = 1; // Saves the current pot value to this EPPROM address
int storePOT = 0; // store the Pot Value
int muted = LOW; // LOW = not muted, HIGH = muted
int Lcode = 1;
void setup(){
pot = new MCP4XXX(10); // pot CS pin will be set to 10
Serial.begin(9600);
pinMode(RECV_PIN,INPUT);
irrecv.enableIRIn(); // Start the receiver
pinMode(LED,OUTPUT);
pinMode(OnLED,OUTPUT);
pot->set(0);
VOLlevel = EEPROM.read(VOLsav);
potValue = EEPROM.read(POTsav);
SetPot();
}
void loop(){
if (irrecv.decode(&results)) {
if (results.value == 0xFB58A7 || results.value == 0x20DF40BF) { // TV Dpad VOL Up
if (muted != HIGH){
//digitalWrite(PWRled,LOW);
VOLlevel++;
if (VOLlevel > 100){VOLlevel = 100;}
if (VOLlevel < 51){potValue = potValue + 3;}
if (VOLlevel >= 51){potValue = potValue + 2;}
if (potValue > 250){potValue = 250;}
SaveVals();
SetPot();
Lcode = 1;
delay(100);
//digitalWrite(PWRled,HIGH);
}
}
else if (results.value == 0xFB12ED || results.value == 0x20DFC03F) { // TV Dpad VOL down
if (muted != HIGH){
//digitalWrite(PWRled,LOW);
VOLlevel--;
if (VOLlevel < 0){VOLlevel = 0;}
if (VOLlevel < 51){potValue = potValue - 3;}
if (VOLlevel >= 51){potValue = potValue - 2;}
if (potValue < 0){potValue = 0;}
SaveVals();
SetPot();
Lcode = 0;
delay(100);
//digitalWrite(PWRled,HIGH);
}
}
else if (results.value == 0xFBBA45 || results.value == 0x20DF807F) { // TV red button Mute
//digitalWrite(PWRled,LOW);
if (muted == LOW){
storePOT = potValue;
potValue = 0;
muted = HIGH;
SetPot();
}
else
if (muted == HIGH){
potValue = storePOT;
storePOT = 0;
muted = LOW;
SetPot();
}
delay(100);
//digitalWrite(PWRled,HIGH);
}
irrecv.resume(); // Receive the next value
}
if (VOLlevel == 0 || muted == HIGH){
digitalWrite(OnLED,HIGH);digitalWrite(LED,LOW);}
if (VOLlevel != 0){digitalWrite(OnLED,LOW);}
if (VOLlevel > 0){
analogWrite(LED,potValue);}
}
void SetPot(){
pot->set(potValue);
}
void SaveVals(){
EEPROM.write(VOLsav,VOLlevel);
EEPROM.write(POTsav,potValue);
}
mcp4xxx.h (9.88 KB)
mcp4xxx.cpp (5.34 KB)
README.md (2.59 KB)