10-13-2017 09:08 PM
I wrote a code in Arduino, which is shown below. Now I want to enter “C f1 f2”, f1 and f2 being floating point numbers, the Arduino will calibrate the output. first value will be the calibration_zero and the second will be the calibration_factor. These values can be read into floating point variables using Serial.parseFloat() or I enter “S n1 n2” n1 and n2 being integers, the Arduino record n1 and n2 in variables no_measurements and period_measurement.
How to include this in code?
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;
const float supplyVoltage = 3.0;
int xReading = 0;
int yReading = 0;
int zReading = 0;
float xVoltage, yVoltage, zVoltage;
float cal_factor = 0.3;
float cal_zero_offset = 1.55;
float xG, yG, zG;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
analogReference(EXTERNAL);
}
void loop() {
// put your main code here, to run repeatedly:
int incoming;
if (Serial.available()>0)
{
incoming = Serial.read();
switch (incoming)
{
case 1:
Serial.parseFloat();
case 71:
readonce();
break;
defalut:
Serial.println("Command not recognized.");
}
}
readonce();
delay(100);
}
void readonce()
{
xReading = analogRead(xPin);
yReading = analogRead(yPin);
zReading = analogRead(zPin);
xVoltage = supplyVoltage*xReading/1024.;
yVoltage = supplyVoltage*yReading/1024.;
zVoltage = supplyVoltage*zReading/1024.;
xG = (xVoltage - cal_zero_offset)/cal_factor;
yG = (yVoltage - cal_zero_offset)/cal_factor;
zG = (zVoltage - cal_zero_offset)/cal_factor;
Serial.print("x: ");
Serial.print(xReading);
Serial.print("\ty: ");
Serial.print(yReading);
Serial.print("\tz: ");
Serial.println(zReading);
}
10-16-2017 09:08 AM
Hi Bufferlab,
This forum typically serves to answer questions about National Instruments products. For your question, maybe try the Arduino Forum!