Pages: [1] 2   Go Down
Author Topic: ADXL193 Accelerometer Assistance Needed!  (Read 3795 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

A bit of a poor first post, asking for assistance and all.

A bit of background first. I am looking into the impact resistance qualities of some materials and constructions for a new cycling helmet idea for a University project. I plan to drop the helmet from varying heights with a 5kg head form with the accelerometer mounted and record the results as they come

I took the plunge and bought an UNO board, and an ADXL193 +/-250g accelerometer as well as a solder-less bread board and a lot of pins.

Now I find myself with a whole lot of bits and just as much inexperience. I have viewed the data sheet for the accelerometer but it does not look anything like the one I have in my hand.
http://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL193.pdf

And here is the accelerometer...
https://www.sparkfun.com/products/9332

I have a code I plan to use I just need to get it all together and in harmony.

So then, what pins go where? smiley-red

Any assistance will be greatly appreciated.

Thanks
Mike

Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would imagine that the code would yield some info.  Post the code.
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 3
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The datasheet is for the chip itself, won't explain how the board is set up.

VDD   (on the left) is 5 volts from the Arduino
GND   is the ground connection from the Arduino
ST      is for the self test function.  If 5v is applied to this you can test the accelerometer to see if it's working.  Do not connect for normal operation
OUT   is the output of the accelerometer.  Connect that to an analog pin on the Arduino.

Need help with the code just ask smiley
Logged

That little black caterpillar you just stepped on will set you back a few bucks....

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok folks, thanks for the help so far!

I will get that all wired up soon.

I have moved onto the code, you know, the one I already had and that wasn't going to be a problem. Well, now, it sort of is.

Code:
import processing.opengl.*;
import processing.serial.*;

Serial serial;
int WIDTH = 1440;
int analog_in = 0;
PFont font;

void setup(){
 size(WIDTH,900,OPENGL);
 textFont(font,20);
 textAIign(TOP,LEFT);
 serial = new Serial(this, SeriaI.Iist()[0], 115200);
 background(255);
 smooth();
}

int val = 0;

void draw() {
 background(255);
 fill(0);
 stroke(0);
 while (seriaI.available() > 0) {
  int c = seriaI.read();
  if (c >= '0' && c <= '9') {
   val = val * 10 + ((int)c - (int)’0’);
  } else if (c == ‘\n’){
   next(val);
   val = 0;
  }
 }


 text(“input: “ + anaIog_in,40,140);

 renderBuffer();
 text(“max-noise: “ + maxInBuffer(),340,90);
 text(“min-noise: “ + minInBuffer(),340,40);
 text(“initiaI min: “ + maxInBuffer2(),40,40);
 text(“initiaI max: “ + minInBuffer2(),40,90);

}
float minInBuffer() {
 float min = 99999;
 for (int i = 0; i < WIDTH; i++){
  if (min > buffer[i])
  min = buffer[i];
 }
 return min;
}
float maxInBuffer() {
 float max = 0;
 for (int i = 0; i < WIDTH; i++){
  if (max < buIfer[i])
  max = buffer[i];
 }
return max;
}
float minlnBuffer2() {
 float min = 99999;
 for (int i = 0; i < WIDTH; i++){
  if (min > buffer2[i])
  min = buffer2[i];
 }
 return min;
}

float maxlnBuffer2() {
 float max = 0;
 for (int i = 0; i < WIDTH; i++){
  if (max < buffer2[i])
  max = buffer2[i];
 }
 return max;
}

int index = O;
float bufter[] = new float[WlDTH];
float bufter2[] = new float[WlDTH];

float min = 509.0;
float max = 506.0;
float m = 2.0/(max - min);
float b = 1.0 - m * max;

void next(int val) {

  analog_in = val;
float acc = (analog_in - 508)/2;
 //println(val);
 if (pause)
  return;

 float gz = m * val + b;
 //float gz = 5.f*val*1000.f/(8.f*1024.f);
 buffer[index] = gz;
 buffer2[index] = acc;
 index = (index + 1) % WIDTH;
}

boolean pause = false;

void keyPressed(){
 if (key == ‘s’){
  saveFrame(“snapshot.png”);
  pause = true;
 }
 if (key == ‘p’ ll key == ‘ ‘){
  pause = !pause;
 }
}

void renderBuffer(){
 int in = WIDTH-1;
 float last = 0;
 for (int i = index; i < WIDTH; i++, in--){
  line(in,height/2+buffer[i],in+1,last);
  last = height/2+buffer[i];
 }
 for (int i = 0; i < index; i++, in--){
  line(in,height/2+buffer[i],in+1,last);
  last = height/2+buffer[i];
 }
}


When I try to upload the code to the board I get a large amout of errors. I do not have anything wired up by the way.

I found this code from a web page and I tried to use it because it is exactly what I am after and uses the same accelerometer.

Help please.

Thanks

Mike
« Last Edit: February 02, 2013, 03:43:54 am by MR_91 » Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also need the error messages you receive.  I did try to compile this, but got errors as well.  Where did you get this sketch from?  It seems that your copy and paste didn't work to well.

Also, please use code tags instead of quote.  It will keep the forum software from tearing your code apart.
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are the errors:

Code:
sketch_feb01b:27: error: stray '\' in program
sketch_feb01b:27: error: stray '\' in program
sketch_feb01b:28: error: stray '\' in program
sketch_feb01b:28: error: stray '\' in program
sketch_feb01b:28: error: stray '\' in program
sketch_feb01b:35: error: stray '\' in program
sketch_feb01b:35: error: stray '\' in program
sketch_feb01b:38: error: stray '\' in program
sketch_feb01b:38: error: stray '\' in program
sketch_feb01b:39: error: stray '\' in program
sketch_feb01b:39: error: stray '\' in program
sketch_feb01b:40: error: stray '\' in program
sketch_feb01b:40: error: stray '\' in program
sketch_feb01b:41: error: stray '\' in program
sketch_feb01b:41: error: stray '\' in program
sketch_feb01b:105: error: stray '\' in program
sketch_feb01b:105: error: stray '\' in program
sketch_feb01b:106: error: stray '\' in program
sketch_feb01b:106: error: stray '\' in program
sketch_feb01b:109: error: stray '\' in program
sketch_feb01b:109: error: stray '\' in program
sketch_feb01b:109: error: stray '\' in program
sketch_feb01b:109: error: stray '\' in program
sketch_feb01b:1: error: 'import' does not name a type
sketch_feb01b:2: error: 'import' does not name a type
sketch_feb01b:4: error: 'Serial' does not name a type
sketch_feb01b:7: error: 'PFont' does not name a type
sketch_feb01b.ino: In function 'void setup()':
sketch_feb01b:10: error: 'OPENGL' was not declared in this scope
sketch_feb01b:10: error: 'size' was not declared in this scope
sketch_feb01b:11: error: 'font' was not declared in this scope
sketch_feb01b:11: error: 'textFont' was not declared in this scope
sketch_feb01b:12: error: 'TOP' was not declared in this scope
sketch_feb01b:12: error: 'LEFT' was not declared in this scope
sketch_feb01b:12: error: 'textAIign' was not declared in this scope
sketch_feb01b:13: error: 'serial' was not declared in this scope
sketch_feb01b:13: error: expected type-specifier before 'Serial'
sketch_feb01b:13: error: expected `;' before 'Serial'
sketch_feb01b:14: error: 'background' was not declared in this scope
sketch_feb01b:15: error: 'smooth' was not declared in this scope
sketch_feb01b.ino: In function 'void draw()':
sketch_feb01b:21: error: 'background' was not declared in this scope
sketch_feb01b:22: error: 'fill' was not declared in this scope
sketch_feb01b:23: error: 'stroke' was not declared in this scope
sketch_feb01b:24: error: 'seriaI' was not declared in this scope
sketch_feb01b:27: error: 'u20190' was not declared in this scope
sketch_feb01b:27: error: expected `)' before 'u2019'
sketch_feb01b:28: error: 'u2018' was not declared in this scope
sketch_feb01b:28: error: expected `)' before 'n'
sketch_feb01b:35: error: 'u201cinput' was not declared in this scope
sketch_feb01b:35: error: 'text' was not declared in this scope
sketch_feb01b:38: error: 'u201cmax' was not declared in this scope
sketch_feb01b:38: error: 'noise' was not declared in this scope
sketch_feb01b:39: error: 'u201cmin' was not declared in this scope
sketch_feb01b:40: error: 'u201cinitiaI' was not declared in this scope
sketch_feb01b:41: error: expected `)' before 'max'
sketch_feb01b.ino: In function 'float minInBuffer()':
sketch_feb01b:47: error: 'buffer' was not declared in this scope
sketch_feb01b.ino: In function 'float maxInBuffer()':
sketch_feb01b:55: error: 'buIfer' was not declared in this scope
sketch_feb01b:56: error: 'buffer' was not declared in this scope
sketch_feb01b.ino: In function 'float minlnBuffer2()':
sketch_feb01b:63: error: 'buffer2' was not declared in this scope
sketch_feb01b.ino: In function 'float maxlnBuffer2()':
sketch_feb01b:72: error: 'buffer2' was not declared in this scope
sketch_feb01b.ino: At global scope:
sketch_feb01b:78: error: 'O' was not declared in this scope
sketch_feb01b:79: error: 'WlDTH' was not declared in this scope
sketch_feb01b:79: error: initializer fails to determine size of 'bufter'
sketch_feb01b:80: error: 'WlDTH' was not declared in this scope
sketch_feb01b:80: error: initializer fails to determine size of 'bufter2'
sketch_feb01b.ino: In function 'void next(int)':
sketch_feb01b:92: error: 'pause' was not declared in this scope
sketch_feb01b:97: error: 'buffer' was not declared in this scope
sketch_feb01b:98: error: 'buffer2' was not declared in this scope
sketch_feb01b.ino: In function 'void keyPressed()':
sketch_feb01b:105: error: 'key' was not declared in this scope
sketch_feb01b:105: error: 'u2018s' was not declared in this scope
sketch_feb01b:105: error: expected `)' before 'u2019'
sketch_feb01b:106: error: 'u201csnapshot' was not declared in this scope
sketch_feb01b:106: error: 'saveFrame' was not declared in this scope
sketch_feb01b:109: error: 'key' was not declared in this scope
sketch_feb01b:109: error: 'u2018p' was not declared in this scope
sketch_feb01b:109: error: expected `)' before 'u2019'
sketch_feb01b.ino: In function 'void renderBuffer()':
sketch_feb01b:118: error: 'height' was not declared in this scope
sketch_feb01b:118: error: 'buffer' was not declared in this scope
sketch_feb01b:118: error: 'line' was not declared in this scope
sketch_feb01b:122: error: 'height' was not declared in this scope
sketch_feb01b:122: error: 'buffer' was not declared in this scope
sketch_feb01b:122: error: 'line' was not declared in this scope

