LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

external reference arduino

Hi guys,

I'm using Arduino with LabVIEW (LIFA). But I have some problems, I'd like to convert this sketch in LabVIEW:

int XPin = A0; // X
int YPin = A1; // Y
int ZPin = A2; // Z

void setup() {
  Serial.begin(9600);
  analogReference(EXTERNAL);
  Serial.println("Setup ADXL377Z"); 
} 

void loop() { 
  int xAccel;
  int yAccel;
  int zAccel;
  
  Serial.print("X: ");
  int x=analogRead(XPin);
  Serial.print( x );
  Serial.print(" Y: ");
  int y=analogRead(YPin);
  Serial.print( y );
  Serial.print(" Z: ");
  int z=analogRead(ZPin);
  Serial.print( z );
  Serial.print("\n");
  
  if(x >= 513){
    xAccel = map(x, 513, 1023, 0, 200);
  } else {
    xAccel = map(x, 0, 513, -200, 0);
    }
  if(y >= 511){
    yAccel = map(y, 511, 1023, 0, 200);
  } else {
    yAccel = map(y, 0, 511, -200, 0);
    }
  if(z >= 515){
    zAccel = map(z, 515, 1023, -1, -200);
  } else {
    zAccel = map(z, 0, 515, 200, -1);
    }
  
  Serial.print(xAccel);
  Serial.print("G, ");
  Serial.print(yAccel);
  Serial.print("G, ");
  Serial.print(zAccel);
  Serial.println("G");

  delay(1000);
}

But I don't know how I can set the external reference and how I can implement the "map" comand.

Do you have some advices?

 

Thanks

0 Kudos
Message 1 of 10
(4,990 Views)

I'm not sure what the purpose of the external reference is but LIFA can just read an analog.  You also may want to consider using LINX since LIFA is getting a bit dated and hasn't been updated recently.

 

As for your scale range checkout the VI in vi.lib

 

vi.lib\Utility\Range And Ratio.llb\Scale Value to New Range.vi

 

I think this is the same function where it will remap a value to a new range.

0 Kudos
Message 2 of 10
(4,943 Views)

Hi,

try to have a look at LabVIEW interface for Arduino.

Regarding "map" function, you can try to use LabVIEW Express VI Scaling and Mapping.

I hope it helps!

Bye,

 

Licia

0 Kudos
Message 3 of 10
(4,936 Views)
For the reference, you would have to modify the sketch to read a command sent by the LabVIEW program that sends the type of reference you want.
0 Kudos
Message 4 of 10
(4,934 Views)

Hi thanks,

I've used Linx and now it works very well Smiley Wink

0 Kudos
Message 5 of 10
(4,924 Views)

I don't remember off-hand whether LINX or LIFA supports setting the analog reference mode, but if not, all you need to do is to customize the firmware slightly, by placing that 

  analogReference(EXTERNAL);

command in the setup() function of the firmware. You'll need to duplicate the firmware file first (for LINX, the files live in Arduino/Libraries/LINX/<board name>/<board name.ino>). Make the one change to the function, and then upload the revised firmware to your board.

 

If you anticipate changing reference modes in runtime, LINX supports custom commands, and it would be pretty straightforwad to write one that recieves a byte from LV, parses that byte, and sets the reference mode accordingly. 

0 Kudos
Message 6 of 10
(4,917 Views)

@dmsilev wrote:

I don't remember off-hand whether LINX or LIFA supports setting the analog reference mode,  


LIFA does not, I don't have LINX installed at the moment but I doubt it has it.  Might be a good feature request if this is a common thing.

0 Kudos
Message 7 of 10
(4,904 Views)

I went and checked; LINX does come with a routine for changing the reference mode (and reference voltage value). So, the solution is just use LINX and use the built-in function. 

Message 8 of 10
(4,887 Views)

Could you define how you solved the problem?
I have the same problem, but I can't find the solution somehow!
Thanks in advance!

0 Kudos
Message 9 of 10
(1,568 Views)