How do I control MCP41010 using ESP32

It is supposed to be a really simple task, but im running into an error:

E (23) gpio: GPIO can only be used as input mode

Here is the code I have used: (I am not even using GPIO 23, wtf is going on T_T)

#include <SPI.h>


const int CS_PIN = 35; // Chip Select pin
const int MOSI_PIN = 21; // Master Out Slave In
const int SCK_PIN = 18; // Clock pin
const int MISO_PIN = 19;
const int dummypin = 23;

//00010001 in hexadecimal this is taken from datasheet
#define CMD_WRITE 0x11

void setup() {
  
  SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
  pinMode(dummypin, INPUT);
  pinMode(CS_PIN, OUTPUT);

  // Set CS high 
  digitalWrite(CS_PIN, HIGH);
}

void loop() {
 
  setPotentiometerValue(0); // Value range is 0-255


}

// Function to set potentiometer value
void setPotentiometerValue(uint8_t value) {
  // Bring CS low to select the MCP41010
  digitalWrite(CS_PIN, LOW);

  
  SPI.transfer(CMD_WRITE); // Command byte
  SPI.transfer(value); // to set pot value

  // Bring CS high to send the data (ig)
  digitalWrite(CS_PIN, HIGH);
}

Where am I going wrong T_T, I am not even using GPIO23

Here is the datasheet: Single/Dual Digital Potentiometer with SPI Interface (microchip.com)

You can check the answers here about the error message you are seeing.

Is this upside down? Setting a pin after using it?

I think this is "error #23"... and has to do with other GPIO pins (reserved?)

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/gpio.html

ah shit thanks, i think i need to change that

thanks for the reply, will check that out

any particular reason not to use the default ESP32 VSPI pins?

MOSI: 23
MISO: 19
SCK: 18
SS: 5

I am already using those pins for something else and they are soldered inplace, i do not want to remove the soldering and rework again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.