Arduino Digital Potentiometer

Hi,

Im trying to get a resistance (50kΩ digital potentiometer) switching in 255 steps from about 50Ω to about 0Ω and then back to 50Ω and so on..... (....5,4,3,2,1,0 ,1,2,3,4,5...50,49,48....)

Actually the resistance is switching in 255 steps from 50Ω to 0Ω, then its starting at 50Ω again. (50,49....5,4,3,2,1,0 ,50,49,48....).

The digital potentiometer im using: http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf

The code:

#include "AH_MCP41xxx.h"
//#include <SPI.h>
//#define DATAOUT 11 //uno MOSI , IC SI
//#define SPICLOCK 13 //uno SCK , IC SCK
#define CS 10 //chipselect pin
#define SHDN 9 //shutdown pin
#define RS 8 //reset pin
#define POTIOMETER_0 0
#define POTIOMETER_1 1
byte resistance = 0;
int testIN1 = A0;
int testIN2 = A1;
AH_MCP41xxx mcp42010;
void setup()
{
Serial.begin(9600);
Serial.println("Setup ready");
mcp42010.init_MCP42xxx (CS, SHDN, RS); //initialisation
}
void loop()
{
mcp42010.setValue(resistance, POTIOMETER_0);
// value range 0-255 (8-bit)
delay(50);
Serial.print("A0: ");
Serial.print(resistance);
Serial.print(": ");
if (resistance==255) {resistance=0;}
int signal = analogRead(testIN1);
Serial.print(signal);
mcp42010.setValue(resistance, POTIOMETER_1); //value range 0-255 (8-bit)
delay(100);
Serial.print("A1: ");
Serial.print(resistance);
Serial.print(": ");
if (resistance==255) {resistance=0;}
signal = analogRead(testIN2);
Serial.print(signal);
//delay(50);
resistance++;
}

Thanks!

You really should have read How to use this forum before posting. (Especially item #7.)

ie Your code and any error messages should always be placed between [code]code tags[/code]. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis, and often also corrupts the code with italics or smilies.

It's still not too late to edit your post and do this. You'll make potential helpers much happier. :slight_smile:


Was there a question?
According to your description, it's doing exactly what you want.
I just got it. :slight_smile: (And Paul just answered it.)

And do you mean 50Ω to 0Ω or 50KΩ to 0Ω?
You say it's a 50KΩ digital pot, then only mention 50Ω in the rest of the post.

Im trying to get a resistance (50kΩ digital potentiometer) switching in 255 steps from about 50Ω to about 0Ω and then back to 50Ω and so on..... (....5,4,3,2,1,0 ,1,2,3,4,5...50,49,48....)

Actually the resistance is switching in 255 steps from 50Ω to 0Ω, then its starting at 50Ω again. (50,49....5,4,3,2,1,0 ,50,49,48....).

The code you wrote increments resistance by one each time through loop(), resetting it to 0 when it gets to 255.

If you want different behavior, you need to write different code.

Here's a hint. Instead of always adding +1, you might want to add -1 under some circumstances.

Thanks for the answer.

I already know that @PaulS, but i tried several things and either nothing changed or I didnt even get a resistance from the digital potentiometer.

Im working with Arduino and the coding for about 2 weeks, I still have to learn the basics.

but i tried several things

None of which you have shown us.

and either nothing changed or I didnt even get a resistance from the digital potentiometer.

Bummer.

You need to post one of the things you tried, and explain what it actually does and what you expected. Then, we can explain why it does not do what you expect, and maybe suggest how to fix it.