Help with control from Arduino Mega to ADXL345 Accelerometer

In summary, the individual is having trouble compiling their code while following a tutorial for an Arduino project. The error message mentions an undefined reference to "yield" and the individual is unsure of what that means or what they are doing wrong. The code they are using is provided and they are seeking assistance in resolving the issue.
  • #1
NaughtyBear
17
1
So I was starting a project and have run into a small issue. I was following a tutorial and the code is not compiling correctly. The error reads as:

Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\NEVERM~1\AppData\Local\Temp\build4347706786189926824.tmp/core.a(wiring.c.o): In function `delay':

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/wiring.c:113: undefined reference to `yield'

collect2.exe: error: ld returned 1 exit status

Error compiling.And I am unsure of what that means or what I am doing wrong. The link is http://eeenthusiast.com/arduino-i2c-adxl-345-robot/ is the tutorial I was following and the code is:
Code:
#include <Wire.h>

#define accel_module (0x53)
byte values[6] ;
char output[512];

void setup(){
Wire.begin();
Serial.begin(9600);

Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(0);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(16);
Wire.endTransmission();
Wire.beginTransmission(accel_module);
Wire.write(0x2D);
Wire.write(8);
Wire.endTransmission();
}

void loop(){
int xyzregister = 0x32;
int x, y, z;

Wire.beginTransmission(accel_module);
Wire.write(xyzregister);
Wire.endTransmission();

Wire.beginTransmission(accel_module);
Wire.requestFrom(accel_module, 6);

int i = 0;
while(Wire.available()){
values[i] = Wire.read();
i++;
}
Wire.endTransmission();

x = (((int)values[1]) << 8) | values[0];
y = (((int)values[3])<< 8) | values[2];
z = (((int)values[5]) << 8) | values[4];

sprintf(output, "%d %d %d", x, y, z);
Serial.print(output);
Serial.write(10);

delay(2000);
}

Any and all help is appreciated. Thank you for your time and assistance!
 
Engineering news on Phys.org

1. How do I connect an ADXL345 accelerometer to an Arduino Mega?

To connect an ADXL345 accelerometer to an Arduino Mega, you will need to use the I2C communication protocol. Connect the SDA and SCL pins of the ADXL345 to the corresponding pins on the Arduino Mega. You will also need to connect the VCC and GND pins to a 3.3V power source and ground on the Arduino Mega. Finally, connect the CS pin to any digital pin on the Arduino Mega for communication.

2. How do I code the Arduino Mega to read data from the ADXL345?

To read data from the ADXL345 accelerometer, you will need to use the Wire library in your Arduino code. First, initialize the library by calling Wire.begin() in the setup() function. Then, use the Wire.requestFrom() function to request data from the ADXL345. Finally, use the Wire.read() function to read the data from the accelerometer and store it in a variable.

3. How do I interpret the data from the ADXL345 accelerometer?

The data from the ADXL345 accelerometer is in the form of acceleration values in the x, y, and z directions. These values are raw data and will need to be converted using the sensitivity range of the accelerometer. The sensitivity range can be changed by writing to the appropriate register in the accelerometer. Once the data is converted, it can be used for further calculations or displayed on a screen.

4. How can I use the data from the ADXL345 accelerometer to control something?

The data from the ADXL345 accelerometer can be used to control various things, such as LEDs, motors, or servos. You can use conditional statements in your code to check the values of the accelerometer and trigger actions accordingly. For example, if the accelerometer detects a certain level of acceleration, you can turn on an LED or move a servo.

5. What are some common troubleshooting steps for getting the Arduino Mega to communicate with the ADXL345 accelerometer?

If you are having trouble getting the Arduino Mega to communicate with the ADXL345 accelerometer, there are a few things you can try. First, make sure all the connections are secure and in the correct pins. Check your code for any errors and make sure the Wire library is properly initialized. You can also try using a different I2C address for the accelerometer by changing the address pins. Finally, make sure the accelerometer is receiving power and is properly configured for I2C communication.

Similar threads

  • Electrical Engineering
Replies
1
Views
2K
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
1K
  • Computing and Technology
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
Replies
3
Views
10K
Back
Top