I got the code from a .pdf document of a report based on helmet testing. I had to run the .pdf doument through an OCR program to get the text. 

The only thing I can think is that there are background programs/requirements the previous code writer had on their PC? Or maybe the OCR program didn't do too good of a job. I'll have a pop at writing it all myself today and see where that gets me.

What's the general consensus of people writing code for other people and being paid in return, that is seriously where I am right now...

Thanks
« Last Edit: February 02, 2013, 03:53:49 am by MR_91 » Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you sure that code is for the Arduino?  It seems to be missing some of the code.  It does look like a copy error from your pdf.  You might want to delete all of the white spaces and use the reformat tool in the IDE.  Or use something like Notepad++ and re-type the code in a new file (Do not copy and paste).

I found this, http://abieneman.wordpress.com/2010/04/04/punch-acceleration-sensor/ maybe you can grab some info off the blog to make it work.  On the 3rd page it does have an explanation of the code given.
« Last Edit: February 02, 2013, 05:41:02 am by codlink » Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I assumed the code was Arduino. Maybe that is where I went wrong. Ardunio was defiantly used for the testing though. I know what you mean about it being incomplete though, I mean, it doesn’t include the void setup and void loop.

Just tried formatting it, no luck. I'll re type it in Notepad++ and give that a shot.

I had come across the punch sensor during my Internet trawl but they talk a lot about an analog converter and, to my knowledge (HA!) I don't need one.

