0

I'm using SPI library in my code for controlling a digital potentiometer (TPL0501) with Arduino Mega.

The code I have is:

#include <SPI.h>
byte address = 0x80;
const int CS = 53;
int SCLK = 52;
int i=0;

void setup()
{
  SPI.begin();
  pinMode (CS, OUTPUT);
  pinMode (SCLK, OUTPUT);
  SPI.setBitOrder(MSBFIRST);


}

void loop()
{

     for (i = 0; i < 256; i++)
    {
      digitalPotWrite(i);
      delay(100);
    }

    delay(5000);
    for (i = 255; i >= 0; --i)
    {
      digitalPotWrite(i);
      delay(100);
    }
}

int digitalPotWrite(int value)
{
  digitalWrite(CS, LOW);
  delay(100);
  SPI.transfer(address);
  SPI.transfer(value);
  delay(100);
  digitalWrite(CS, HIGH);


}

Following the datasheet, I think the code is correct because this is what the datasheet says:

Datasheet

Can someone help me identify the error in my code, if any, because when I try to read the resistance with an ohmeter, I do not get the expected values.

  • what is expected and actual value, can you provide any example for this? – Vaibhav Apr 23 at 9:04
  • @Vaibhav the end to end resistance is 100kOhms. It's supposed to give me output in that range, increasing values first, then decreasing. I'm using the component alongside a buck-boost converter, but am currently trying to only test the potentiometer alone. – George Apr 23 at 9:10
  • Are you floating all H, L and W terminals? The voltage relative on this pins should not exceed GND-VDD range. Connect L to GND then measure the resistance again. – Dorian Apr 24 at 8:33
  • What is SPI.transfer(address); supposed to achieve? SPI has no "address" concept, unless it's for selecting registes within a chip - and that chip has none. – Majenko Apr 24 at 9:10
  • try and measure the voltage drop between pin W and L if H is floating or between H and W if L is floating. – Delyan Karaslavov Oct 3 at 18:05

Your Answer

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

Browse other questions tagged or ask your own question.