I found from this link that with the 4151, you have to call transfer() twice, once with the value of 0 then with the value you that you want to set the level to. Apparently, the first call sets the channel to 0. This code works:
/////////////////////////////////
SPI1.setBitOrder(MSBFIRST);
SPI1.setClockSpeed(10,MHZ);
SPI1.setDataMode(SPI_MODE0);
SPI1.begin();
//select the POT device
digitalWrite(D5, LOW);
//set the channel
SPI1.transfer(0);
//set the POT level
SPI1.transfer(255);
//unselect the POT device
digitalWrite(D5, HIGH);
///////////////////////////////////////////
Now all I have to do is figure out how to convert a String to an int value, heh.
By the way, whenever I put a for loop with the loop() function, and flash, the Photon goes into green breathe mode.
[Edit: code correction per peekay… tested and works]
Any other way that I tried to configure the code with a function ended up with the Photon breathing green. This code works with the physical setup as shown above:
Thanks. I saw that and several others from the Arduino community. Maybe this stuff is just obvious to non-noobs, but there really was no reference for getting the Photon to talk to the 4151. The only think that I was missing was that I needed to call SPI.transfer() twice, which I found out from the link I posted above.
MCP41XX datasheet
The MCP 4151 has 257 steps to control the voltage.
In my case I need to control 5V from the Photon SPI. Use the D-side SPI interface pins. Note that the MCP4151 VDD and P0A pins are both connected to 5V. I am powering the Photon with 5V supply to the VIN.