question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All sensors output 0.0

See original GitHub issue

Greetings,

I’m just getting started with the sense hat and am likely doing something wrong. I was working through this guide and controlling the LEDs was going great. I moved on to try the accelerometer example and just get zeros.

$ cat acc-example.py
from sense_hat import SenseHat

sense = SenseHat()

while True:
    acceleration = sense.get_accelerometer_raw()
    x = acceleration['x']
    y = acceleration['y']
    z = acceleration['z']

    x=round(x, 0)
    y=round(y, 0)
    z=round(z, 0)

    print("x={0}, y={1}, z={2}".format(x, y, z))

When running the above, I just get this:

$ python acc-example.py 
x=0.0, y=0.0, z=0.0
x=0.0, y=0.0, z=0.0
x=0.0, y=0.0, z=0.0
x=0.0, y=0.0, z=0.0
...

Examples from the prompt showing other sensor behavior:


$ python
Python 3.6.2 (default, Jul 22 2017, 21:19:22) 
[GCC 7.1.1 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sense_hat import SenseHat
>>> s = SenseHat()
>>> s.set_imu_config(True, True, True) ## just to be sure

>>> s.get_orientation_radians()
{'roll': 0.0, 'pitch': -0.0, 'yaw': -0.0}

>>> s.get_compass()            
-0.0

>>> s.get_gyroscope()
{'roll': 0.0, 'pitch': -0.0, 'yaw': -0.0}

>>> s.get_accelerometer_raw()
{'x': 0, 'y': 0, 'z': 0}

I’m using arch ARM.

$ cat /boot/config.txt 
# See /boot/overlays/README for all available options

gpu_mem=128
initramfs initramfs-linux.img followkernel

start_file=start_x.elf
fixup_file=fixup_x.dat

dtparam=i2s=on
dtparam=spi=on
dtparam=i2c_arm=on
dtoverlay=rpi-sense

$ cat /etc/modules-load.d/raspberrypi.conf 
snd-bcm2835
i2c-dev
bcm2835-v4l2

Does anything look awry above, or would you have tips on finding out what’s wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bsimmocommented, Nov 1, 2020

Does this help, notice the blacklist (ubuntu user) https://github.com/J-Pai/EnvTrackerNode

On Sun, 1 Nov 2020 at 14:03, fjctp notifications@github.com wrote:

I am encountering the same issue. I am running Ubuntu Server 20.04.1. It is a fresh install. Issues

  1. I got this error when I run get_temperature(), get_humidity(), or get_pressure().

OSError: XXXX Init Failed

  1. I got zeros reading when I run get_accelerometer_raw(), get_gyroscope(), and get_compass()

Debug steps

  1. Check if i2c is working

ubuntu@ubuntu:~$ ls -al /dev/i2c-1 crw-rw---- 1 root i2c 89, 1 Apr 1 2020 /dev/i2c-1

ubuntu@ubuntu:~$ cat /boot/firmware/syscfg.txt

This file is intended to be modified by the pibootctl utility. User

configuration changes should be placed in β€œusercfg.txt”. Please refer to the

README file for a description of the various configuration files on the boot

partition.

enable_uart=1 dtparam=audio=on dtparam=i2c_arm=on dtparam=spi=on cmdline=cmdline.txt

ubuntu@ubuntu:~$ i2cdetect -F 1 Functionalities implemented by /dev/i2c-1: I2C yes SMBus Quick Command yes SMBus Send Byte yes SMBus Receive Byte yes SMBus Write Byte yes SMBus Read Byte yes SMBus Write Word yes SMBus Read Word yes SMBus Process Call yes SMBus Block Write yes SMBus Block Read no SMBus Block Process Call no SMBus PEC yes I2C Block Write yes I2C Block Read yes

ubuntu@ubuntu:~$ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: – – – – – – – – – – – – – 10: – – – – – – – – – – – – UU – – – 20: – – – – – – – – – – – – – – – – 30: – – – – – – – – – – – – – – – – 40: – – – – – – UU – – – – – – – – – 50: – – – – – – – – – – – – UU – – 5f 60: – – – – – – – – – – 6a – – – – – 70: – – – – – – – –

  1. add user to i2c group

sudo addgroup ubuntu input sudo addgroup ubuntu i2c

Tried to access sensor data with sudo python3 test_script.py. Still had the same issues 2.

Build RTIMULib from source

git clone https://github.com/RPi-Distro/RTIMULib cd RTIMULib/Linux/python python setup.py build python setup.py install

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/astro-pi/python-sense-hat/issues/79#issuecomment-720093486, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN4X3RQCAAZ4OXZH6YDSNVTCJANCNFSM4D4IBPWQ .

0reactions
jwhendycommented, Jan 11, 2021

K. Confirming blacklist matters on arch as well.

$ lsmod |grep st_
st_pressure_spi        16384  0
st_magn_spi            16384  0
st_sensors_spi         16384  2 st_pressure_spi,st_magn_spi
regmap_spi             16384  2 st_sensors_spi,hts221_spi
st_pressure_i2c        16384  0
st_magn_i2c            16384  0
st_pressure            16384  2 st_pressure_spi,st_pressure_i2c
st_magn                16384  2 st_magn_i2c,st_magn_spi
st_sensors_i2c         16384  2 st_magn_i2c,st_pressure_i2c
st_sensors             24576  6 st_magn_i2c,st_pressure_spi,st_pressure,st_magn_spi,st_pressure_i2c,st_magn
industrialio_triggered_buffer    16384  3 hts221,st_pressure,st_magn
industrialio           73728  10 hts221,st_magn_i2c,st_sensors,st_pressure_spi,st_pressure,st_magn_spi,st_pressure_i2c,industrialio_triggered_buffer,st_magn,kfifo_buf

Woohoo, I think this can actually be closed! tl;dr for the future:

  • blacklist modules as described at EnvTrackerNode
  • in addition to checking /etc/udev/rules.d/* for /dev/i2c-1 access, also consider the i2c group method referenced here. A symptom of this will be the ability to run the EnvTrackerNode/scripts/sense_hat_demo.py only as root/with sudo
  • tbd: whether or not building RTIMULib and python-sense-hat are required vs. installing packages, which I’ll leave to someone else to test
Read more comments on GitHub >

github_iconTop Results From Across the Web

When reading from multiple sensors i get all values to 0.0 ...
I want to collect Accelerometer,Accelerometer (Without Gravity) and Gyroscope data from my phone and send it to a TCP socket in my PC....
Read more >
Products | All Sensors
The CPM 502 Series offers a ceramic, media isolated pressure sensor with ... Offset, - 0.4 to 0.0 mV/V (Other nominal values available...
Read more >
PM Sensor always reading 0.0 - #24 by victor - Hardware
When I ask for a reading on the CLI, I see the fan on the PM sensor spin. Some CLI output, including version,...
Read more >
ADXL362 output data "0.0,0" - Q&A - MEMS Inertial Sensors
The ADXL362 Acceleration Sensor is continuously generating 0,0,0 data during operation even on activation status. ("0,0,0" data come out all ...
Read more >
lm_sensors - ArchWiki
Users wish to rename the output of some sensors. The cores might be displayed in an incorrect order. All of the above (and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found