Accelerometer readings get "stuck" - please help

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Paulo
Posts: 4
Joined: Sat Oct 29, 2016 9:22 pm

Accelerometer readings get "stuck" - please help

Post by Paulo » Sat Oct 29, 2016 9:37 pm

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)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accelerometer readings get "stuck" - please help

Post by pythoncoder » Sun Oct 30, 2016 7:11 am

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.

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: Accelerometer readings get "stuck" - please help

Post by shaoziyang » Sun Oct 30, 2016 7:32 am

It maybe cause by USB port or USB wire.

Paulo
Posts: 4
Joined: Sat Oct 29, 2016 9:22 pm

Re: Accelerometer readings get "stuck" - please help

Post by Paulo » Sun Oct 30, 2016 3:37 pm

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!

Paulo
Posts: 4
Joined: Sat Oct 29, 2016 9:22 pm

Re: Accelerometer readings get "stuck" - please help

Post by Paulo » Mon Oct 31, 2016 11:04 pm

even without using any GPIO, I consistently get the Accel() readings "stuck" (example below) after some iterations in the loop

Code: Select all

a = pyb.Accel()
for i in range(1000):
    print( a.x(), a.y(), a.z() )
    pyb.delay(20)
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)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accelerometer readings get "stuck" - please help

Post by pythoncoder » Tue Nov 01, 2016 8:44 am

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.

linuxcircle
Posts: 5
Joined: Mon Nov 07, 2016 2:50 am

Re: Accelerometer readings get "stuck" - please help

Post by linuxcircle » Mon Nov 07, 2016 2:53 am

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? :cry:

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accelerometer readings get "stuck" - please help

Post by pythoncoder » Mon Nov 07, 2016 8:05 am

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.

linuxcircle
Posts: 5
Joined: Mon Nov 07, 2016 2:50 am

Re: Accelerometer readings get "stuck" - please help

Post by linuxcircle » Tue Nov 08, 2016 2:55 am

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. :geek:

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Accelerometer readings get "stuck" - please help

Post by pythoncoder » Tue Nov 08, 2016 6:20 am

@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.

Post Reply