Skip to content

Commit af33c9f

Browse files
authored
Optimizations and backward compatibility added (#3)
* Readings in example optimized; arduino version < 1.0 support; readme syntax and markdown error fixed and chaged; reorganized examples folder structure; keywords.txt added for keywords highlighting; I2C bus initialization moved into a library, so no need to initialize it separately * Old files removed * Markdown fixed
1 parent 6b3b2fb commit af33c9f

File tree

7 files changed

+123
-89
lines changed

7 files changed

+123
-89
lines changed

GY_85.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ float* GY_85::readGyro()
161161

162162
void GY_85::init()
163163
{
164+
Wire.begin();
164165
SetAccelerometer();
165166
SetCompass();
166167
SetGyro();

GY_85.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
#include "Arduino.h"
2-
#include <Wire.h>
3-
41
#ifndef GY_85_h
52
#define GY_85_h
63

4+
#if ARDUINO >= 100
5+
#include "Arduino.h"
6+
#else
7+
#include "WProgram.h"
8+
#endif
9+
10+
#include <Wire.h>
11+
712
//----------addresses----------//
813
#define ADXL345 (0x53) // Device address as specified in data sheet //ADXL345 accelerometer
914
#define DATAX0 (0x32) //X-Axis Data 0
@@ -16,8 +21,7 @@
1621
#define ITG3200 (0x68) //compass
1722

1823

19-
class GY_85
20-
{
24+
class GY_85 {
2125

2226
private:
2327
void GyroCalibrate();

README

Lines changed: 0 additions & 25 deletions
This file was deleted.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
GY-85 Arduino Library
2+
=====================
3+
A basic GY-85 raw data getter for arduino.
4+
5+
Wiring for arduino UNO:
6+
7+
GY-85 -> Arduino
8+
--------------------
9+
VCC_IN -> 5V
10+
GND -> GND
11+
SCL -> A5
12+
SDA -> A4
13+
14+
For other arduino boards you have to check the I2C pins.
15+
16+
Installation
17+
--------------------
18+
Download library and move it to your Arduino/libraries folder

example/example.ino

Lines changed: 0 additions & 59 deletions
This file was deleted.

examples/ReadRawData/ReadRawData.ino

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "GY_85.h"
2+
3+
// Create module object
4+
GY_85 GY85;
5+
6+
void setup() {
7+
// Initialize the serial communication:
8+
Serial.begin(9600);
9+
10+
// Initialize module
11+
GY85.init();
12+
}
13+
14+
void loop() {
15+
// Read data from sensors
16+
int* accelerometerReadings = GY85.readFromAccelerometer();
17+
int ax = GY85.accelerometer_x(accelerometerReadings);
18+
int ay = GY85.accelerometer_y(accelerometerReadings);
19+
int az = GY85.accelerometer_z(accelerometerReadings);
20+
21+
int* compassReadings = GY85.readFromCompass();
22+
int cx = GY85.compass_x(compassReadings);
23+
int cy = GY85.compass_y(compassReadings);
24+
int cz = GY85.compass_z(compassReadings);
25+
26+
float* gyroReadings = GY85.readGyro();
27+
float gx = GY85.gyro_x(gyroReadings);
28+
float gy = GY85.gyro_y(gyroReadings);
29+
float gz = GY85.gyro_z(gyroReadings);
30+
float gt = GY85.temp(gyroReadings);
31+
32+
// Log it to serial port
33+
Serial.print("accelerometer");
34+
Serial.print(" x:");
35+
Serial.print(ax);
36+
Serial.print(" y:");
37+
Serial.print(ay);
38+
Serial.print(" z:");
39+
Serial.print(az);
40+
41+
Serial.print("\t compass");
42+
Serial.print(" x:");
43+
Serial.print(cx);
44+
Serial.print(" y:");
45+
Serial.print(cy);
46+
Serial.print(" z:");
47+
Serial.print(cz);
48+
49+
Serial.print("\t gyro");
50+
Serial.print(" x:");
51+
Serial.print(gx);
52+
Serial.print(" y:");
53+
Serial.print(gy);
54+
Serial.print(" z:");
55+
Serial.print(gz);
56+
Serial.print("\t gyro temp:");
57+
Serial.println(gt);
58+
59+
// Make delay between readings
60+
delay(100);
61+
}

keywords.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#######################################
2+
# Syntax Coloring Map For GY_85
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
GY_85 KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
init KEYWORD2
16+
readFromAccelerometer KEYWORD2
17+
readFromCompass KEYWORD2
18+
readGyro KEYWORD2
19+
accelerometer_x KEYWORD2
20+
accelerometer_y KEYWORD2
21+
accelerometer_z KEYWORD2
22+
compass_x KEYWORD2
23+
compass_y KEYWORD2
24+
compass_z KEYWORD2
25+
gyro_x KEYWORD2
26+
gyro_y KEYWORD2
27+
gyro_z KEYWORD2
28+
temp KEYWORD2
29+
30+
#######################################
31+
# Constants (LITERAL1)
32+
#######################################
33+
34+
#sample LITERAL1

0 commit comments

Comments
 (0)