Interfacing hx711 with beaglebone black using embedded linux

 

In this post i am going to explain how to interfacing hx711 with beaglebone black using embedded linux. Hx711 is a low cost 24 bit adc, with low-noise programmable gain amplifier (PGA). It is designed for designed for weigh scales application. You can buy hx711 module  for $2  on amazon or other on line stores. Sampling rate can be programmed through hardware, though only 10 SPS and 80 SPS. It is enough for most of the  simple application where we do not need that much sampling rate. I will try to keep it generic so that you can apply it to any other SBC.

Interfacing hx711 with beaglebone
HX711

Wiring

One side you need to connect it to sesnor and the other side to beaglebone black. There are four wires you need to connect it to beaglebone black.

GND—>P9_1

DT  —>P8_7

SCK—>P8_8

VCC—>P9_3

 

Compiling the driver built into the kernel

For Interfacing hx711 with beaglebone black you need to build linux with hx711 device driver. Fortunately there is a linux driver available for hx711.It uses Industrial I/O subsystem (IIO). We need to compile it with the kernel. First you need to know how build embedded linux using mailine kernel. You can follow my  previous post to do that. For building embedded linux with hx711 driver you need to go to menucofig and select the driver.

Go to linux directory and type the below command.

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

First you need to go to Device Drivers.

Interfacing hx711 with beaglebone

Then you need to navigate to Industrial I/O support. Here you need to built into kernel. For that you need to mark it is as ‘*’.

Interfacing hx711 with beaglebone

Here select AVIA HX711 ADC for weight cells. After selecting hx711, save it and exit.

Interfacing hx711 with beaglebone

 

Device tree  to add hx711

For beaglebone black you need to edit the am335x-boneblack.dts file to add pimuxing.

/*
 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
/dts-v1/;
/plugin/;

#include "am33xx.dtsi"
#include "am335x-bone-common.dtsi"
#include "am335x-bonegreen-common.dtsi"

/ {
	model = "TI AM335x BeagleBone Green";
	compatible = "ti,am335x-bone-green", "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";

	    weight@0 {

		pinctrl-names = "default";
		pinctrl-0 = <&weight_pins>;


		compatible = "avia,hx711";
		sck-gpios = <&gpio2 3 GPIO_ACTIVE_HIGH>;
		dout-gpios = <&gpio2 2 GPIO_ACTIVE_HIGH>;
		avdd-supply =  <&vmmcsd_fixed>;
		
	};


};

&am33xx_pinmux {
		weight_pins: pinmux_weight_pins {
				pinctrl-single,pins = <
					0x090 0x37	
					0x094 0x17	
				>;
			};

		};

	
&epwmss1 {
	status = "okay";
};

&ehrpwm1 {
	status = "okay";
};

 

After modifying the dts fiel you need to build linux and copy the uImage and am335x-boneblack.dtb file as explained in the previous post.

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage dtbs LOADADDR=0x80008000 -j4

 

After copying the files to sd card, plug it into the beaglebone black and power it on. You should see this in dmesg.

[    1.895671] hx711-gpio weight@0: GPIO lookup for consumer sck
[    1.905267] hx711-gpio weight@0: using device tree for GPIO lookup
[    1.912082] of_get_named_gpiod_flags: parsed 'sck-gpios' property of node '/weight@0[0]' - status (0)
[    1.921918] hx711-gpio weight@0: GPIO lookup for consumer dout
[    1.928084] hx711-gpio weight@0: using device tree for GPIO lookup
[    1.934560] of_get_named_gpiod_flags: parsed 'dout-gpios' property of node '/weight@0[0]' - status (0)

 

Usage

You can navigate to /sys/devices/platform. You can see the weight@0 folder.

# cd /sys/devices/platform/
#ls
Fixed MDIO bus.0/  leds/              pmu/               soc/
alarmtimer/        ocp/               power/             weight@0/
cpufreq-dt/        opp-table/         reg-dummy/
fixedregulator0/   oprofile-perf.0/   serial8250/

Navigate into the weight@0/iio:device0 folder. Here you will find in_volatge0_raw, in_voltage1_raw.

# cd /sys/devices/platform/weight@0/
# ls
driver           iio:device0      of_node          subsystem
driver_override  modalias         power            uevent
# cd iio\:device0/
# ls
dev                          name
in_voltage0_raw              of_node
in_voltage0_scale_available  power
in_voltage1_raw              subsystem
in_voltage1_scale_available  uevent
in_voltage_scale
# pwd
/sys/devices/platform/weight@0/iio:device0

You can read the adc value of first channel.

# cat in_voltage0_raw 
8383998

Output data rate can be controlled by connecting pin 15 (RATE) to either 0(GND) or 1(+3.3V). Hope this article helped you with interfacing hx711 with beaglebone black. In the coming post i will explain the hx711 driver and device tree binding  in detail.


Leave a Reply

Your email address will not be published. Required fields are marked *