Flora Accelerometer

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Flora Accelerometer

Post by Plushberry »

I was wondering if there was a way to either use the accelerometer to record the data and be able to determine the velocity, or simply to integrate acceleration to figure out immediate velocity directly in the code. I am trying to use the accelerometer to smoothly change the colors of neopixels as the speed increases

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

The accelerometer itself can't measure velocity. You can only estimate it by integrating the acceleration over time. You can do reasonably well over a short time-span if you calibrate for any zero-g offset and start from a known velocity (e.g. zero). But cumulative errors are inevitable, so your velocity estimate will be less accurate over time.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

how possible would it be to make something that goes from one color to another as the speed goes up and down? also, what would the code for the integration look like>

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

how possible would it be to make something that goes from one color to another as the speed goes up and down?
To do that, you don't need to integrate anything. You just need to look at the acceleration force. If the force is positive in a certain direction, then you are accelerating - so your speed is increasing. If the acceleration force is negative, then you are decelerating so your speed is decreasing.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

I know, but if you're going at a constant speed, there is no acceleration, therefore it would read zero. so for constant velocity i would need to constantly integrate the information.

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

What exactly are your requirements? If you want o know if you are accelerating or decelerating, an accelerometer is what you need. If you want to know your precise velocity at all times, you will need something more than an accelerometer. Typically for navigation systems, acceleration data is combined with GPS data to derive long-term velocity data.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

as i described, i just want to place the flora with the accelerometer on a moving object, and say if the object is stationary, the leds glow red, but when the object starts moving forwards the color smoothly changes. like a bike or skateboard is what i have in mind, so i guess roughly 30 minutes of velocity data.

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

You will not be able to accurately calculate velocity over a period of 30 minutes using only an accelerometer. The accelerometer will measure vibration and other acceleration forces. So it can give you some other clues about whether you are moving or not. You just can't know precisely how fast unless you add some additional data such as GPS position data.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

So the gps module is what i would want to include if i want to measure velocity over time correct?

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

For something like a bike or a skateboard, yes. GPS position data is only accurate to within a few meters. But moving at bike or skateboard speeds, you can get a reasonable longer-term estimate of speed. There are various algorithms such as Kalman or complementary filters that can combine the long-term absolute accuracy of the GPS with the short-term relative accuracy of the accelerometer to get a good real-time estimate of velocity.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

Thanks for the help with the accelerometer/velocity question i had. I am also unsure of how to detect north using the magnetometer data when I open up the serial port and turn it 90 degrees, I don't see a strong change in values, they do change, but not in a way I specifically understand. I bascically want to color code the cardinal directions so that if the divice is pointed north, the leds will change accordingly.

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

I bascically want to color code the cardinal directions so that if the divice is pointed north, the leds will change accordingly.
That is similar to what is done here: https://learn.adafruit.com/steam-punk-g ... ementation
The compass heading is calculated in the beginning of the loop function:

Code: Select all

   // Calculate the angle of the vector y,x from magnetic North
   float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
The heading is passed to this function to select the color:

Code: Select all

// choose a color based on the compass heading and proximity to "pos".
uint32_t selectColor(float heading, float proximity)
{
     uint32_t color;
 
     // Choose eye color based on the compass heading
     if (heading < 60)
     {
        color = strip.Color(0, 0, proximity);
     }
     else if (heading < 120)
     {
        color = strip.Color(0, proximity, proximity);
     }
     else if (heading < 180)
     {
        color = strip.Color(0, proximity, 0);
     }
     else if (heading < 240)
     {
        color = strip.Color(proximity, proximity, 0);
     }
     else if (heading < 300)
     {
        color = strip.Color(proximity, 0, 0);
     }
     else // 300-360
     {
        color = strip.Color(proximity, 0, proximity);
     }
}

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

Should i worry about the values in the serial port, or is it fine, since i know the accelerometer is working?

User avatar
adafruit_support_bill
 
Posts: 88139
Joined: Sat Feb 07, 2009 10:11 am

Re: Flora Accelerometer

Post by adafruit_support_bill »

If the magnetometer is working correctly, the heading calculation should give you a value between 0 and 360 degrees.

User avatar
Plushberry
 
Posts: 194
Joined: Wed Oct 14, 2015 10:06 pm

Re: Flora Accelerometer

Post by Plushberry »

is there a simple way i can test it out?

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”