Senior Design Project Help

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Yes the leds flashed this time and the program that was on the board which made the led in pin 13 flash is no longer flashing
 

hgmjr

Joined Jan 28, 2005
9,027
All that is needed now is to get your code straightened out. Chrisw1990 will probably be able to take it from here.

I still think you need to put together a schematic of your circuit. It is the best way for engineers to communicate with each other.

hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
As of right now i have the board being powered by the COM cable. The accelerometer is receiving just under 5V constant. The output side is around 1.5V when the accelerometer is resting and moves +/- .2V when i wave it around.

I'm wondering if I have the inputs and outputs set up correctly. I never received a diagram saying which ports are which and how they should be labeled in the program. Here is a picture of how I have everything plugged in at the moment.

http://www.flickr.com/photos/79051833@N03/7078543529/
 

hgmjr

Joined Jan 28, 2005
9,027
I am going to need a bit of time to look over what your code looks like. It is getting late here so I will check back with you tomorrow. Maybe you and Chrisw1990 can get your problem sorted. I will see where things stand in 8 hours or so.

Good Luck,
hgmjr
 

chrisw1990

Joined Oct 22, 2011
551
hello, im back.. right, sounds like your having a problem with the in/out? i.e. controlling the relay?
how about.. just an idea.. getting your program to control the led on the board?
you can look at/copy the code from the demo application that was loaded onto the device, im sure you can get the code to look at, and therefore, without using the relay, you can turn the led on and off, when it triggers.. then its a matter of changing the output pin for the relay?
im also looking at the datasheet for your board here:
Power from USB:
Simply plug USB cable, and the Romeo is able to work. Please notice that the
USB can only supply 500 mA current. It should be able to meet the most
requirements for LED lit application. However it is not enough to power DC
motors or servo.
i wonder if you need an external power source? i know its only a relay, but i cant find the required current for the relay to make it switch.. maybe worth looking at

right, had a look at the sample code from the website of that board..
try using this code:
youll need to copy "pinMode..." and put that into your own setup()
and for all your if statements, turning the relay on or off.. youll need to replace with
DigitalWrite(...,HIGH) or LOW depending on your desired output
Rich (BB code):
int relayPin = 10;

void setup()
{
pinMode(relayPin, OUTPUT); // Set Pin10 to output mode
}
and then.. when assigning the value to relay (turning it on or off.. use:
Rich (BB code):
digitalWrite(relayPin, HIGH);
that should set it high/low.. iv set the relay pin to 10, just so its not near anything else... though your welcome to change it =]
 
Last edited:

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Helllo Chrisw1990 so i tried replacing the output with an led instead of the relay and found something interesting. The led always is on and never turns off. Last night I adjusted my high and low limit so they were only 10 over the middle point, but no matter what I do the led wont turn off. Here is an updated version of my code:

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 relaypin = 13;                  // Output for the relay

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

void loop()
{
  if(analogRead(xpin)>1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(xpin)<0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  if(analogRead(ypin)>1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(ypin)<0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  if (analogRead(zpin)>1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(zpin)<0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  // delay before next reading:
  delay(100);
  
}
 

hgmjr

Joined Jan 28, 2005
9,027
Helllo Chrisw1990 so i tried replacing the output with an led instead of the relay and found something interesting. The led always is on and never turns off. Last night I adjusted my high and low limit so they were only 10 over the middle point, but no matter what I do the led wont turn off. Here is an updated version of my code:

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 relaypin = 13;                  // Output for the relay
 
void setup() {
  // initialize the LED pin as an output:
  pinMode(relaypin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(xpin, INPUT);  
  pinMode(ypin, INPUT); 
  pinMode(zpin, INPUT);   
}
 
void loop()
{
  if(analogRead(xpin)>0B1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(xpin)<0B0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  if(analogRead(ypin)>0B1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(ypin)<0B0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  if (analogRead(zpin)>0B1000001010)
  { digitalWrite(relaypin, HIGH); }
  else if(analogRead(zpin)<0B0111110110)
  { digitalWrite(relaypin, HIGH); }
  else{digitalWrite(relaypin, LOW);}
  // delay before next reading:
  delay(100);
 
}
You need to add prefix "B" to all of your binary numbers to tell the compiler that they are binary radix.

hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Ok, So i think it has to do either with the binary or the the way it's reading in the analog inputs. I changed the binary back to the 4g range and the led is still on. I even put a line of code before the if statement to tell the led to start in the off position. I'm going to look at their sample code to see how they are reading the analog input in.
 

hgmjr

Joined Jan 28, 2005
9,027
Then there still must be a coding error. I will continue reviewing your code to see if I can spot the logic error.

hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Thank you, I just unplugged the accelerometer and the led never turned off. I would think that if the accelerometer was unplugged the led would turn off. Or am I mistaken with that thought?
 

hgmjr

Joined Jan 28, 2005
9,027
Take a picture of your hookup aand post it here and I think Chris or I can figure it out.

You can attach your pics using AAC instead of photoflix.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
You need to give it another try.

You will need to use "Go Advanced" mode and look for button "Manage attachments".


hgmjr
 

Thread Starter

ripcus10

Joined Apr 13, 2012
56
Here is one with the led on. I'm not using an external led i'm using on that is already on the board. It is in slot 13 (the green one that is lit up in the picture right above the power light)
 

Attachments

hgmjr

Joined Jan 28, 2005
9,027
Hold on. I thought we have been talking about an LED that was put in place of the RELAY as a test.

The LED on the accelerometer board most likely indicates that power is applied to the board.

hgmjr
 
Top