Hello!
i'm trying to read data from a dht22 sensor
i'm using this document to help me understand how to talk to it
i managed to do the start sequence and read some bits however some bits are missing
in the code below, i kept only the parts to get a delta time between each iteration
here is the snipped of the output :
as you can see i never get under 28us so it will be hard to get sensor output bit for value 1.
also if it can help i'm using a msys2 gcc compiler on windows and serial over usb.
i also find another way of doing what i want in the pico c sdk (page 395-396) but i keep getting "bad data" sa the output. i think this is still due to the fact that the pico is missing some bits so the checksum is wrong
i think most of the slowness comes from the printf and the fact that i'm using serial over usb. am i correct and is there any way to be able to read the bits on time ?
i'm trying to read data from a dht22 sensor
i'm using this document to help me understand how to talk to it
i managed to do the start sequence and read some bits however some bits are missing
in the code below, i kept only the parts to get a delta time between each iteration
Code:
#include <stdio.h>#include "pico/stdlib.h"#include "hardware/gpio.h"#include "pico/time.h"int main() { stdio_init_all(); // sleep_ms(2000); // gpio_init(4); // gpio_set_dir(4, GPIO_OUT); // gpio_put(4, 1); // gpio_put(4, 0); // sleep_ms(1); // gpio_put(4, 1); // sleep_us(30); // gpio_put(4, 0); // gpio_set_dir(4, GPIO_IN); absolute_time_t previous = get_absolute_time(); absolute_time_t current = previous; int64_t delta = 0; // uint previous_pin_value = gpio_get(4); // uint current_pin_value = previous_pin_value; for (;;) { current = get_absolute_time(); delta += absolute_time_diff_us(previous, current); printf("delta: %lld\n", delta); delta = 0; // current_pin_value = gpio_get(4); // if (previous_pin_value != current_pin_value) { // printf("previous pin value : %u lasted %lld\n", previous_pin_value, delta); // previous_pin_value = current_pin_value; // delta = 0; // } previous = current; }}
Code:
delta: 144delta: 53delta: 42delta: 39delta: 38delta: 39delta: 41delta: 47delta: 80delta: 44delta: 40delta: 38delta: 40delta: 39delta: 39delta: 40delta: 44delta: 42delta: 40delta: 40delta: 40delta: 84delta: 59delta: 47delta: 40delta: 39delta: 40delta: 41delta: 40delta: 40delta: 71delta: 50delta: 43delta: 41delta: 39delta: 42delta: 40delta: 42delta: 45delta: 40delta: 40delta: 187delta: 50delta: 40delta: 41delta: 40delta: 46delta: 199delta: 50delta: 43delta: 39delta: 40delta: 392delta: 54delta: 42delta: 41delta: 40delta: 42delta: 215delta: 49delta: 41delta: 41delta: 39delta: 40delta: 253delta: 50delta: 75delta: 40delta: 39delta: 44delta: 40delta: 39delta: 41delta: 41delta: 41delta: 79delta: 46delta: 41delta: 41delta: 40delta: 41delta: 382delta: 46delta: 45delta: 41delta: 39delta: 41delta: 206delta: 50delta: 41delta: 41delta: 41delta: 43delta: 363delta: 52delta: 40delta: 40delta: 41delta: 233delta: 49delta: 44delta: 43delta: 41delta: 40delta: 376delta: 48delta: 42delta: 42delta: 39delta: 41delta: 206delta: 47delta: 41delta: 41delta: 40delta: 44delta: 372delta: 46delta: 41delta: 41delta: 40delta: 240delta: 46delta: 39delta: 42delta: 40delta: 41delta: 383delta: 47delta: 39delta: 41delta: 40delta: 41delta: 201delta: 49delta: 40delta: 40delta: 40delta: 43delta: 380
also if it can help i'm using a msys2 gcc compiler on windows and serial over usb.
i also find another way of doing what i want in the pico c sdk (page 395-396) but i keep getting "bad data" sa the output. i think this is still due to the fact that the pico is missing some bits so the checksum is wrong
i think most of the slowness comes from the printf and the fact that i'm using serial over usb. am i correct and is there any way to be able to read the bits on time ?
Statistics: Posted by inco2508 — Mon Jun 24, 2024 11:11 pm — Replies 1 — Views 35