The goal of this tutorial is to equip the reader with a collection of hardware and software tools for working with Power System Management devices, and more generally, devices that fall under the Linux hardware monitoring kernel API (HWMON) framework.
The tutorial will focus on using standard tools and simple examples that can be used for debug and development.
Also note that the tutorial is geared toward Linux-based systems, in contrast to bare-metal, no-OS applications. A great resource for learning about this use case is the Linduino to PSM adapter shield. The instructions for this board go over how to run several examples on the Linduino (A clone of the Arduino UNO).
This video includes installation and configuration of Kuiper Linux, as well as building and installing the development branch of the libiio with HWMON support. The video will be re-done (and re-hosted on the CftL YouTube channel) once these features are merged to master and included in a Kuiper release.
Follow the directions for downloading and burning the ADI Kuiper Linux image to the SD card:
Kuiper Linux
Remove this when overlay is merged to RPi branch and shows up in Kuiper. For the time being you will need to copy this file:
Compiled DC1962C Device Tree Overlay
to the boot/overlays directory on the SD card. This can be done from Windows, Linux, Mac.
For reference, here is the source:
DC1962C Device Tree Overlay Source
Add the following line to config.txt:
dtoverlay=rpi-dc1962c
Make the fllowing connections between the DC1962C and the Raspberry Pi, following the pin mapping in Figure 1 and corresponding photo in Figure 2.
Pin mapping diagram
Figure 1. Pin Mapping Diagram
Figure 2. Connections with Discrete Wires
When bringing up I2C devices on the Raspberry Pi (or any other processor / operating system, for that matter), it's helpful to know if devices are connected properly. The i2c-detect utility will scan all addresses on a partc I2c-detect is part of the I2C-tools package, which is pre-installed in Kuiper Linux. (It can be installed with apt-get install i2c-tools on Debian systems). The i2c-detect man page describes all options. Run:
i2cdetect -y 1
And observe the output as shown in Figure X.
Re-take screenshot with other EEPROMs on experimenter setup disabled (0x50-0x53)
Figure 4. Scanning I2C Bus 1 with i2c-detect
The LTC2974, LTC2977, and LTC3880 are at I2C addresses 0x32, 0x33, and 0x30, respectively. i2c-detect reports “UU” for these addresses because these devices are controlled from kernelspace, and users cannot access them directly. The onboard 24AA02 EEPROM is not associated with a driver. The upper nibble of the i2c address is 0x5, and the lower 3 bits select banks within the device. Externally, addresses 0x50 to 0x57 are acknowledged.
Note that no data transfer actually occurs, the i2c-detect command is simply testing which devices acknowledge, then a stop condition is issued.
ToDo: add issue to Kuiper repo - add lm-sensors
sudo apt-get install lm-sensors
sensors
sudo pip3 install hwmon
(run through some of the examples)
from hwmon import Hwmon sensors = Hwmon.HW() sensors.print_data()
Yup, this really works!
ToDo: Remove when merged to master and included in Kuiper release The libiio master branch now includes HWMON support, but is not included in the latest Kuiper release. It needs to be installed manually - but fear not, It's easy:
git clone https://github.com/analogdevicesinc/libiio.git cd libiio git checkout master mkdir build && cd build && cmake -DWITH_SYSTEMD=ON -DWITH_HWMON=ON -DWITH_EXAMPLES=ON ../ && make && sudo make install sudo reboot
iio_info
IIO Oscilloscope
Hopefully PyADI-IIO in the not too distant future
When you need to dig in deeper, use cases, noting that you have to remove the device tree overlay in order to use userspace functions.
Put together a simple python script to periodically log data from the power stick over time, and save to a local file. Show how this can be used to detect anomalies, trends toward higher operating temperatures, and other diagnostic stuff.
Show both a python HWMON example running locally, and a libiio based example that can run either locally or remotely.
Existing PSM tools are the workhorse of system design and bringup. The Linux HWMON drivers and utilities are additional tools available for run-time debug and monitoring. (obviously this conclusion needs work…)