The WG901 accelerometer is a versatile sensor capable of measuring acceleration along multiple axes. It is an essential component in modern electronics, providing critical data for motion detection, orientation, and dynamic acceleration. Common applications include smartphones, wearables, gaming devices, vehicle dynamics, and industrial machinery monitoring.
Pin Number | Pin Name | Description |
---|---|---|
1 | VDD | Power supply voltage |
2 | GND | Ground |
3 | SCL/SPC | Serial Clock for I2C/SPI Clock |
4 | SDA/SDI | Serial Data for I2C/SPI Data Input |
5 | SDO | SPI Data Output (if SPI mode is selected) |
6 | CS | Chip Select for SPI (active low) |
7 | INT1 | Interrupt 1 output |
8 | INT2 | Interrupt 2 output |
#include <Wire.h>
// WG901 I2C address (check datasheet for your device's address)
#define WG901_I2C_ADDRESS 0x1D
// Register addresses (refer to the WG901 datasheet)
#define REG_CTRL1 0x20
#define REG_OUT_X 0x29
void setup() {
Wire.begin(); // Initialize I2C
Serial.begin(9600); // Start serial communication at 9600 baud
// Initialize WG901 (set ODR, measurement range, etc.)
Wire.beginTransmission(WG901_I2C_ADDRESS);
Wire.write(REG_CTRL1);
Wire.write(0x57); // Example configuration byte
Wire.endTransmission();
}
void loop() {
int16_t xAccel = readAcceleration(REG_OUT_X);
Serial.print("X-Axis Acceleration: ");
Serial.println(xAccel);
delay(100); // Read every 100 milliseconds
}
int16_t readAcceleration(byte regAddress) {
Wire.beginTransmission(WG901_I2C_ADDRESS);
Wire.write(regAddress);
Wire.endTransmission(false);
Wire.requestFrom(WG901_I2C_ADDRESS, 2, true);
byte lowByte = Wire.read();
byte highByte = Wire.read();
// Combine the two bytes into a 16-bit value and return it
return (int16_t)((highByte << 8) | lowByte);
}
Q: How do I change the measurement range? A: Modify the configuration byte sent to the REG_CTRL1 register to select the desired range.
Q: Can I use both I2C and SPI simultaneously? A: No, you must select one communication protocol and configure the device accordingly.
Q: What is the purpose of the INT1 and INT2 pins? A: These pins can be configured to output interrupt signals for events like data ready, free-fall detection, or motion detection.
Q: How do I interpret the raw acceleration data? A: The raw data needs to be converted using the sensitivity level set by the measurement range. Refer to the datasheet for the conversion formula.
This documentation provides a foundational understanding of the WG901 accelerometer and how to integrate it into electronic projects. For more detailed information, always refer to the manufacturer's datasheet.