Accelerometer readings get "stuck" - please help
Accelerometer readings get "stuck" - please help
Hi guys,
I'm working for a couple of days on an accelerometer data logger, and haven't been able to avoid the following problem:
- if I try to continuously retrieve Accel readings, even at very low rates (as 20Hz), after a short amount of time the readings get stuck; the Accel stops working and I have to reset the pyboard.
Can anyone help me with this?
Below is a simple block of code which already gives the problem.
Thanks!!
accel = pyb.Accel()
for i in range(1000):
print( accel.x(), accel.y(), accel.z() )
pyb.delay(50)
I'm working for a couple of days on an accelerometer data logger, and haven't been able to avoid the following problem:
- if I try to continuously retrieve Accel readings, even at very low rates (as 20Hz), after a short amount of time the readings get stuck; the Accel stops working and I have to reset the pyboard.
Can anyone help me with this?
Below is a simple block of code which already gives the problem.
Thanks!!
accel = pyb.Accel()
for i in range(1000):
print( accel.x(), accel.y(), accel.z() )
pyb.delay(50)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Accelerometer readings get "stuck" - please help
I can't reproduce this, even increasing the loop to 10,000 passes. Have you anything connected to the GPIO lines of the Pyboard? If so, please give details. How is the Pyboard powered?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Accelerometer readings get "stuck" - please help
It maybe cause by USB port or USB wire.
Re: Accelerometer readings get "stuck" - please help
Thanks pythoncoder and shaoziyang for your quick reply.
I'm using a PYBLITEv1.0-AC board. The pyboard is powered through the USB cable (and from your replies I sense this is an important point...)
In my application I'm also communicating with a GPS via UART [ pyb.UART(1, 9600) ]. I will check again if I get the accelerometer "stuck" at fixed values without the UART open.
While not actively using it in the code, I configure one pin for input [ pyb.Pin('X1', pyb.Pin.IN) ]. That's all about GPIO.
I run the example code I've sent (enough to generate the problem after a couple of seconds) via Putty.
Thanks!
I'm using a PYBLITEv1.0-AC board. The pyboard is powered through the USB cable (and from your replies I sense this is an important point...)
In my application I'm also communicating with a GPS via UART [ pyb.UART(1, 9600) ]. I will check again if I get the accelerometer "stuck" at fixed values without the UART open.
While not actively using it in the code, I configure one pin for input [ pyb.Pin('X1', pyb.Pin.IN) ]. That's all about GPIO.
I run the example code I've sent (enough to generate the problem after a couple of seconds) via Putty.
Thanks!
Re: Accelerometer readings get "stuck" - please help
even without using any GPIO, I consistently get the Accel() readings "stuck" (example below) after some iterations in the loop
the board is powered via USB, and this is the only code I'm running.
Any help/comments are appreciated. Thanks!
output example:
...
2 -1 -19
2 0 -20
3 -1 -20
4 -1 -19
-24 -20 -16
-24 -20 -16
-24 -20 -16
... (from now, stuck at this value)
Code: Select all
a = pyb.Accel()
for i in range(1000):
print( a.x(), a.y(), a.z() )
pyb.delay(20)
Any help/comments are appreciated. Thanks!
output example:
...
2 -1 -19
2 0 -20
3 -1 -20
4 -1 -19
-24 -20 -16
-24 -20 -16
-24 -20 -16
... (from now, stuck at this value)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Accelerometer readings get "stuck" - please help
I've now located a Pyboard Lite and I still can't replicate this behaviour even with 10,000 iterations of your initial code. Perhaps you have a defective board?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 5
- Joined: Mon Nov 07, 2016 2:50 am
Re: Accelerometer readings get "stuck" - please help
I have very similar problem. Accelerator readings got stuck only when I send data through serial port. As soon as I disable serial, it starts to read fine. Is there an interrupt or threading bug between serial and accelerometer?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Accelerometer readings get "stuck" - please help
OK, I've now managed to replicate this on the Pyboard Lite AC and also a Pyboard V1.0. It's surely a bug. I will raise an issue. The following script locks the accelerometer every time:
Code: Select all
accel = pyb.Accel()
uart = pyb.UART(1, 9600)
print(accel.x(), accel.y(), accel.z())
uart.write( 'hello')
for _ in range(10): # It's locked. Waggle the board around and see nothing change
pyb.delay(500)
print(accel.x(), accel.y(), accel.z())
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 5
- Joined: Mon Nov 07, 2016 2:50 am
Re: Accelerometer readings get "stuck" - please help
Thanks for reporting it. Is there a way around this? I was thinking using a multi thread to separate the UART sending process with the accel reading process. Or perhaps getting a master - slave protocol where the slave on the board will only read accel value when asked.
Will upgrading the micropython firmware to latest version fix it?
Otherwise I would need an external module to read, which is adding to the bulkiness of the board.
They should really consider adding bluetooth module as default feature in next release.
Will upgrading the micropython firmware to latest version fix it?
Otherwise I would need an external module to read, which is adding to the bulkiness of the board.
They should really consider adding bluetooth module as default feature in next release.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Accelerometer readings get "stuck" - please help
@Damien has pointed out that the accelerometer uses the same pins (I2C1: X9 and X10) as UART1. The above script works with a different UART. https://github.com/micropython/micropyt ... -258925948
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.