ADXL193 Accelerometer Assistance Needed!

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.

Here are the errors:

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

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, Punch Acceleration Sensor – Part 1 | ABieneman's Blog 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.

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.

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.

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)

Yea, that's meant for the Processing environment.

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

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:

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:

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

That code is for Processing, not the Arduino.

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?

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.

PaulS:
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.

Ok, thanks for clearing that up. My project is to design and construct a new take on a folding Cycling helmet. Testing the impact resistance is one on many factors. I guess paying for code is like paying for a 3D printed part for a concept though - which is fine.

Thanks

Hello,

I have a 3rd year Product Design University project that requires the use of a 250g accelerometer for helmet testing.

I have the following kit:
Arduino UNO board
ADXL193 Accelerometer
Breadboard
Jumpers

I need a code and any other supporting scripts to allow me to visually see the G-force the accelerometer is subjected to.

I am open to payment suggestions and I will pay via Paypal.

I look forward to hearing from you!

Thanks
Mike

Try this code out - it constantly checks for minimum and maximum recoil.
But it only displays once every second. The more you display the smaller your sample rate becomes.
If the sample rate is too slow, you will miss the recoil event.

/* 
 Recoil Viewer designed by AB9VH Electronics, James Douglas III - 2012
 Sparkfun ADXL193 single axis accelerometer, 5v reference
 
 X axis analog pin 0
 Ground, black wire
 +5v, red wire  (Vin: voltage input 5v)
 
 ZERO G = 508  (calibration data)
 */

int X = 0;                          // fresh data from accelerometer
int Xmax = 508;                     // maximim recoil data
int Xmin = 508;                     // minimum recoil data
int R = 0;                          // recoil reading in g force
unsigned long time = 0;             // time in millis of recoil event

void setup() {
  Serial.begin(9600);            // opens serial port for LCD shield
  Serial.println("Recoil Viewer by AB9VH Electronics");
  Serial.println();
  time = millis();               // time of recoil event
}

void loop() {
  X = analogRead(0);             // read analog input
  if (X < Xmin) Xmin = X; 
  if (X > Xmax) Xmax = X;
  if (millis()-time >= 1000) {      // display every one second
    time = millis();               // time of recoil event  
    R = (Xmin-508)*.5;              // calculate maximum recoil
    Serial.print("Min recoil = ");
    Serial.print(R);
    Serial.print("g     ");
    R = (Xmax-508)*.5;              // calculate minimum recoil
    Serial.print("Max recoil = ");
    Serial.print(R);
    Serial.println("g");
  }
}

I was not aware I crossposted, to be honest. This thread is asking for code for payment. This section of the forum was suggested to me by another forum user - I did not ask for a new code in that thread, as far as I'm concerned, I got my answer out of that thread.

If it needs to be merged, so be it, I had no intension of violating any forum rules. It’s the last thing I want to do in my time of need.

Threads merged.

  • moderator

This is the third thread I've found on this subject. I hope there aren't too many more.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator

JD3:
Try this code out - it constantly checks for minimum and maximum recoil.
But it only displays once every second. The more you display the smaller your sample rate becomes.
If the sample rate is too slow, you will miss the recoil event.

Excellent, thank-you! It works! Well, as far as I know, I need to test this on a real on the market helmet to know for sure. I will let you know.

Where did you find the code? My only issue is it displays/scrolls just the maximum achieved G-load in the session, it doesn't reset to zero. Is there anyway of doing this? I would like to enter the results on to a chart at the desired intervals you see.

Oh, and Moderator, I am sorry that I appeared to be cross-posting. I thought I was OK because each thread was a different query i.e one was asking for coding help, one for basic what pin when help and the last was asking for paid assistance. But I can see how it could be seen/classified as cross-posting.

I wrote the sketch for detecting recoil with ADXL193. I have used it with several projects.

Here is the original version that I had modified and posted earlier.
I wasn't sure what you were doing or needed to display.

/* 
 Recoil Viewer designed by AB9VH Electronics James Douglas III - 2012
 Sparkfun ADXL193 single axis accelerometer, 5v reference
 
 X axis analog pin 0
 
 ZERO G = 508  (calibrated data)
 */

int X = 0;                          // fresh data from accelerometer
int Xmax = 508;                     // max raw data, opposite of gravity
int Rmax = 0;                       // max recoil reading in g force
unsigned long time = 0;             // time in millis of recoil event
boolean lcd = false;                // okay to display info

void setup() {
  Serial.begin(9600);            // opens serial port for LCD shield
  Serial.println("Recoil Viewer by AB9VH Electronics");
  Serial.println();
  time = millis();               // time of recoil event
}

void loop() {
  X = analogRead(0);          // read analog input
  if (X > Xmax) {             // recoil event is opposite of gravity
    Xmax = X; 
    time = millis();          
    lcd = true;
  }
  if ((lcd == true) && (millis()-time >= 1000)) {    // display 1 second after recoil
    Rmax = (508-Xmax)*.5;                // calculate max recoil
    Serial.print(Rmax);
    Serial.print("g   ");
    lcd = false;
  }
  if (millis()-time >= 4000) Xmax = 508;  // reset max recoil after 4 seconds
}