RPi3 and Sense Hat. Missing Module

Hey,

I am trying to dockify my app on RPi3 which controls the Sense Hat. On the resin.io logs it says can’t find module RTIMU. How can I resolve the problem?

And what is the difference between installing dependencies vs install requirements in the Docker Template?

hey @gh_touloupas can you post your dockerfile here? What language are you trying to use the sensehat in? we have a few examples:

1 Like
FROM resin/%%RESIN_MACHINE_NAME%%-python


RUN apt-get update && apt-get install -yq \
    python3=3.4.2-2 sense-hat raspberrypi-bootloader i2c-tools && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app


COPY ./requirements.txt /requirements.txt

RUN apt-get update && \
apt-get install -yq --no-install-recommends \
  build-essential libssl-dev libffi-dev libyaml-dev python3-dev python3-pip && \
pip3 install -r requirements.txt && \
apt-get remove \
  build-essential libssl-dev libffi-dev libyaml-dev python3-dev python3-pip \
&& apt-get autoremove && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY . ./

ENV INITSYSTEM on

CMD modprobe i2c-dev && python src/main.py

Looks like you may be actually just missing RTIMU? Just saw this: https://github.com/RPi-Distro/python-sense-hat/issues/58
You could try adding the install steps from https://github.com/RPi-Distro/RTIMULib/tree/master/Linux/python to your Dockerfile.

It’s also potentially problematic that you’re starting from a python base image and installing a specific python - might be better to start from plain resin/raspberrypi3-debian:jessie ?

1 Like

Thanks for helping. Also I have one more question. What’s the difference between installing from requirements.txt and installing dependencies on a DockerFile? I am trying to find out more about resin.io.

There is no difference although using requirements.txt is nicer as it separates any dependencies from your Dockerfile.

1 Like

Thanks everyone, you were very helpful. Consider this topic closed.

@gh_touloupas

I’ve been playing with RPi4, with the Balena team helping with some rough egdes.

Here is a multi-step docker container which trims down the final output size and which also fixes the problem with RTIMU module with building on local build layer then moving to the app layer. I’ve got final size trimmed down by half (probably could be better):

# See more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.7.3-stretch-build as builder
# Always set a working directory
WORKDIR /app
# Sets utf-8 encoding for Python
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Make sure we use the virtualenv:
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Use `install_packages` if you need to install dependencies
RUN pip install -U pip && \
    pip install -U wheel && \
    pip install -U numpy && \
    pip install -U pillow
# RTIMU library fix
RUN git clone https://github.com/RPi-Distro/RTIMULib/ RTIMU
WORKDIR /app/RTIMU/Linux/python
RUN python setup.py build && \
    python setup.py install
# reset working directory
WORKDIR /app
# This will copy all files in our root to the working  directory in the container
COPY requirements.txt ./
RUN pip install -U --no-cache-dir -r requirements.txt

# Trimmed down app container
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian-python:3.7.3-stretch-run as app
# Extra python env
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Use `install_packages` if you need to install dependencies
RUN install_packages libjpeg62-turbo-dev
# Make sure we use the virtualenv:
COPY --from=0 /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Always set a working directory
WORKDIR /app
# This will copy all files in our root to the working  directory in the container
COPY . ./
# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1
# main.py will run when container starts up on the device
CMD ["python", "-u", "src/main.py"]

It uses virtuanl env to sharing dependencies between Docker builders. Only single dependency libjpeg62-turbo-dev is required on the app container. It assumes using Python 3.

It should work without a change on RPi3, as the template is using variables for targets.

hth!