LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

LIFA and SPI for AD5206 DigPot

Solved!
Go to solution

Hi All,

I'm diving into LabView for the first time and hit a few bumps.

I want to convert the Arduino SPI tutorial (http://arduino.cc/en/Tutorial/SPIDigitalPot) to LabView but I'm not quite sure where to start.

I've read a lot of the posts on this discussion board and it has helped a lot on the other parts of my project (I have the LIFA stepper motor interface in LabView running just fine, thanks!), but I'm in the dark with where to start with SPI.

I'm using an Arduino Uno wired to an AD5206 digital potentiometer and I want to be able to make a control in LabView to change the wiper value.

Here is the code from the Arduino that I want to run in LabView -


#include <SPI.h>
const int slaveSelectPin = 10;

void setup() {

  pinMode (slaveSelectPin, OUTPUT);
  SPI.begin();
}

void loop() {
  digitalPotWrite(2, 200);
}

void digitalPotWrite(int address, int value) {

  digitalWrite(slaveSelectPin,LOW);

  SPI.transfer(address);
  SPI.transfer(value);

  digitalWrite(slaveSelectPin,HIGH);
}

Thanks for your help!

-Matt

Message 1 of 9
(9,614 Views)
Solution
Accepted by matt2008

Something like this should work:

0.PNG

Outside the loop initialize the SPI bus (you could add SPI configuration here too).

Inside the loop build a byte array containing two bytes, the address and value. 

Specifiy the chip select pin to use (to be safe you could set this as an output outside the loop as well)

The word size is the number of bytes to transfer between chip select toggles; in this case 2.

After the loop terminates close the SPI bus (not really necissary here but good practice).

Then close the connection to the Arduino

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker group on Google Plus.

0 Kudos
Message 2 of 9
(6,101 Views)

Thanks for such a quick response!

I'll give it a go later today. Thanks!

-Matt

0 Kudos
Message 3 of 9
(6,101 Views)

Works perfect. Thanks!

-Matt

0 Kudos
Message 4 of 9
(6,101 Views)

Matt,

Happy to help.  Did my explination make sense as to why it works?  Let us know if you have any more questions about this.

-Sam K

LabVIEW Hacker

Join / Follow the LabVIEW Hacker group on Google Plus.

0 Kudos
Message 5 of 9
(6,101 Views)

How would I use this to simutaniously control multiple dig pots? is there a way to connect two dig pots in series using labview?

0 Kudos
Message 6 of 9
(6,101 Views)

If it is an SPI device, you can connect as many as you want provided that you have enough digital pins to support it.  All of the devices share the same communication lines but each device needs its own "chip select" pin.  To find out more, you should search for how the SPI communication protocol works.

0 Kudos
Message 7 of 9
(6,101 Views)

Hi Nathan,


Thank you for the quick responds! and for taking the time out to help me.


So for the Mega 2526 ; MOSI 51,SCK 52, SS (chip select) 53/ANY DIGITAL


My question is how does LabView know when to write?


My understanding is digital write/MOSI goes low, writes to the digpot, then goes high again.


If I am trying to control multiple digpots how will it know that it needs to go low again?

0 Kudos
Message 8 of 9
(6,101 Views)

I don't know the SPI protocol very well but if you are using the subVI's provided by LIFA, you don't have to worry about any of the timing with the SPI lines.  The code on the Arduino does all of that.  You simply execute the "SPI Send Receive" function with the correct parameters (this assumes that you have the SPI bus configured correctly though).

So, to work with two SPI devices, you simply use two separate calls to the "SPI Send Receive"  function with different CS pins.

Also, if you didn't know already, it would be wise to consider switching from LIFA to LINX because LIFA is no longer officiall supported by the original author (who, conincidentally, is the author of it's replacement, LINX).  There should be minimal difference in how you use the SPI between the two intefaces.  See the official announcement here.

0 Kudos
Message 9 of 9
(6,101 Views)