Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Sensors / Re: Library for accelerometer functions
|
on: April 20, 2011, 07:08:41 pm
|
|
Hello every1! its been long.Below is the code.It gives an error of about 10 degrees with real life investigation.NOW I AM TRYING TO STORE AND READ THIS FROM THE BUILT-IN EEPROMOF THE ARDUINO. I AM HAVING TROUBLE WITH 10Bit to 8 bit conversion. I understand that I will have to divide it by '4' according to the example given with arduino0022. But I cant read the values in 10 bit format smiley-sad.Pleae shout out if any1 can help. /*
The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc .
*/
// these constants describe the pins. They won't change: const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage double xpin = A1; // x-axis of the accelerometer double ypin = A2; // y-axis double zpin = A3; // z-axis (only on 3-axis models) const float arduino_power_supply = 5; const float sensor_power_supply = 5; const float zero_g_bias = sensor_power_supply / 2; void setup() { // initialize the serial communications: Serial.begin(9600); // Provide ground and power by using the analog inputs as normal // digital pins. This makes it possible to directly connect the // breakout board to the Arduino. If you use the normal 5V and // GND pins on the Arduino, you can remove these lines. pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH); }
void loop() { // print the sensor values: float voltage_x = (analogRead(xpin)) * arduino_power_supply / 1024; float x = (voltage_x - zero_g_bias) * 1000 / 330; float Aa = (analogRead(xpin)); float Bb =(analogRead(xpin)-503); float Cc =(Bb/150); float Dd =(tan(Cc)*x); float xangle=((Dd)*(180/PI)); Serial.print(xangle); // print a tab between values: Serial.print("\t"); float voltage_y = (analogRead(ypin)) * arduino_power_supply / 1024; float y = (voltage_y - zero_g_bias) * 1000 / 330; double A=(analogRead(ypin)); double B=(A-509); double C=((B/-154)); double D=(tan(C)); double E=(((D)*(180/PI))*y); Serial.print(E); // print a tab between values: Serial.print("\t"); float voltage_z = (analogRead(zpin)) * arduino_power_supply / 1024; float z = (voltage_z - zero_g_bias) * 1000 / 330; float Aaa = (analogRead(zpin)); float Bbb =(analogRead(zpin)-580); float Ccc =(Bbb/190); float Ddd =(tan(Ccc)*2); float zangle=((Ddd)*(180/PI)*z);
Serial.print(zangle);; Serial.print("\t"); delay(100); Serial.print("\t"); Serial.print(Aa); Serial.print("\t"); Serial.print(A); Serial.print("\t"); Serial.print(Aaa); Serial.print("\t"); Serial.print("\t");
Serial.print(x); Serial.print ("\t");
Serial.print(y); Serial.print ("\t");
Serial.print(z); Serial.println(); // delay before next reading: delay(500); }
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: lilypad arduino and lilypad adxl335 accelerometer measurement of a true angle.
|
on: March 24, 2011, 07:28:37 pm
|
|
int pwrPin=18; // not initialized in case not used int gndPin=19; // " int xPin=A1; // variable to set x pin int yPin=A2; // y pin int zPin=A3; // z pin // self test pin, build does not use
long x, y, z; // hold raw x,y,z reading from sensor int xAngle, yAngle, zAngle; // hold angle conversions const int samples = 10; // number of samples for error int readingX[samples]; // array of x samples int readingY[samples]; // y int readingZ[samples]; // z int neutral = 3; // variable that will hold the deadspace for quadrants int sensorMax = 470; // holds specification for max sensor range int sensorMin = 550; // holds specification for min sensor range
// not sure if this will work because the pwrPin and gndPin were not initialized and since this // only runs once........ void setup() { Serial.begin(9600); pinMode(pwrPin, OUTPUT); digitalWrite(pwrPin, HIGH); pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW); }
void loop(){ // read in (x) samples into the array for (int i=0; i<samples; i++){ readingX = analogRead(xPin); readingY = analogRead(yPin); readingZ = analogRead(zPin); } // sum up all the array for averaging for (int i=0; i<samples; i++){ x = x + readingX; y = y + readingY; z = z + readingZ; } // spit out the averages x = x/samples; y = y/samples; z = z/samples; } // returns the quadrant that the accelerometer is indicating, quadrants start in top right and go counter clockwise int getTiltQuadrant(){ if(x>=neutral && y>=neutral)return 1; if(x>-neutral && x<neutral && y>neutral)return 2; if(x<=neutral && y>=neutral)return 3; if(x<=-neutral && y>-neutral && y<neutral) return 4; if(x<-neutral && y<=-neutral) return 5; if(x>-neutral && x<neutral && y<-neutral) return 6; if(x>=neutral && y<=neutral) return 7; if(x>=neutral && y>-neutral && y<neutral) return 8; }
int getQuadrantTiltAngle(){ if (x>0 && y>0) return atan(x/y); if (x>0 && y<0) return atan((x/y)+180); if (x<0 && y<0) return atan((x/y)+180); if (x<0 && y>0) return atan((x/y)+360); } // get the angle of the x in relation to plane int getXAngle(){ xAngle = map(x, sensorMin, sensorMax, -90, 90); Serial.print(xAngle); return xAngle;
} // y axis int getYAngle(){ yAngle = map(y, sensorMin, sensorMax, -90, 90); Serial.print(yAngle); return yAngle; } // z axis int getZAngle(){ zAngle = map(z, 662, 355, -90, 90); Serial.print(zAngle); return zAngle; } // setters and getters section int getX(){ return x; }
int getY(){ return y; }
int getZ(){ return z; }
void setXPin(int pin){ xPin = 3; }
void setYPin(int pin){ yPin = 2; }
void setZPin(int pin){ zPin = 1; }
void setPwrPin(int pin){ pwrPin = 18; }
void setGndPin(int pin){ gndPin =19; }
void setNeutral(int neutral){ neutral = neutral; }
void setSensorMax(int maxS){ sensorMax = maxS; }
void setSenorMin(int minS){ sensorMin = minS; }
// print the sensor values:
|
|
|
|
|
7
|
Using Arduino / Programming Questions / lilypad arduino and lilypad adxl335 accelerometer measurement of a true angle.
|
on: March 24, 2011, 05:24:07 pm
|
Hello every1!!  This is my first ever post and I am an absolute newbee to arduino...I am trying to measure true angles of the 'x' 'y' and 'z' axis at the moment what I get is only 'g' values I am a bit confused about the coding.I dont know how to convert this values to get the angle values display by the serial monitor.Would anyone please care to assist me with this. I will be ever so helpful for your help.. Cheers 
|
|
|
|
|