mpu9250: add MPU6500 (#5767)
Signed-off-by: Yifei Ding <yifeiding@protonmail.com>
This commit is contained in:
parent
8a06528747
commit
d17ef95a3c
|
@ -1640,13 +1640,14 @@ cs_pin:
|
||||||
|
|
||||||
### [mpu9250]
|
### [mpu9250]
|
||||||
|
|
||||||
Support for mpu9250 and mpu6050 accelerometers (one may define any
|
Support for MPU-9250, MPU-9255, MPU-9255, MPU-6050, and MPU-6500
|
||||||
number of sections with an "mpu9250" prefix).
|
accelerometers (one may define any number of sections with an
|
||||||
|
"mpu9250" prefix).
|
||||||
|
|
||||||
```
|
```
|
||||||
[mpu9250 my_accelerometer]
|
[mpu9250 my_accelerometer]
|
||||||
#i2c_address:
|
#i2c_address:
|
||||||
# Default is 104 (0x68).
|
# Default is 104 (0x68). If AD0 is high, it would be 0x69 instead.
|
||||||
#i2c_mcu:
|
#i2c_mcu:
|
||||||
#i2c_bus:
|
#i2c_bus:
|
||||||
#i2c_speed: 400000
|
#i2c_speed: 400000
|
||||||
|
|
|
@ -18,6 +18,31 @@ that it has a voltage regulator and a level shifter.
|
||||||
|
|
||||||
### Wiring
|
### Wiring
|
||||||
|
|
||||||
|
An ethernet cable with shielded twisted pairs (cat5e or better) is recommended
|
||||||
|
for signal integrety over a long distance. If you still experience signal integrity
|
||||||
|
issues (SPI/I2C errors), shorten the cable.
|
||||||
|
|
||||||
|
Connect ethernet cable shielding to the controller board/RPI ground.
|
||||||
|
|
||||||
|
***Double-check your wiring before powering up to prevent
|
||||||
|
damaging your MCU/Raspberry Pi or the accelerometer.***
|
||||||
|
|
||||||
|
#### SPI Accelerometers
|
||||||
|
|
||||||
|
Suggested twisted pair order:
|
||||||
|
|
||||||
|
```
|
||||||
|
GND+MISO
|
||||||
|
3.3V+MOSI
|
||||||
|
SCLK+CS
|
||||||
|
```
|
||||||
|
|
||||||
|
##### ADXL345
|
||||||
|
|
||||||
|
|
||||||
|
**Note: Many MCUs will work with an ADXL345 in SPI mode(eg Pi Pico), wiring and
|
||||||
|
configuration will vary according to your specific board and avaliable pins.**
|
||||||
|
|
||||||
You need to connect ADXL345 to your Raspberry Pi via SPI. Note that the I2C
|
You need to connect ADXL345 to your Raspberry Pi via SPI. Note that the I2C
|
||||||
connection, which is suggested by ADXL345 documentation, has too low throughput
|
connection, which is suggested by ADXL345 documentation, has too low throughput
|
||||||
and **will not work**. The recommended connection scheme:
|
and **will not work**. The recommended connection scheme:
|
||||||
|
@ -31,25 +56,46 @@ and **will not work**. The recommended connection scheme:
|
||||||
| SDA | 19 | GPIO10 (SPI0_MOSI) |
|
| SDA | 19 | GPIO10 (SPI0_MOSI) |
|
||||||
| SCL | 23 | GPIO11 (SPI0_SCLK) |
|
| SCL | 23 | GPIO11 (SPI0_SCLK) |
|
||||||
|
|
||||||
An alternative to the ADXL345 is the MPU-9250 (or MPU-6050). This
|
|
||||||
accelerometer has been tested to work over I2C on the RPi at 400kbaud.
|
|
||||||
Recommended connection scheme for I2C:
|
|
||||||
|
|
||||||
| MPU-9250 pin | RPi pin | RPi pin name |
|
|
||||||
|:--:|:--:|:--:|
|
|
||||||
| 3V3 (or VCC) | 01 | 3.3v DC power |
|
|
||||||
| GND | 09 | Ground |
|
|
||||||
| SDA | 03 | GPIO02 (SDA1) |
|
|
||||||
| SCL | 05 | GPIO03 (SCL1) |
|
|
||||||
|
|
||||||
|
|
||||||
Fritzing wiring diagrams for some of the ADXL345 boards:
|
Fritzing wiring diagrams for some of the ADXL345 boards:
|
||||||
|
|
||||||
![ADXL345-Rpi](img/adxl345-fritzing.png)
|
![ADXL345-Rpi](img/adxl345-fritzing.png)
|
||||||
|
|
||||||
|
#### I2C Accelerometers
|
||||||
|
|
||||||
Double-check your wiring before powering up the Raspberry Pi to prevent
|
Suggested twisted pair order:
|
||||||
damaging it or the accelerometer.
|
|
||||||
|
```
|
||||||
|
3.3V+SDA
|
||||||
|
GND+SCL
|
||||||
|
```
|
||||||
|
|
||||||
|
##### MPU-9250/MPU-9255/MPU-6515/MPU-6050/MPU-6500
|
||||||
|
|
||||||
|
Alternatives to the ADXL345 are MPU-9250/MPU-9255/MPU-6515/MPU-6050/MPU-6500.
|
||||||
|
These accelerometers have been tested to work over I2C on the RPi or RP2040(pico)
|
||||||
|
at 400kbaud.
|
||||||
|
|
||||||
|
Recommended connection scheme for I2C on the Raspberry Pi:
|
||||||
|
|
||||||
|
| MPU-9250 pin | RPi pin | RPi pin name |
|
||||||
|
|:--:|:--:|:--:|
|
||||||
|
| VCC | 01 | 3.3v DC power |
|
||||||
|
| GND | 09 | Ground |
|
||||||
|
| SDA | 03 | GPIO02 (SDA1) |
|
||||||
|
| SCL | 05 | GPIO03 (SCL1) |
|
||||||
|
|
||||||
|
![MPU-9250 connected to RPI](img/mpu9250-PI-fritzing.png)
|
||||||
|
|
||||||
|
Recommended connection scheme for I2C(i2c0a) on the RP2040:
|
||||||
|
|
||||||
|
| MPU-9250 pin | RP2040 pin | RPi pin name |
|
||||||
|
|:--:|:--:|:--:|
|
||||||
|
| VCC | 39 | 3v3 |
|
||||||
|
| GND | 38 | Ground |
|
||||||
|
| SDA | 01 | GP0 (I2C0 SDA) |
|
||||||
|
| SCL | 02 | GP1 (I2C0 SCL) |
|
||||||
|
|
||||||
|
![MPU-9250 connected to PICO](img/mpu9250-PICO-fritzing.png)
|
||||||
|
|
||||||
### Mounting the accelerometer
|
### Mounting the accelerometer
|
||||||
|
|
||||||
|
@ -96,10 +142,13 @@ Afterwards, check and follow the instructions in the
|
||||||
[RPi Microcontroller document](RPi_microcontroller.md) to setup the
|
[RPi Microcontroller document](RPi_microcontroller.md) to setup the
|
||||||
"linux mcu" on the Raspberry Pi.
|
"linux mcu" on the Raspberry Pi.
|
||||||
|
|
||||||
|
#### Configure ADXL345 With RPi
|
||||||
|
|
||||||
Make sure the Linux SPI driver is enabled by running `sudo
|
Make sure the Linux SPI driver is enabled by running `sudo
|
||||||
raspi-config` and enabling SPI under the "Interfacing options" menu.
|
raspi-config` and enabling SPI under the "Interfacing options" menu.
|
||||||
|
|
||||||
For the ADXL345, add the following to the printer.cfg file:
|
Add the following to the printer.cfg file:
|
||||||
|
|
||||||
```
|
```
|
||||||
[mcu rpi]
|
[mcu rpi]
|
||||||
serial: /tmp/klipper_host_mcu
|
serial: /tmp/klipper_host_mcu
|
||||||
|
@ -115,9 +164,12 @@ probe_points:
|
||||||
It is advised to start with 1 probe point, in the middle of the print bed,
|
It is advised to start with 1 probe point, in the middle of the print bed,
|
||||||
slightly above it.
|
slightly above it.
|
||||||
|
|
||||||
For the MPU-9250, make sure the Linux I2C driver is enabled and the baud rate is
|
#### Configure MPU-6000/9000 series With RPi
|
||||||
|
|
||||||
|
Make sure the Linux I2C driver is enabled and the baud rate is
|
||||||
set to 400000 (see [Enabling I2C](RPi_microcontroller.md#optional-enabling-i2c)
|
set to 400000 (see [Enabling I2C](RPi_microcontroller.md#optional-enabling-i2c)
|
||||||
section for more details). Then, add the following to the printer.cfg:
|
section for more details). Then, add the following to the printer.cfg:
|
||||||
|
|
||||||
```
|
```
|
||||||
[mcu rpi]
|
[mcu rpi]
|
||||||
serial: /tmp/klipper_host_mcu
|
serial: /tmp/klipper_host_mcu
|
||||||
|
@ -132,6 +184,28 @@ probe_points:
|
||||||
100, 100, 20 # an example
|
100, 100, 20 # an example
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Configure MPU-6000/9000 series With PICO
|
||||||
|
|
||||||
|
PICO I2C is set to 400000 on default. Simply add the following to the
|
||||||
|
printer.cfg:
|
||||||
|
|
||||||
|
```
|
||||||
|
[mcu pico]
|
||||||
|
serial: /dev/serial/by-id/<your PICO's serial ID>
|
||||||
|
|
||||||
|
[mpu9250]
|
||||||
|
i2c_mcu: pico
|
||||||
|
i2c_bus: i2c1a
|
||||||
|
|
||||||
|
[resonance_tester]
|
||||||
|
accel_chip: mpu9250
|
||||||
|
probe_points:
|
||||||
|
100, 100, 20 # an example
|
||||||
|
|
||||||
|
[static_digital_output pico_3V3pwm] # Improve power stability
|
||||||
|
pin: pico:gpio23
|
||||||
|
```
|
||||||
|
|
||||||
Restart Klipper via the `RESTART` command.
|
Restart Klipper via the `RESTART` command.
|
||||||
|
|
||||||
## Measuring the resonances
|
## Measuring the resonances
|
||||||
|
@ -158,6 +232,9 @@ is some other ID, it is indicative of the connection problem with ADXL345,
|
||||||
or the faulty sensor. Double-check the power, the wiring (that it matches
|
or the faulty sensor. Double-check the power, the wiring (that it matches
|
||||||
the schematics, no wire is broken or loose, etc.), and soldering quality.
|
the schematics, no wire is broken or loose, etc.), and soldering quality.
|
||||||
|
|
||||||
|
**If you are using MPU-6000/9000 series accelerometer and it show up as `mpu-unknown`, use with
|
||||||
|
caution! They are probably refurbished chips!**
|
||||||
|
|
||||||
Next, try running `MEASURE_AXES_NOISE` in Octoprint, you should get some
|
Next, try running `MEASURE_AXES_NOISE` in Octoprint, you should get some
|
||||||
baseline numbers for the noise of accelerometer on the axes (should be
|
baseline numbers for the noise of accelerometer on the axes (should be
|
||||||
somewhere in the range of ~1-100). Too high axes noise (e.g. 1000 and more)
|
somewhere in the range of ~1-100). Too high axes noise (e.g. 1000 and more)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
Binary file not shown.
After Width: | Height: | Size: 58 KiB |
|
@ -9,8 +9,16 @@ from . import bus, motion_report, adxl345
|
||||||
|
|
||||||
MPU9250_ADDR = 0x68
|
MPU9250_ADDR = 0x68
|
||||||
|
|
||||||
MPU9250_DEV_ID = 0x73
|
MPU_DEV_IDS = {
|
||||||
MPU6050_DEV_ID = 0x68
|
0x74: "mpu-9515",
|
||||||
|
0x73: "mpu-9255",
|
||||||
|
0x71: "mpu-9250",
|
||||||
|
0x70: "mpu-6500",
|
||||||
|
0x68: "mpu-6050",
|
||||||
|
#everything above are normal MPU IDs
|
||||||
|
0x75: "mpu-unknown (DEFECTIVE! USE WITH CAUTION!)",
|
||||||
|
0x69: "mpu-unknown (DEFECTIVE! USE WITH CAUTION!)",
|
||||||
|
}
|
||||||
|
|
||||||
# MPU9250 registers
|
# MPU9250 registers
|
||||||
REG_DEVID = 0x75
|
REG_DEVID = 0x75
|
||||||
|
@ -189,12 +197,14 @@ class MPU9250:
|
||||||
# In case of miswiring, testing MPU9250 device ID prevents treating
|
# In case of miswiring, testing MPU9250 device ID prevents treating
|
||||||
# noise or wrong signal as a correctly initialized device
|
# noise or wrong signal as a correctly initialized device
|
||||||
dev_id = self.read_reg(REG_DEVID)
|
dev_id = self.read_reg(REG_DEVID)
|
||||||
if dev_id != MPU9250_DEV_ID and dev_id != MPU6050_DEV_ID:
|
if dev_id not in MPU_DEV_IDS.keys():
|
||||||
raise self.printer.command_error(
|
raise self.printer.command_error(
|
||||||
"Invalid mpu9250/mpu6050 id (got %x).\n"
|
"Invalid mpu id (got %x).\n"
|
||||||
"This is generally indicative of connection problems\n"
|
"This is generally indicative of connection problems\n"
|
||||||
"(e.g. faulty wiring) or a faulty chip."
|
"(e.g. faulty wiring) or a faulty chip."
|
||||||
% (dev_id))
|
% (dev_id))
|
||||||
|
else:
|
||||||
|
logging.info("Found %s with id %x"% (MPU_DEV_IDS[dev_id], dev_id))
|
||||||
# Setup chip in requested query rate
|
# Setup chip in requested query rate
|
||||||
self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_WAKE)
|
self.set_reg(REG_PWR_MGMT_1, SET_PWR_MGMT_1_WAKE)
|
||||||
self.set_reg(REG_PWR_MGMT_2, SET_PWR_MGMT_2_ACCEL_ON)
|
self.set_reg(REG_PWR_MGMT_2, SET_PWR_MGMT_2_ACCEL_ON)
|
||||||
|
|
Loading…
Reference in New Issue