digipot-read-wiper

xodballxod/digipot-mcp-spi/digipot-read-wiper

Read the steps from digipot wiper Pot2 -> true for reading the 2nd wiper.
digipot-read-wiper
@/digipot-read-wiper
Read the steps from digipot wiper Pot2 -> true for reading the 2nd wiper.
SPI@/spi
SPI class reference
CSport
CS (chip select) pin, can be any digital pin, to allow multiple devices.
Pot2boolean
False -> Wiper 0 True -> Wiper 1 (for devices with 2 wipers)
UPDpulse
Read the Wiper
digipot-read-wiper
OUT
SPI
CS
Pot2
UPD
DONE
OUTnumber
DONEpulse
To use the node in your project you should have the xodballxod/digipot-mcp-spi library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

// used for MicroChip Technology MCP413X/415X/423X/425X SPI controlled digitial potentiometers and rheostats
// Reference for Wiring: http://www.learningaboutelectronics.com/Articles/MCP4131-digital-potentiometer-circuit.php

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
#pragma XOD error_raise enable


node {


    void evaluate(Context ctx) {

    if (!isInputDirty<input_UPD>(ctx))
        return;
  
    static_assert(isValidDigitalPort(constant_input_CS), "must be a valid digital port");
    ::pinMode(constant_input_CS, OUTPUT); // set pinmode output for Chip Select

    auto digipot = getValue<input_SPI>(ctx);
  
        
    ::digitalWrite(constant_input_CS, false); // chip select active
     uint16_t address = getValue<input_Pot2>(ctx) << 12;
     uint16_t command = ( (uint16_t) 0b0011 ) << 10;
    // uint16_t COMMAND_MASK = 0;
    // uint16_t transferByte =  0;
         
    // digipot->transfer((uint8_t) getValue<input_Address>(ctx)); // address
    //digipot->transfer16( address  | (uint16_t) getValue<input_STEP>(ctx)); // value
    //uint16_t data = digipot->transfer16( 0b0001110000000000 );  // value

    uint8_t data = digipot->transfer16( address | command );  // value
        
    ::digitalWrite(constant_input_CS, true); // chip select unactive
    emitValue<output_OUT>(ctx,  data )  ;
    emitValue<output_DONE>(ctx, 1);
    }
    
}