Automationhat ADC fluctuating

I have an Automationhat connected with a raspberrypi 4 with a fresh OS installed. We initially had trouble with the python3-automationhat package saying it was not installed, but then when trying to install it manually, it says it is up to date:

    Checking environment...
    Updating apt indexes........................
    Checking hardware requirements...
    Checking for packages required for GPIO control...
    raspi-gpio is already installed
    RPi.GPIO installed and up-to-date
    I2C already enabled
    Checking packages required by I2C interface...
    Python 2 smbus installed and up-to-date
    Python 3 smbus installed and up-to-date
    Automation HAT comes with examples and documentation that you may wish to install.
    Performing a full install will ensure those resources are installed,
    along with all required dependencies. It may however take a while!
    Do you wish to perform a full install? [y/N] y
    Checking for dependencies...
    python3-sn3218 is already installed
    Installing python3-automationhat...
    install ok installed
    Installing Automation HAT library for Python 3...
    **error**: **externally-managed-environment**
    × This environment is externally managed
    ╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    For more information visit http://rptl.io/venv
    **note**: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
    **hint**: See PEP 668 for the detailed specification.
    Python 3 library install failed!
    If problems persist, visit forums.pimoroni.com for support
    **pi@raspberrypi**:**~/Pimoroni/automationhat $** sudo apt install python3-automationhat
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    python3-automationhat is already the newest version (0.2.0).
    0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

When I check the Pimoroni/automationhat/ folder, there are no example files. I created input.py:

#!/usr/bin/env python3

import time

import automationhat


if automationhat.is_automation_hat():
    automationhat.light.power.write(1)

while True:
    print(automationhat.input.read())
    print(automationhat.analog.read())
    time.sleep(0.5)

This does seem to work, but results in inconsistent input values. Also, the signal is connected on ADC 1, but the value reads on ADC 2 in the above script. This seems consistent as I connected 5v direct to ADC 2 and it shows up on ADC 3
Physically, I have 5V from the hat connected across a voltage divider with a potentiometer as the lower resister to allow changing the input (5v - 10k ohm - v output - 10k ohm pot - ground). We have verified with a multimeter that we are getting values in the 2.5v range depending on the pot position.
When I manually enter commands into the interpreter I get interesting results. The first read of the analog results in a good value, but each subsequent read results in 0.02, 4.4, 5.3, or sometimes the correct value.
Code used:

import automationhat as hat
hat.analog.one.read()

The lights on the hat are off until the first command. they are then on consistently until I exit the interpreter.
We have also tried running the Node-red module with similar results. Wildly varying values are received, but generally 0.02, 4.4, 5.3, or the actual value. In this case, the ADC number also seems to be offset.

That error message is a result of a change made in the Bookworm OS release.
Virtual Environments, Libgpiod, gpiodevice and the current mess I’m making of our Python libraries - Support - Pimoroni Buccaneers

Which is likely why things are messed up for you. One way out is to reflash your SD card and select the “Legacy OS” option. That will get you Bullseye instead of Bookworm. And the installer “should” work OK. It’s a viable option on a Pi 4.

1 Like