SPI digital potentiometers

Hi,

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 :
http://arduino.cc/en/Reference/SPI
datasheet of my digipot
http://www.analog.com/static/imported-files/data-sheets/AD5204-5206.pdf

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

sebastien

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

Hi,

Thanks for that quick and clear reply.

Do I have to mix this to send orders to Arduino
http://arduino.cc/en/Tutorial/SwitchCase2
and that to transmit orders to digipots via SPI
http://arduino.cc/en/Tutorial/SPIDigitalPot
?

Cheers

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);  
  SPI.begin();  
}  
  
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);  
    }  
  }  
}