SPI digital potentiometers


I’m seeking a way to control a digital potentiomer via my Arduino Card into an OF code. The digipots use SPI interface (kind of 3wires serial communciation).

Do I have to use standard output writing included into ofArduino class (in a loop threaded sending what i need trough pins of arduino ?

Arduino has SPI special library to control those igital potentiometers, can I use this in my OF code and how ?
Do I have to overwrite ofArduino class to include those SPI interfacing functions ?

Writing SPI functions for OF ? some exists ?
Do i really need arduino ? Can ofSerial be enough ?

All refs i found here :
datasheet of my digipot

Thanks in advance for helping about it, result will be great, and ofusers will be proud of OF as usual :slight_smile:


ofArduino relies on having firmata installed on your Arduino to handle reading/writing to all the pins, like a little operating system. Unfortunately firmata doesn’t support SPI right now, so if you want to control a component that communicates over SPI you’re better off just using ofSerial and sending a command to the Arduino that can then write the appropriate data over SPI to the component with something like this guy: http://arduino.cc/en/Tutorial/SPIDigitalPot


Thanks for that quick and clear reply.

Do I have to mix this to send orders to Arduino
and that to transmit orders to digipots via SPI


This is probably a discussion better suited for the Arduino forums, but something like this should be ok:

#include <SPI.h>  
const int selectPin = 10;  
void setup() {  
  pinMode (selectPin, OUTPUT);  
void loop() {  
  if (Serial.available() > 0) {  
    char cmd = Serial.read();  
    if (cmd == 'A') {  
      digitalWrite(selectPin, LOW);  
      SPI.transfer(0x20); // or whatever the address of the device of it  
      SPI.transfer(value); // what you want to transfer  
      digitalWrite(selectPin, HIGH);