I'm trying to get a ESP8266 D1 mini to communicate with an MPU9250.
After many trials and tribulations I've managed to create and flash my own firmware based on https://github.com/adafruit/esp8266-mic ... agrant.git with apparent success.
All of this was achieved by following the instructions in: https://learn.adafruit.com/building-and ... d-firmware.
This runs on a VM on my windows 10 machine.
While in the VM, I also cloned the https://github.com/micropython-IMU/micropython-mpu9x50 repository to its own folder. ~/micropython-mpu9x50.
From this folder I issued cp *.py ~/micropython/ports/esp8266/modules ## 4 modules was copied.
cd ~/micropython/ports/esp8266/modules
ls *.py ## shows 4 files are copied correctly
cd ~/micropython
git submodule update --init
make -C mpy-cross
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
make: Entering directory '/home/vagrant/micropython/mpy-cross'
make: Leaving directory '/home/vagrant/micropython/mpy-cross'
cd ~/micropython/ports/esp8266
make axtls
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
make: *** No rule to make target 'axtls', Stop. ## could this be part of my problem?
make
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
MPY modules/mpu9250.py
MPY modules/mpu9150.py
MPY modules/vector3d.py
MPY modules/imu.py
GEN build/frozen-mpy.c
CC build/frozen-mpy.c
LINK build/firmware.elf
text data bss dec hex filename
596244 1096 66368 663708 a209c build/firmware.elf
Create build/firmware-combined.bin
esptool.py v1.2
flash 32976
padding 3888
irom0text 564404
total 601268
md5 5577863511db7ce1c4b6e52659640e26
cp ./build/firmware-combined.bin /vagrant/
exit ## the VM
From here I checked that the current firmware-combined.bin is available from DOS. (check date & time)
Now I used uPyCraft IDE to Burn the firmware onto the esp8266
Then I accessed the REPL via uPyCraft
## the following instructions from the README.md of the ~/micropython-mpu9x50 folder.
## 'Wiring the sensors.
##pyboard mpu9250
VIN 3V3
GND GND
SCL SCL ## on esp8266 I connected GPIO5 pulled up by 5k1 resistor to 3v3.
SDA SDA ## on esp8266 I connected GPIO4 pulled up by 5k1 resistor to 3v3.
##Quickstart
##Example assuming an MPU9250 connected to 'X' I2C interface on the Pyboard:
>>>from mpu9250 import MPU9250 ##It worked! no error message. I assume that the frozen modules are there.
>>>imu = MPU9250('X')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mpu9250.py", line 47, in --init--
File "imu.py", line 84, in --init--
ValueError: invalid I2C peripheral
Now, my guess is that the 'X' interface is a)native to the Pyboard or b) the GPIO 5(scl) and 4(sda) combination has another 'handle'.
Info on this 'X' handle is very sparse, so I ventured towards the Quick reference for the ESP8266 at micropython.org I2C bus:
>>>from machine import I2C, Pin
>>>i2c = I2C(scl=Pin(5),sda=Pin(4)) ## Works OK
Now back to the README.md instructions, with some misguided initiative:
>>>imu = MPU9250(i2c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mpu9250.py", line 47, in --init--
File "imu.py", line 99, in --init--
ValueError: Two MPU's detected: must specify a device address ##I've only got one MPU connected. My fault here. i2c.scan() shows all the available addresses. I checked wiring and retried i2c.scan() with result: [104]
>>>imu = MPU9250(i2c)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mpu9250.py", line 47, in --init--
File "imu.py", line 105, in --init--
File "imu.py", line 161, in chip_id
ValueError: Bad chip ID retrieved: MPU communication failure
And now I'm stuck here. My knowledge of micropython is pretty sparse, and I don't know how to define 'imu' so that I can use statements like: print(imu.accel.xyz) or print(imu.temperature)
I'm feeling very far, but so near. My firmware seems to be good, or am I wrong?
The README.md of the ~/micropython-mpu9x50 under heading PMU9250 Class, Methods says: "MPU9250() The constructor supports the following arguments
1. side_str 'X' or 'Y' (mandatory) defines the I2C interface in use. Alternatively an initialized I2C object may be passed.
I've already established that there are inconsistencies between Pyboard and esp8266 pin definitions. (confirmed by @pythoncoder) Could these inconsistencies stretch to usage of side_str 'X' or 'Y' as well?
Searching for 'side_str' inside docs.micropython.org did not match any document. So I assume that an initialized I2C object must be passed. I just don't know how to proceed from here.
Pyboard code on ESP2866
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Pyboard code on ESP2866
That is the correct way to set it up, and your scan result is correct. The fact that you're getting
Code: Select all
ValueError: Bad chip ID retrieved: MPU communication failure
Code: Select all
self.chip_id # Test communication by reading chip_id: throws exception on error
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.