LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

passing 16 bits binary to digital pin

Hi all,

Im trying to use arduino to control a DAC through labview. Using arduino only, I can generate the value I want on the DAC but when using Labview, I can read the Analog pin and create the 16 bits binary string needed. However I have been unable to push this binary 16 bits to the digital pin.

I can confirm that I can communicate R/W from Labview using the LVIFA file with serial below:

void setup()

  // Initialize Serial Port With The Default Baud Rate

  syncLV();

 

  // Place your custom setup code here

 

}

   

/*********************************************************************************

**  loop()

**

**  The main loop.  This loop runs continuously on the Arduino.  It

**  receives and processes serial commands from LabVIEW.

**

**  Input:  None

**  Output: None

*********************************************************************************/

void loop()

{  

  // Check for commands from LabVIEW and process them.  

  checkForCommand();

  // Place your custom loop code here (this may slow down communication with LabVIEW)

 

    if(acqMode==1)

  {

    sampleContinously();

  }

}

The labview so far working but cannot shift the 16 bits in the Digital pin 6.

DecToBin_n_to_DigitalPin.bmp

Any help to solve this problem will be appreciated.

Thanks

0 Kudos
Message 1 of 6
(5,371 Views)

You will have to show how you do this in Arduino code.

Also, you should switch to using LINX because LIFA is no longer officially supported.  LIFA Replacement - LINX Officially Released

0 Kudos
Message 2 of 6
(4,019 Views)

Arduino comes with code for working with shift registers.  Although you may not be using a shift register You can still use the shift register code.

An example of an Arduino shift register functions provided is;

shiftOut( DATA, CLK,  MSBFIRST, B10101010)

Where DATA is the data pin, CLK is the clock pin,

MSBFIRST means most significant bit first and

B10101010 is the data.

Using the shift register code you don't write code for shifting out the data one bit at a time. Instead you tell the function what data to send and let the function handle the sending of bits

If possible try to obtain access to Jermy Blum's "Exloring Arduino".  It has an excellent write up on using shift registers with Arduno. 

hrh1818

0 Kudos
Message 3 of 6
(4,020 Views)

My arduino working code directly without labview is:

--------------Start code  -----------------------

#include <SPI.h>

const int ldacPin = 3;

const int clrPin = 7;

const int uniPin = 8;

const int ssPin = 10;

//pin 11(MOSI) on Arduino connected to pin 2(DIN) on DAC

const int sclkPin = 13;

int command = 0b0100000000000000; // 0100  Load input and DAC registers from shift register; DAC output updated.

int commandPlusData;

void setup() {

  SPI.begin();

 

  pinMode(ssPin,OUTPUT);

  digitalWrite (ssPin, HIGH);

 

  pinMode(clrPin,OUTPUT);

  digitalWrite (clrPin, HIGH); //To clear DAC

   

  pinMode(ldacPin,OUTPUT);

  digitalWrite (ldacPin, HIGH);

 

  pinMode(uniPin,OUTPUT);

  digitalWrite(uniPin, HIGH); //Needed to set DAC to unipolar mode pin 8 on the dac

  

}

void loop() {

 

  for (int data=0b0000000000000000; data < 3891; data++){ //Increment upto data<xxxx

      commandPlusData = command | data;

  digitalWrite (ssPin, LOW); // pin 10 - initiate serial communication

  SPI.transfer (highByte (commandPlusData));

  SPI.transfer (lowByte (commandPlusData));

  digitalWrite (ssPin, HIGH);

  delay(10);

 

}

 

}

------------End code----------------

Also part that is not clear for me is if Im still using LVIFA (will look at LINX), do I have to:

- add the this arduino sketch as another file in the LVIFA ino?

- or add the sketch into the section that says put your programme here?

- or just load the standard LVIFA to the arduino and do everything else into labview?

Thanks

0 Kudos
Message 4 of 6
(4,020 Views)

hrh1818, I have this going already. But Im not grasping the practical way to using the labview with arduino through LVIFA.

The basic is ok, like reading and writing to a pin through the labview using the serial COM.

How do get to integrate my code above through labview?

Hope Im not confusing everyone with my confusion

Thanks

0 Kudos
Message 5 of 6
(4,020 Views)

If your device uses the SPI protocol, you simply use the SPI protocol provided by the API (you should use LINX).

Both LIFA and LINX make Arduino a slave device.  You can only run code via LabVIEW (or if you are more advanced, you can have the Arduino run other code but only if you build it into the LIFA/LINX architecture).  So, both LIFA and LINX give a a multifunction DAQ device.  You can use the functions provided by the API such as digital reading/writing, analog reading, I2C, SPI, PWM, etc.

0 Kudos
Message 6 of 6
(4,020 Views)