Thanks for your help Codlink.
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It doesn't look like a code used with the Arduino.  If you want to link the pdf, I could take a look..

Also, you might want to try and use the AnalogInput examples in the IDE and see if you can get readings from the device.  Then, expand from there.
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I dont have the kit with me at the moment so I will try the Analoginput later.

Here is the page

* code 250g testing.pdf (54.2 KB - downloaded 33 times.)
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yea, that's meant for the Processing environment.

Let me know if the example works out.  Any problems, just post here.
Logged

//LiNK

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am I need of some assistance with some code I have found. I want to be able to measure the G-load of the deceleration of a helmet I designed with various materials and constructions built with-in it.

Currently I have in my possession: Arduino Uno Board; ADXL193 +/- 250g accelerometer; breadboard and jumper wires.

Here is the code:
Code:
import processing.opengl.*;
import processing.serial. *;
Serial serial;
int WIDTH = 1440;
int analog_in = 0;

PFont font;
void setup() {
size(WIDTH,900,0PENGL);
font= loadFont("Helvetica-Bold-20.vlw");
textFont(font, 20);
textAiign(TOP,LEFT);
serial =new Serial(this, Serial.list()[O], 115200);
background(255);
smooth();
}

int val = 0;
void draw(){
background(255);
fiii(O);
stroke(O);
while (serial.available() > 0) {
int c =serial.read();
if (c >= '0' && c <= '9') {
val =val  * 10 + ((int)c - (int)'O');
} else if (c == '\n') {
next(val);
val= 0;
}
}

text("input: "+ analog_in, 40,140);
renderBuffer();
text("max-noise: " + maxlnBuffer(), 340,90);
text("min-noise: "+ minlnBuffer(), 340, 40);
text("initial min: " + maxlnBuffer2(), 40,40);
text("initial max:"+ minlnBuffer2(), 40,90);
}
float minInBuffer() {
float min= 99999;
for (inti= 0; i <WIDTH;  i++) {
if (min> buffer[i])
min = buffer[i];
}
return min;
}

