Hello!
I am quite new to programming and working with microcontrollers. The Firmware on my ESP8266 ist Micropython: esp8266-20170108-v1.8.7.bin
I want to connect my ESP8266 HUZZAH breakout microcontroller with LSM9DS1 9DOF. I have found a library for this sensor. But it was written to work with the PyBoard, I guess.
https://github.com/hoihu/projects/blob/ ... lsm9ds1.py
I tried to make it work with my ESP8266, but I have some issues with it.
So this is what I write into WebREPL.
WebREPL connected
>>> import machine
>>> from lsm9ds1 import LSM9DS1
>>> from machine import Pin, I2C
>>> import array
>>> i2c = I2C(scl=Pin(5), sda=Pin(4))
>>> i2c.start()
>>> lsm9 = LSM9DS1(i2c)
right id's are given
>>> lsm9.read_gyro()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lsm9ds1.py", line 167, in read_gyro
TypeError: can't convert memoryview to int
I totally don't know how to get rid of this error.
This is what the function looks like:
def read_gyro(self):
"""Returns gyroscope vector in degrees/sec."""
i2c = self.i2c
mv = memoryview(array.array('h',[0,0,0]))
f = self.scale_gyro
self.i2c.readfrom_mem(107, 0x18 | 0x80, mv)
return (mv[0]/f, mv[1]/f, mv[2]/f)
Thank you all in advance!!
ESP8266 HUZZAH breakout + LSM9DS1 9DOF
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
The third argument to readfrom_mem should be the number of bytes to read, and not the buffer to read them into, as this code seems to assume. I think this code is simply wrong.
-
- Posts: 288
- Joined: Sun May 04, 2014 8:54 am
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
Not sure how similar they are, but maybe this helps:
https://github.com/micropython-IMU/micropython-lsm9ds0
https://github.com/micropython-IMU/micropython-lsm9ds0
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
Thank you for answers!
I solved this problem by using the i2c.readfrom_mem_into function. And I changed self.scratch_int from self.scratch_int = array.array('h',[0,0,0]) to self.scratch_int = bytearray(3) and also self.scratch = array.array('B',[0,0,0,0,0,0]) to self.scratch = bytearray(6). This finally made the functions work. I will share the ESP8266-specified lsm9ds1.py file as soon as I can confirm that it works properly.
I solved this problem by using the i2c.readfrom_mem_into function. And I changed self.scratch_int from self.scratch_int = array.array('h',[0,0,0]) to self.scratch_int = bytearray(3) and also self.scratch = array.array('B',[0,0,0,0,0,0]) to self.scratch = bytearray(6). This finally made the functions work. I will share the ESP8266-specified lsm9ds1.py file as soon as I can confirm that it works properly.
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
I'm the author of this driver. It was originally designed to work with the pyb module and its I2C interface.
Later I started to port the driver to work with the machine module but unfortunately I couldn't test it because my SenseHat board was broken. It seems that I've overlooked a couple of things.
I'm happy to accept pull requests- it would be nice to test it on the pyboard as well.
Later I started to port the driver to work with the machine module but unfortunately I couldn't test it because my SenseHat board was broken. It seems that I've overlooked a couple of things.
I'm happy to accept pull requests- it would be nice to test it on the pyboard as well.
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
Hey marfis,
Thanks for your respond!
As soon as I finish my project, I will try to run this driver on the pyboard. Could you tell me how to visualize the data LSM9DS1 shows me ?
Thanks for your respond!
As soon as I finish my project, I will try to run this driver on the pyboard. Could you tell me how to visualize the data LSM9DS1 shows me ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
A common requirement is to derive heading, pitch and roll values from the three sensors. This is known as sensor fusion and is mathematically fairly involved. This library https://github.com/micropython-IMU/micr ... fusion.git achieves this. It is designed to be device independent but you will need to do some work to interface it to your sensor (it was developed with MPU6050, MPU9150 and MPU9250 devices).
I have run it on the ESP8266 but had to use frozen bytecode because of lack of RAM.
You may like to offer some code in due course
I have run it on the ESP8266 but had to use frozen bytecode because of lack of RAM.
You may like to offer some code in due course
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: ESP8266 HUZZAH breakout + LSM9DS1 9DOF
see also here:
viewtopic.php?t=1693
I used @pythoncoders fusion lib to work with the lsm9ds1 sensor chip and made a balancing ball example (video link is also in the link above)
viewtopic.php?t=1693
I used @pythoncoders fusion lib to work with the lsm9ds1 sensor chip and made a balancing ball example (video link is also in the link above)