Senior Design Project Help

chrisw1990

Joined Oct 22, 2011
551
yeh, i use microsofts calculator for conversions, open the calculator, click view, then programmer =] im off now, see what you can do, if you set the limits lower than you want, then you can prove the function by moving it about on your desk
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Here is my final code:

Rich (BB code):
// 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
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)
const int relay = 0;                  // Output for the relay

void loop()
{
  if(analogRead(xpin)>1101110111); 
  { do relay = 1 };
  else if(analogRead(xpin)<0010001001); 
  {do relay = 1 };
  else(relay = 0)
  if(analogRead(ypin)>1101110111);
  (do relay = 1);
  else if(analogRead(ypin)<0010001001);
  (do relay = 1);
  else(relay = 0)
  if (analogRead(zpin)>1101110111);
  (do relay = 1);
  else if(analogRead(zpin)<0010001001);
  (do relay = 1);
  else(relay = 0)
  // delay before next reading:
  delay(100);
  
}
And these are the list of errors that I get when I try to compile it:


ADXL3xx.cpp: In function 'void loop()':
ADXL3xx:23: error: assignment of read-only variable 'relay'
ADXL3xx:23: error: expected `;' before '}' token
ADXL3xx:23: error: expected `while' before '}' token
ADXL3xx:23: error: expected `(' before '}' token
ADXL3xx:23: error: expected primary-expression before '}' token
ADXL3xx:23: error: expected `)' before '}' token
ADXL3xx:23: error: expected `;' before '}' token
ADXL3xx:24: error: 'else' without a previous 'if'
ADXL3xx:25: error: assignment of read-only variable 'relay'
ADXL3xx:25: error: expected `;' before '}' token
ADXL3xx:25: error: expected `while' before '}' token
ADXL3xx:25: error: expected `(' before '}' token
ADXL3xx:25: error: expected primary-expression before '}' token
ADXL3xx:25: error: expected `)' before '}' token
ADXL3xx:25: error: expected `;' before '}' token
ADXL3xx:26: error: 'else' without a previous 'if'
ADXL3xx:26: error: assignment of read-only variable 'relay'
ADXL3xx:27: error: expected `;' before 'if'
ADXL3xx:28: error: expected primary-expression before 'do'
ADXL3xx:28: error: expected `)' before 'do'
ADXL3xx:29: error: 'else' without a previous 'if'
ADXL3xx:30: error: expected primary-expression before 'do'
ADXL3xx:30: error: expected `)' before 'do'
ADXL3xx:31: error: 'else' without a previous 'if'
ADXL3xx:31: error: assignment of read-only variable 'relay'
ADXL3xx:32: error: expected `;' before 'if'
ADXL3xx:33: error: expected primary-expression before 'do'
ADXL3xx:33: error: expected `)' before 'do'
ADXL3xx:34: error: 'else' without a previous 'if'
ADXL3xx:35: error: expected primary-expression before 'do'
ADXL3xx:35: error: expected `)' before 'do'
ADXL3xx:36: error: 'else' without a previous 'if'
ADXL3xx:36: error: assignment of read-only variable 'relay'
ADXL3xx:38: error: expected `;' before 'delay'

Any advice you can give me to get rid of all these?
 

chrisw1990

Joined Oct 22, 2011
551
ah yes,
Rich (BB code):
if(analogRead(xpin)>1101110111); 
  { do relay = 1 };
should be
Rich (BB code):
if(analogRead(xpin)>1101110111) 
  { do relay = 1; }
same problem for all lines, too many semicolons..
your "else" needs to use curly brackets {} in fact you need to use curly brackets in all.. i.e...
if()
{
relay=1;
}
and it doesnt know what relay is.. i assume your compiler is like mplab when i say try #define relay A0, at the moment its just 0...
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
I look at another digital output sample and after changing my code around came up with this

Rich (BB code):
/*
 
 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
const int xpin = A3;                  // x-axis of the accelerometer
const int ypin = A2;                  // y-axis
const int zpin = A1;                  // z-axis (only on 3-axis models)
const int relay = 2;                  // Output for the relay

void setup() {
  // initialize the LED pin as an output:
  pinMode(relay, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(xpin, INPUT);  
  pinMode(ypin, INPUT); 
  pinMode(zpin, INPUT);   
}

void loop()
{
  if(analogRead(xpin)>0001011110)
  { digitalWrite(relay, HIGH); }
  else if(analogRead(xpin)<0010100010)
  { digitalWrite(relay, HIGH); }
  else{digitalWrite(relay, LOW);}
  if(analogRead(ypin)>0001011110)
  { digitalWrite(relay, HIGH); }
  else if(analogRead(ypin)<0010100010)
  { digitalWrite(relay, HIGH); }
  else{digitalWrite(relay, LOW);}
  if (analogRead(zpin)>0001011110)
  { digitalWrite(relay, HIGH); }
  else if(analogRead(zpin)<0010100010)
  { digitalWrite(relay, HIGH); }
  else{digitalWrite(relay, LOW);}
  // delay before next reading:
  delay(100);
  
}
It compiles fine and doesn't throw any errors but i can move the accelerameter all over and smack in on my hand and nothing happens. Not real sure why that is
 

chrisw1990

Joined Oct 22, 2011
551
because.. 4g is ALOT.. to trigger 4g, thats.. 40m/s (4*g g=9.8m/s^2)
like i said, you might need to set it lower first, then set it up to your spec..
also, i dont know what you need to do to set it in 2, 4 6g modes?
<edit>
you need to set the microswitches.. set it to 4g, cos thats what we have been aiming for, thats 1 0 on the switches..
then adjust the values so you can have lower thresholds..
also, are you sure that relay is set to a port pin? i.e. an actual pin? no idea how you program an avr io port, but something to check
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
In the code that i just posted i changed the trigger to 1g to see if i could get it to work and that still didn't change a thing
 

chrisw1990

Joined Oct 22, 2011
551
In the code that i just posted i changed the trigger to 1g to see if i could get it to work and that still didn't change a thing
ok, i suggest a hardware check.. comment out your if statement,
have:
relay=1;
delay(1000);
relay=0;
delay(1000);

assuming delay can accept 1000. that should toggle the relay output, so turn it on and off..
=]
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
I think i may have found out what is going on. When i try to upload the program to the board it says upload complete and then throws the error code of:

avrdude: stk500_getsync(): not in sync: resp=0x00

I did a google search for the code and came up with some things to try. I'm going to try doing those and see if that helps at all
 

chrisw1990

Joined Oct 22, 2011
551
thats just because the io is probbaly high, try an oscilloscope?
did you comment out the if statement? and put that relay=0 code i mentioned earlier?
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Do you know how to remove programs that have been uploaded to the microcontroller. When i was installing the software for it the tutorial said to upload a blink program and for whatever reason that one worked and one of the leds keeps blinking regardless.
 

chrisw1990

Joined Oct 22, 2011
551
there should be an "erase" or erase flash button in the compiler/ide that your building your project in.. assuming it has identified the board is plugged in of course
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Yeah i put
Rich (BB code):
else{digitalWrite(relay, LOW);}
at the end of each if statement. I have the board hooked up to my usb drive of my laptop right now
 

chrisw1990

Joined Oct 22, 2011
551
no i mean, comment out the ifs, /* */ style, and just toggle the relay.. make sure the processor is controlling the io.. maybe i misunderstand whats going on here, think its bedtime!
 
Top