Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module_upload=${MODULE}.ko
all: clean compile dht22-overlay.dtbo

dht22-overlay.dtbo:
dtc -I dts -O dtb -o dht22.dtbo dht22-overlay.dts
dtc -I dts -O dtb -o dht22.dtbo dht22-overlay.dts

compile:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
Expand All @@ -19,6 +19,17 @@ clean:
# this just copies a file to raspberry
#install:
# scp ${module_upload} pi@raspberry:test/

# This will only work if compiling on the pi
install:
cp ${MODULE}.ko /lib/modules/$(shell uname -r)/kernel/drivers/iio/humidity/
cp ${MODULE}.dtbo /boot/overlays/
depmod -a

uninstall:
rm -fv /lib/modules/$(shell uname -r)/kernel/drivers/iio/humidity/${MODULE}.ko
rm -fv /boot/overlays/${MODULE}.dtbo


info:
modinfo ${module_upload}
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ Do not forget to make a "depmod -a".

At the moment the driver is in a early beta stage.
But you should not get read errors.


## Install using make
Clone repo
cd to repo directory
run ```make```
run ```make install``` to place the necessary files in the kernel modules directory and /boot/overlays
reboot

You can verify that it is working correctly by running this command, which should show similar output
```
# cat /sys/devices/platform/dht22\@0/iio\:device0/in_humidityrelative_input
59.400000000
```
23 changes: 11 additions & 12 deletions dht22.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/delay.h>
#include <linux/ktime.h>

#include <linux/platform_device.h>
#include <linux/iio/iio.h>
Expand All @@ -43,7 +44,7 @@
// to generate interrupt
#define GPIO_ANY_GPIO 4
#define GPIO_ANY_GPIO_DESC "gpio pin used for DHT22"
#define GPIO_ANY_GPIO_DEVICE_DESC "Read temperature and huminity"
#define GPIO_ANY_GPIO_DEVICE_DESC "Read temperature and humidity"
#define DHT22_CONST_SCALE 1
#define DHT22_CONST_SCALE2 10

Expand Down Expand Up @@ -308,7 +309,7 @@ static int proc_show(struct seq_file *m, void *v)
{
short int h;
short int t;
struct timeval tv;
ktime_t tv;

// Read sensor
send_start_bit();
Expand All @@ -318,15 +319,15 @@ static int proc_show(struct seq_file *m, void *v)
check_measurement();
}

tv = ktime_to_timeval((dht22->read_timestamp));
tv = ktime_get();
t = get_temperature();
h = get_humidity();

seq_printf(m, "DHT22 on gpio pin %d:", GPIO_ANY_GPIO);
seq_printf(m, "\n");
seq_printf(m, " temperature = %d.%1d° C\n", t / 10, t % 10);
seq_printf(m, " humidity = %d.%1d%% RH\n", h / 10, h % 10);
seq_printf(m, " timestamp = %ld\n", (long)tv.tv_sec);
seq_printf(m, "timestamp = %lli", tv);
seq_printf(m, dht22-> chksum_ok ? " no checksum error\n" : " checksum error !\n");
return 0;
}
Expand All @@ -338,12 +339,11 @@ static int proc_open(struct inode *inode, struct file *file)
}

static struct proc_dir_entry *proc_dir, *proc_file;
static const struct file_operations proc_fileops = {
.owner = THIS_MODULE,
.open = proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
static const struct proc_ops proc_fileops = {
.proc_open = proc_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};

static void proc_init(void)
Expand Down Expand Up @@ -431,7 +431,6 @@ static int read_raw(struct iio_dev *iio_dev,
/* iio_dev variables block */
/****************************************************************************/
static const struct iio_info dht22_iio_info = {
.driver_module = THIS_MODULE,
.read_raw = read_raw,
};

Expand Down Expand Up @@ -513,7 +512,7 @@ static int probe_dht22(struct platform_device *pdev)
free_iio_gpio:
devm_gpio_free(dev, dht22_idev->gpio);
free_iio_device:
devm_iio_device_free(dev, iio);
devm_iio_device_alloc(dev, iio);
return (ret);
}

Expand Down