Accelerometer Issues?

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.
TinBane
Posts: 4
Joined: Sun Jul 20, 2014 7:16 am

Accelerometer Issues?

Post by TinBane » Sun Jul 20, 2014 7:22 am

Hi,

So I got my pyboard working on ubuntu linux. Got it running in REPL.
Linked up so that main, runs.

Got a bunch of the LED projects tested and working.

Set up this code (ignore the leds line, it's not necessary).

Code: Select all

# main.py -- put your code here!
import pyb
acc = pyb.Accel()
leds = [pyb.LED(i) for i in range(1,5)]
while True:
    print(acc.x(), acc.y(), acc.z())
    pyb.delay(1000)
So, it spits out two lines no problem, but what I find is that the values don't change at all. They are supposed to be really sensitive, but no matter how I change the pyboard's location or angle, the result appears to always be 4, 8, and 12 respectively for x, y, and z.

Am I doing something wrong?
I'll copy the code onto my second board, and test that.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Accelerometer Issues?

Post by dhylands » Sun Jul 20, 2014 5:51 pm

if I leave the Leds line in your code, I get the same behaviour (it prints the same value over and over).
If I change the range(1,5) to range(1,4) or comment out the line entirely, then it seems to work properly.

So it seems that a call to pyb.Le(4) causes the accelermeter to mess up. And, if I replace your leds line with led = pyb.Led(4) then I continuously get the same value from the accelerometer.

I'll file a bug.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Accelerometer Issues?

Post by dhylands » Sun Jul 20, 2014 6:14 pm

It seems to be this issue: https://github.com/micropython/micropython/issues/626

So it looks like you need to add a small delay after calling pyb.Accel() and before calling acc.x() for the first time.

TinBane
Posts: 4
Joined: Sun Jul 20, 2014 7:16 am

Re: Accelerometer Issues?

Post by TinBane » Sun Jul 20, 2014 11:38 pm

Does that mean that the LED(4) issue was a false correlation?
I tried on my other pyboard, and I'd taken out the LED line and it worked just fine.
The issue you linked up is interesting, but at the same time it also doesn't explain why I continue to get unchanging values. Looks like this is a new error, related to LED(4). Should I update the firmware ('m using the version they came with) and see if I can replicate it?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Accelerometer Issues?

Post by dhylands » Mon Jul 21, 2014 2:06 am

TinBane wrote:Does that mean that the LED(4) issue was a false correlation?
I'm pretty sure - yes. Putting a pyb.delay(30) after the pyb.Accel() call makes everything work properly for me.
TinBane wrote:I tried on my other pyboard, and I'd taken out the LED line and it worked just fine.
The issue you linked up is interesting, but at the same time it also doesn't explain why I continue to get unchanging values. Looks like this is a new error, related to LED(4). Should I update the firmware ('m using the version they came with) and see if I can replicate it?
I tested both with the latest firmware and with the firmware that originally shipped with the pyboard.

I think that the final solution will be to put a 30 millisecond delay inside the pyb.Accel() routine. See the discussion here:
https://github.com/micropython/micropython/issues/763

The Accelerometer doesn't always seem to need the delay (i've had it work with no delay). You may also get different behaviour the very first time you access the accelerometer after a power on, versus accessing after pressing the RESET button (which only resets the STM32F405).

TinBane
Posts: 4
Joined: Sun Jul 20, 2014 7:16 am

Re: Accelerometer Issues?

Post by TinBane » Mon Jul 21, 2014 3:10 am

So, is the problem that once you get a bad result from the accelerometer, that it won't give a proper reading afterwards?
Because it wasn't only a one off call that was failing, it was ongoing polling getting the same result.
Is that what you experienced?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Accelerometer Issues?

Post by dhylands » Mon Jul 21, 2014 3:25 am

TinBane wrote:So, is the problem that once you get a bad result from the accelerometer, that it won't give a proper reading afterwards?
Because it wasn't only a one off call that was failing, it was ongoing polling getting the same result.
Is that what you experienced?
Yeah - when it failed, I always got the same result on every read. When it failed, it wouldn't necessarily print the same 3 values as from the the last time it failed, but whatever the fist value received, it would repeat that over and over again.

PinkInk
Posts: 65
Joined: Tue Mar 11, 2014 3:42 pm

Re: Accelerometer Issues?

Post by PinkInk » Tue Jul 22, 2014 5:10 pm

If you read it too fast in a loop without a delay it also crashes within seconds.

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

Re: Accelerometer Issues?

Post by linuxcircle » Tue Nov 08, 2016 3:28 am

I am having the similar issue where I used UART via bluetooth, and do uart.write("accel x vaue = ", x).
I think there is a problem with the processor's interrupt, that it will always ready the same accel value if we do something else to other pins before of after we read the values.

So at this stage the accel value can only be printed on the screen, and not combined with LEDs, or transmitted via serial.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Accelerometer Issues?

Post by dhylands » Tue Nov 08, 2016 9:44 am

The Accelerometer uses I2C1 which is on the same pins as UART1.

So you can't use the Accelerometer and UART1 at the same time. Other UARTs won't affect the accelerometer.

Post Reply