MCP41010 Single/Dual Digital Potentiometer with SPITM Interface

used products:

1. Arduino UNO
2. MCP41010

content:

Çeşme: http://techrm.blogspot.com.tr/2015/02/how-to-control-digital-potentiometer.html

Arduino:

int csPin = 2; // Chip Select on pin 2 of Arduino int sckPin = 4; // Serial Clock on pin 4 of Arduino int sdiPin = 5; // Serial Data Input on pin 5 of Arduino byte address = B00010001; // Command byte // 17 //byte address = 0x11; // 17 int values[] = {0,38,255}; void potify(byte val) { digitalWrite (csPin, LOW); spi_transfer(address); spi_transfer(val); digitalWrite(csPin, HIGH); } void spi_transfer(byte bb) { byte mask; for (int i = 7; i >= 0; i--) { mask = 0x01 << i; int v = !!(bb&mask); digitalWrite(sdiPin, v); digitalWrite (sckPin,HIGH); digitalWrite(sckPin, LOW); } } void setup() { pinMode(csPin, OUTPUT); pinMode(sckPin, OUTPUT); pinMode(sdiPin, OUTPUT); Serial.begin(9600); Serial.println("Ready!"); } void loop() { for (int i = 0; i < 3; i++) { int v = values[i]; Serial.print("v: ");Serial.print(v);Serial.println(); potify(v); delay(1000); } }