Killertechno
Posts: 139
Joined: Wed Jan 02, 2013 8:28 am

[CM3] HC-SR04 driver available?

Sun Feb 18, 2018 6:07 pm

Hy guys, I would like to connect HC-SR04 sensor to my CM3 board (I want use character device as exercise, nor Python library or similar)
My OS: Raspbian GNU/Linux 8 (jessie)
Kernel: 4.14.18
Processor: BCM2709

My old HC-SR04 driver is not working (maybe changed something in kernel/Debian), I have already enabled device-tree through raspi-config.
I've found several kernel drivers for Raspberry, but I can't compile due it's giving me some errors ( error: unknown field ‘class_attrs’ specified in initializer).
Source is https://github.com/johannesthoma/linux-hc-sro4 but using other hc-sr04 kernel driver for Raspberry I still get similar errors.
Any working driver?
Thanks.

adasek
Posts: 1
Joined: Fri Feb 23, 2018 12:06 am

Re: [CM3] HC-SR04 driver available?

Fri Feb 23, 2018 12:37 am

Hi, I encoutered a similar problem.

Solved it in https://github.com/adasek/linux-hc-sro4


My circuit: https://tutorials-raspberrypi.com/raspb ... r-hc-sr04/

Compilation
I compiled locally on Raspberry with kernel 4.14.20-v7+ - got kernel source using the guide using the guide https://raspberrypi.stackexchange.com/a/40419 (rpi-source program is the trick, don't forget to apt update, apt dist-upgrade and rpi-update before)

modified linux-hc-sro4 Makefile:

Code: Select all

obj-m += hc-sro4.o

ARCH=arm
KERNEL_DIR=/lib/modules/`uname -r`/build

all:
        make -C $(KERNEL_DIR) M=$(PWD) modules ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE)

clean:
        make -C $(KERNEL_DIR) M=$(PWD) clean ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE)
Next steps
(maybe obvious but may help someone)

Code: Select all

#inside cloned hc-sro4 with modified makefile
make
#hc-sro4.ko was created

#Load module on a startup:
 #copy into modules dir (or any subdirectory) 
 sudo cp hc-sro4.ko /lib/modules/`uname -r`/
 #append into modules.order
 sudo echo hc-sro4.ko >> /lib/modules/`uname -r`/modules.order 
 #Probe all modules
 sudo depmod -a
 #Set to startup
 sudo echo "hc-sro4" >> /etc/modules 

#One time load of a module
sudo modprobe hc-sro4

#should return something
lsmod | grep hc_sro4

#Creating a sensor
sudo echo "18 23 3000" > /sys/class/distance-sensor/configure 
#change 18 - gpio trigger, 23 - gpio echo

#Measuring
cat /sys/class/distance-sensor/distance_18_23/measure
 

Return to “Compute Module”

Who is online

Users browsing this forum: No registered users and 2 guests