As the title says... Chat on...

User avatar
By etlaare
#61973 Good day to you all, I hope this is the right forum,

It looked straight forward, but somehow I seem to have missed something on getting the nodeMCU SPI to work with a digital potentiometer (MPC41100)
flashed the spi module,
using the HSPI pins, using a resistor to gnd on ChipSelect pin and the following code, but the wiper remains on it's default position.

Code: Select all-- Using HSPI to MCP41100 digital potentiometer

cs = 8
gpio.mode(cs, gpio.OUTPUT)

spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
gpio.write(cs,gpio.HIGH)

function setPot(R)
    gpio.write(cs,gpio.LOW)
    wrote = spi.send(1, 19, R)
    gpio.write(cs,gpio.HIGH)
end

setPot(64)


Any hint is very much appreciated :-)
User avatar
By devsaurus
#62023 Looks good so far.
You double checked clk and mosi wiring? Did you try with lower frequency than 10MHz? Can you observe whether the device changes resistance it not?
User avatar
By etlaare
#62054
devsaurus wrote:Looks good so far.
You double checked clk and mosi wiring? Did you try with lower frequency than 10MHz? Can you observe whether the device changes resistance it not?


thank you for your reply, I did double check all connections a couple of times now. According to the specifications of the digital potentiometer 10MHz should be easy to achieve, but I will try dividing the frequency some more tomorrow. I don't really need the high speed for this. And yes I can measure the resistance with my multi-meter, no changes, also set it up as a voltage divider, no difference in the voltage. I also connected a LED on the clk but it shows nothing. I assumed there should be some light at least after the setup. Or do I need to set a pwm signal on that pin myself maybe ? Should the clk be running constantly or only during a spi.send ?

I was hoping somebody would recognize something wrong in the code.
User avatar
By devsaurus
#62090 Sorry, missed that when I looked at the code first:

Move
Code: Select allgpio.mode(cs, gpio.OUTPUT)
after
Code: Select allspi.setup()
. The gpio output setting gets reverted at its current position and cs pin will toggle for each byte being sent and your manual cs toggling is not effective.