I have an MCP4151 digital potentiometer chip. I have managed to get it to work using and Arduino Uno using the code below:
#include <SPI.h>
byte address = 0x00;
int CS= 5;
void setup()
{
pinMode (CS, OUTPUT);
SPI.begin();
}
void loop()
{
for (int i = 0; i <= 128; i++)
{
digitalPotWrite(i);
delay(10);
}
delay(500);
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);
}
But when I try to get it to work using an ESP32 programmed using Arduino language it doesn't. I have connected like that
- SCK -> 18
- MOSI -> 23
- SS -> 5
I also used the potentiometer inside like a voltage divider for test purposes. GND on one leg, 3.3v on the other and an LED on the wiper. Are there other settings that I have to implement in order the ESP32 SPI to work like an Arduino SPI? Did I miss something?