Here is a library using this arduino library for the MCP4xxx series SPI digital potentiometer/rheostat, for example the MCP4131.
Be sure to read the description for the arduino library as not all chips in the series are supported. On some chips MISO, MOSI are multiplexed and need special wiring, this is explained well in the description for the arduino library.
Updates
v1.01
Fixed a problem that didn't allow you to use both potentiometers.
Be sure to read the description for the arduino library as not all chips in the series are supported. On some chips MISO, MOSI are multiplexed and need special wiring, this is explained well in the description for the arduino library.
B4X:
Sub Process_Globals
Public Serial1 As Serial
Public mcp As MCP4xxx 'testing for MCP4131
Public const total=9800 As UInt 'measured from term A to B
Public const wiperohms=110 As UInt 'measured from term A to wiper when wiper is at 0
Public ohminc=0 As UInt
End Sub
Private Sub AppStart
Serial1.Initialize(9600)
Log("AppStart")
'testing for MCP4131
mcp.Initialize(10,mcp.POT_0,mcp.RES7BIT,mcp.POTENTIOMETER)
Log("wiper range ",mcp.WiperRange)
ohminc=total/mcp.WiperRange
Log("increments of ",ohminc," ohms")
Log("wiper pos ",mcp.WiperGet)
Log("Is terminal A is connected? ",mcp.ConnTermA)
mcp.ConnTermASet(False)
Log("Is terminal A is connected? ",mcp.ConnTermA)
mcp.ConnTermASet(True)
Log("Is terminal A is connected? ",mcp.ConnTermA)
swing_wiper
End Sub
Sub swing_wiper
Do While True
For i = 0 To 127
mcp.WiperSet(i)
'mcp.WiperIncrement
Log("Set to: ",(mcp.WiperGet*ohminc)+wiperohms," ohms")
Delay(5000)
Next
Loop
End Sub
Updates
v1.01
Fixed a problem that didn't allow you to use both potentiometers.
Attachments
Last edited: