-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request for LSM303AGR (micro:bit v1.5) #125
Comments
Tried to piece a test code together based on Adafruit's old LSM303 driver (which is pretty basic and the magnetometer registers looks incorrect.). The following code is confirmed working on my micro:bit v1.5, for both accelerometer and magnetometer. If no one else is available to work on it, I'll later try my best to write a proper-ish driver. package main
import (
"machine"
"time"
)
const (
LSM303_ADDRESS_ACCEL = 0x19
LSM303_ADDRESS_MAG = 0x1E
LSM303_REGISTER_ACCEL_CTRL_REG1_A = 0x20
LSM303_REGISTER_ACCEL_OUT_X_L_A = 0x28
LSM303_REGISTER_MAG_MR_REG_M = 0x60
LSM303_REGISTER_MAG_OUT_X_L_M = 0x68
)
func main() {
i2c := machine.I2C0
i2c.Configure(machine.I2CConfig{})
i2c.WriteRegister(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, []byte{0x77})
i2c.WriteRegister(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_MR_REG_M, []byte{0x8C})
data := make([]byte, 6)
for {
i2c.ReadRegister(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_OUT_X_L_A | 0x80, data)
accel_x := int16((uint16(data[1]) << 8) | uint16(data[0]))
accel_y := int16((uint16(data[3]) << 8) | uint16(data[2]))
accel_z := int16((uint16(data[5]) << 8) | uint16(data[4]))
i2c.ReadRegister(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_OUT_X_L_M | 0x80, data)
mag_x := int16((uint16(data[1]) << 8) | uint16(data[0]))
mag_y := int16((uint16(data[3]) << 8) | uint16(data[2]))
mag_z := int16((uint16(data[5]) << 8) | uint16(data[4]))
println("LSM303_ACCR:", accel_x, accel_y, accel_z)
println("LSM303_MAG:", mag_x, mag_y, mag_z)
println("-----")
time.Sleep(time.Millisecond * 100)
}
} Output:
|
This will be a great addition to the driver's list, I do not have one of the newest micro:bit, so feel free to continue the work and make a PR of it. |
I'll close this since in the end I solved my own request in [this PR] (#162). |
The current micro:bit version 1.5 uses a single LSM303AGR accelerometer/magnetometer chip. Might be a close relative of the LSM6DS3 driver you have here? The older 1.3b version uses MMA8653 + MAG3110.
https://tech.microbit.org/hardware/#motion-sensor
https://support.microbit.org/support/solutions/articles/19000087020-micro-bit-motion-sensor-hardware-change
The text was updated successfully, but these errors were encountered: