Skip to content

Instantly share code, notes, and snippets.

@Zixuan-Qiao
Created April 1, 2024 22:30
Show Gist options
  • Save Zixuan-Qiao/f25ea43bed34aafd33d97d12c1dca76c to your computer and use it in GitHub Desktop.
Save Zixuan-Qiao/f25ea43bed34aafd33d97d12c1dca76c to your computer and use it in GitHub Desktop.
Summary on how to setup analog input on Beaglebone Black

Beaglebone Black - Setting Up Analog Input

Beaglebone Black comes with analog input pins and analog-to-digital converter (ADC) modules. The process I followed to access these pins is documented here.

Required Hardware

Beaglebone Black, PC running on Linux system (Ubuntu ver 20.04)

Serial to USB cable, USB type A to mini B cable

Loading the ADC Device Tree Overlay

To access the analog pins, the ADC device tree overlay has to be loaded.

On the board, run the following command to check the loaded device tree overlays:

sudo beagle-version | grep UBOOT

The following line indicates that the ADC overlay is loaded.

UBOOT: Loaded Overlay:[BB-ADC-00A0.kernel]

If it is not present, check the /boot/uEnv.txt, make sure device tree overlay is enabled:

enable_uboot_overlays=1

And the ADC overlay is included:

#disable_uboot_overlay_adc=1

If you want to disable the overlay afterwards, just uncomment the line:

disable_uboot_overlay_adc=1

Reboot the system after making changes:

sudo reboot

Accessing Analog Input

After ADC device tree overlay is loaded, the /iio:device0 directory should appear under /sys/bus/iio/devices.

Switch to the directory, it should contain in_voltage0_raw to in_voltage7_raw.

To access the value:

cat in_voltage0_raw

It can also be used in user-space applications:

file_p = fopen("/sys/bus/iio/devices/iio:device0/in_voltage0_raw", "r");
fgets(buff, LENGTH, file_p);

References

  1. https://forum.beagleboard.org/t/bullseye-cant-find-files-of-opt-scripts-tools/35076/10
  2. https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
  3. https://groups.google.com/g/beagleboard/c/P_Y5yjJyuu4/m/G0J70kZoAwAJ
  4. https://askubuntu.com/questions/882433/enable-adc-input-on-beaglebone-with-4-x-kernel
  5. https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/exporting-and-unexporting-an-overlay
  6. https://www.linux.com/training-tutorials/how-get-analog-input-beaglebone-black/
  7. https://www.kernel.org/doc/html/v5.10/driver-api/iio/index.html
  8. https://elinux.org/EBC_Exercise_10a_Analog_In
  9. https://forum.beagleboard.org/t/repurposing-pins-for-gpio/37588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment