Skip to content

12. Gyro Accelerometer

sm6yvr edited this page Jun 8, 2017 · 10 revisions

This is not yet a released feature, the functions is in the develop branch

ADXL345

This sensor is a 3 axis accelerometer/gyro, It's possible to read x,y,z angle and also xg,yg,zg for acceleration. Angle should be used to be able to track when the mover are flipped and then stop the cutter engine. The cutter engine should not start if the mover is not standing flat.

PoC: I would like to try if it's possible to use the accelerometer to detect if the mover has hit something. The sensor has support for fire an event (interrupt) when a "tap" is detected. I have an idea to use this to detect that the mover has reached something and then back and move away.

Assemble

The sensor are soldered on a lab board for easier assembly. ADXL345

Connection

This sensor is connected to the I2C bus on the morgan top shield, the connections marked gyro or display can be used.

ADXL345 I2C gyro Description
5V pin 1 +
SDA pin 2
SCL pin 3
GND, SDO pin 4 - Both GND and SDO to -
3v3 <-> CS Connect 3v3 with CS

Setup and debug software

A new function must be added in the test program to be able to see the reported values when the mover is standing flat.

Configuration

Uncomment this line in Definition.h to enable this sensor in the code:

//#define __ADXL345__

Here are some parameters that you can/should update depends on how your setup is.

SensADXL345.h

Parameter default value Description
ADDRESS_I2C 0x53 If SDO connected to GND otherwise is address 0x1D

Definition.h

Parameter default value Description
Z_ANGLE_NORMAL See section SetupDebug MODE how to get this value
Y_ANGLE_NORMAL See section SetupDebug MODE how to get this value
TILTANGLE 45 when the mover detect that is's tilted
FLIPANGLE 75 when the mover detect that it's flipped and stop the cutter engine.

SetupDebug MODE

StartDebug MODE must be enabled in definition.h

#define __SETUP_AND_DEBUG_MODE__ true

It's now important that the liam is standing on a flat surface like a floor.

Send the code to your arduino uno and start a serial monitor. Type 'H' to see the help text. Then type G to get some value from the sensor.

**********************
SW version:5.2.0Jun  8 201723:01:56
SensADXL345 Initialized!
Welcome to Liam Test Program
Send 'H' for list of commands
<typing H>
------- Help menu ------------
L = Left Wheel motor on/off
R = Right Wheel motor on/off
C = Cutter motor on/off
S = test BWF Sensor
G = test Gyro/Compass/Accelerometer
D = turn LED on/off
T = make a 10 second test run
P = print SOC & debug values
E = Cutter motor calibrate
<typing G>
RAW Z = 161
RAW Y = 195
Tilt angle = 20

Copy the RAW-values from the output and update the parameters in definition.h

#define Z_ANGLE_NORMAL 161
#define Y_ANGLE_NORMAL 195

Program the updated code to the arduino and run the "G" again to see the "Tilt angle". it should now be around 0 and you are ready with the setup of ADXL345.

Datasheet

http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL346.pdf