Digital Potentiometer MCP41100 SPI

Can someone tell me how can I set the resistance of this pot?

I tried the code provided on the website : https://electricimp.com/docs/api/hardware/spi/configure/ but it doesn’t seems to be working for me. The resistance from A to the wiper is still at the midpoint. Also I would like to know how to connect it properly. I am using SPI 257 and Pin9 as the Chip select (CS).

Thank you very much in advance.

Looks like you forgot to link to the component?

Sorry about that ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf that is the link for the datasheet of potentiometer used. I tried to connect the CS to the Ground (Always Enable). But it doesn’t seem to work.

Usually SPI slaves need the nCS line to go low at the beginning of each command: the high-to-low transition marks the start of the command.

Peter

Usually SPI slaves need the nCS line to go low at the beginning of each command: the high-to-low transition marks the start of the command.

Peter

I did that but it doesn’t seem to be working. The resistance between Terminal A and the wiper is not changing.

`

CS ← hardware.pin9
CS.configure(DIGITAL_OUT_OD_PULLUP);
SPI ← hardware.spi257
SPI.configure(SIMPLEX_TX | MSB_FIRST | CLOCK_IDLE_LOW, 400);

function send()
{
CS.write(0);
local resistance = blob(1);
resistance.writen(0x01, ‘b’);
SPI.write(resistance);
CS.write(1);
}

send();

`

This is my code. Not sure if there is anything wrong with it.

I also checked the wave coming out of pin9(CS), pin5(CLK) and pin7(MOSI). But I got sine wave out of it. Should I not be getting square waves ?

The datasheet (tables 5-1 and 5-2) suggests that you need to write a command-byte followed by a data-byte.

Peter

So can you give me a brief idea what would the code looks like? Thank you very much.

eg:

SPI.write(format("\\x11%c", 100));

…writes (the first “1” in the \x11) to pot 0 (the second “1” in \x11 - pot 1 would be \x12), the value 100.

No need to create a blob for this.

Got it working. Thank you very much guys. Appreciated.