float maxlnBuffer() {
float max= 0;
for (inti= 0; i <WIDTH;  i++) {
if (max< buffer[i])
max = buffer[i];
}
return max;
}

float minlnBuffer2() {
float min = 99999;
for (inti = 0; i < WIDTH; i++) {
if (min > buffer2[i])
min = buffer2[i];
}

return min;
}
float maxlnBuffer2() {
float max = 0;

for (inti= 0; i <WIDTH; i++){
if (max< buffer2[i])
max = buffer2[i];
}
return max;
}

int index= 0;
float buffer[] =new float[ WIDTH];
float buffer2[] = new float[WIDTH];
float min = 509.0;
float max = 506.0;
float m = 2.0/(max-  min);
float b = 1.0 - m *max;

void next(int val) {

analog_in = val;
float ace=  (analog_in - 508)12;
//println(val);
if (pause)
return;
float gz = m *val + b;
//float gz = 5.f*val*1OOO.f/(8.f*1024.f);

buffer[index] = gz;
buffer2[index] = ace;
index= (index+ 1)% WIDTH;
}
boolean pause= false;

void keyPressed() { if (key == 's') { saveFrame("snapshot.png"); pause =true;
}
if (key == 'p' II key == ' ') {
pause = !pause;
}
}
void renderBuffer() {
int in = WIDTH-1;
float last= 0;
for (inti= index; i <WIDTH; i++, in--) {
line(in,heightl2+buffer[i],in+1 ,last);
last = heightl2+buffer[i];
}
for (inti = 0; i <index; i++, in--) {
line(in,heightl2+buff er[i],in+1 ,last);
last = heightl2+buffer[i];
}
}

