我在弄乱Gy61板和Arduino ...经过一番尝试之后我想运行一个代码,以便能够从Arduino中获得g值。
Arduino通过板上的5v连接到adxl(将其转换为3.3v) 和轴到等效销 从地到地
Arduino的3.3v连接到Aref引脚,以使Arduino mega使用3.3v,以便获得能够线性计算g的比例输出
现在,我尝试使用触摸屏来设置gy61,该触摸屏也使用模拟引脚,但要在5V的基础上与库相结合...结果是触摸屏上的协调值由于模拟参考输入而被重新放置了。设置...所以我尝试将arduinoreference移至Analogreading部分,然后将其设置为默认值,但这并没有真正的帮助,因为Arduino现在可以正确返回值,但只能返回负值...无法计算超过+0.05 g的值
某人可以告诉我我的正面价值观去了哪里还是我现在计算错了?
我还尝试将Analogref(DEFAULT)移至程序中的各个点,但只有当Analogref(EXTERNAL)位于程序的设置部分时,它才能正常工作
const int xInput = A8;
const int yInput = A9;
const int zInput = A10;
float xAccel;
float yAccel;
float zAccel;
// initialize minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;
// Take multiple samples to reduce noise
const int sampleSize = 10;
void setup()
{
//analogReference(EXTERNAL); // I needed to comment this out in order to get the touchscreen to run
Serial.begin(9600);
}
void loop()
{
//Read raw values
int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);
// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);
// re-scale to fractional Gs
xAccel = (float)xScaled/1000.0,2;
yAccel = (float)yScaled/1000.0,2;
zAccel = (float)zScaled/1000.0,2;
Serial.print("X, Y, Z :: ");
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
Serial.print(" :: ");
Serial.print(xAccel,2);
Serial.print("G, ");
Serial.print(yAccel,2);
Serial.print("G, ");
Serial.print(zAccel,2);
Serial.println("G");
delay(200);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
analogReference(EXTERNAL);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
delay(10);
analogReference(DEFAULT);
}