09-07-2015 10:22 AM
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
09-08-2015 07:56 AM
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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-08-2015 08:30 AM
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
09-08-2015 08:30 AM
09-08-2015 09:10 AM
Hi thanks,
I've used Linx and now it works very well
09-08-2015 09:29 AM
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.
09-08-2015 10:07 AM
@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.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
09-08-2015 02:44 PM
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.
01-13-2023 05:08 AM
Could you define how you solved the problem?
I have the same problem, but I can't find the solution somehow!
Thanks in advance!
01-13-2023 07:53 AM