Now, with this code the writter used the same equippment as me and managed to get usuable results from the code. I, cannot. The code is riddled with errors:
Code:
sketch_feb02a.ino:9:16: error: invalid suffix "PENGL" on integer constant
sketch_feb02a:1: error: 'import' does not name a type
sketch_feb02a:2: error: 'import' does not name a type
sketch_feb02a:3: error: 'Serial' does not name a type
sketch_feb02a:7: error: 'PFont' does not name a type
sketch_feb02a.ino: In function 'void setup()':
sketch_feb02a:9: error: 'size' was not declared in this scope
sketch_feb02a:10: error: 'font' was not declared in this scope
sketch_feb02a:10: error: 'loadFont' was not declared in this scope
sketch_feb02a:11: error: 'textFont' was not declared in this scope
sketch_feb02a:12: error: 'TOP' was not declared in this scope
sketch_feb02a:12: error: 'LEFT' was not declared in this scope
sketch_feb02a:12: error: 'textAiign' was not declared in this scope
sketch_feb02a:13: error: 'serial' was not declared in this scope
sketch_feb02a:13: error: expected type-specifier before 'Serial'
sketch_feb02a:13: error: expected `;' before 'Serial'
sketch_feb02a:14: error: 'background' was not declared in this scope
sketch_feb02a:15: error: 'smooth' was not declared in this scope
sketch_feb02a.ino: In function 'void draw()':
sketch_feb02a:20: error: 'background' was not declared in this scope
sketch_feb02a:21: error: 'O' was not declared in this scope
sketch_feb02a:21: error: 'fiii' was not declared in this scope
sketch_feb02a:22: error: 'stroke' was not declared in this scope
sketch_feb02a:23: error: 'serial' was not declared in this scope
sketch_feb02a:33: error: 'text' was not declared in this scope
sketch_feb02a:35: error: invalid operands of types 'const char [12]' and 'float' to binary 'operator+'
sketch_feb02a:36: error: 'minlnBuffer' was not declared in this scope
sketch_feb02a:37: error: invalid operands of types 'const char [14]' and 'float' to binary 'operator+'
sketch_feb02a:38: error: invalid operands of types 'const char [13]' and 'float' to binary 'operator+'
sketch_feb02a.ino: In function 'float minInBuffer()':
sketch_feb02a:42: error: 'inti' was not declared in this scope
sketch_feb02a:42: error: 'i' was not declared in this scope
sketch_feb02a:43: error: 'buffer' was not declared in this scope
sketch_feb02a.ino: In function 'float maxlnBuffer()':
sketch_feb02a:51: error: 'inti' was not declared in this scope
sketch_feb02a:51: error: 'i' was not declared in this scope
sketch_feb02a:52: error: 'buffer' was not declared in this scope
sketch_feb02a.ino: In function 'float minlnBuffer2()':
sketch_feb02a:60: error: 'inti' was not declared in this scope
sketch_feb02a:60: error: 'i' was not declared in this scope
sketch_feb02a:61: error: 'buffer2' was not declared in this scope
sketch_feb02a.ino: In function 'float maxlnBuffer2()':
sketch_feb02a:70: error: 'inti' was not declared in this scope
sketch_feb02a:70: error: 'i' was not declared in this scope
sketch_feb02a:71: error: 'buffer2' was not declared in this scope
sketch_feb02a.ino: At global scope:
sketch_feb02a:78: error: initializer fails to determine size of 'buffer'
sketch_feb02a:79: error: initializer fails to determine size of 'buffer2'
sketch_feb02a.ino: In function 'void next(int)':
sketch_feb02a:88: error: expected ',' or ';' before numeric constant
sketch_feb02a:90: error: 'pause' was not declared in this scope
sketch_feb02a.ino: In function 'void keyPressed()':
sketch_feb02a:101: error: 'key' was not declared in this scope
sketch_feb02a:101: error: 'saveFrame' was not declared in this scope
sketch_feb02a:103: error: 'key' was not declared in this scope
sketch_feb02a:103: error: expected `)' before 'II'
sketch_feb02a.ino: In function 'void renderBuffer()':
sketch_feb02a:110: error: 'inti' was not declared in this scope
sketch_feb02a:110: error: 'i' was not declared in this scope
sketch_feb02a:111: error: 'heightl2' was not declared in this scope
sketch_feb02a:111: error: 'line' was not declared in this scope
sketch_feb02a:114: error: 'i' was not declared in this scope
sketch_feb02a:115: error: 'heightl2' was not declared in this scope
sketch_feb02a:115: error: 'buff' was not declared in this scope
sketch_feb02a:115: error: 'line' was not declared in this scope

Along with "import does not have a name type" in an orange box.

Ultimately, I want the code to interpret the results from the accelerometer and display them to me on a graph so I can draw some conclusions.

Goes without saying really, your help is very much appreciated.

Thanks
Mike


Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That code is for Processing, not the Arduino.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Oh, wow, that explains a lot. Thanks.

Due to the fact it’s my 3rd year final I do not have the time to learn the correct coding, what’s the attitude towards people writing code for monetary payment?

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49074
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what’s the attitude towards people writing code for monetary payment?
That depends on what the project is for. If the project to read the accelerometer IS part of your course work, then paying someone else to write the code is cheating, and we don't support that.

If the project to read the accelerometer data is a personal project that has nothing to do with school then post in Gigs and Collaboration to hire someone.
Logged

Pages: [1] 2   Go Up
Jump to: