Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » HOW TO READ DHT22 WITH C1000??(THE OUTPUT ON SERIAL MONITOR IS ZERO, PLEASE TELL ME WHAT SHOULD I DO OR CORRECT IT)
HOW TO READ DHT22 WITH C1000?? [message #1775646] Thu, 02 November 2017 14:46 Go to next message
fahmi rosnan is currently offline fahmi rosnanFriend
Messages: 1
Registered: November 2017
Junior Member
Why it didn't show any value or reading from the sensor (dht22)?
How to read the raw value from digital pin?

#include "qm_gpio.h" //Calling QMSI GPIO API
#include "clk.h"
#include "qm_pinmux.h"
#include "qm_pin_functions.h"


#define PIN_DHT22 21
#define LED_PIN_ID (QM_PIN_ID_55)
#define PIN_MUX_FN (QM_PIN_55_FN_GPIO_21)


//static qm_gpio_state_t {QM_GPIO_HIGH};


uint32_t expectPulse(_Bool level) /*function to read DHT11 pulse*/
{
uint32_t count = 0;
while (qm_gpio_read_pin(QM_GPIO_0, PIN_DHT22, QM_GPIO_LOW) == level)
{
if (count++ >= 100000)
{ /* 1 millisecond to read DHT11 pulse */
return 0; /* Exceeded timeout, fail. */
}
}
return count;
}


static void pin_mux_setup(void)
{
qm_pmux_select(LED_PIN_ID, PIN_MUX_FN);
}




int main()
{
qm_gpio_port_config_t cfg;
pin_mux_setup();


uint32_t cycles[80], i; /* same cycle number as in the DHT11 library */
uint8_t data[5];


/* Reset 40 bits of received data to zero. */
data[0] += data[1] += data[2] += data[3] += data[4] = 0;
QM_PUTS("DHT22 example");


while(1)
{
// Act like Arduino's pinMode
//DHT in as O/P.
cfg.direction = BIT(PIN_DHT22);
qm_gpio_set_config(QM_GPIO_0, &cfg);


qm_gpio_set_pin(QM_GPIO_0, PIN_DHT22); /* set HIGH to DHT11 pin */
clk_sys_udelay(250000); /* 250 ms */


//Send DHT start signal
qm_gpio_clear_pin(QM_GPIO_0, PIN_DHT22); /* set DHT11 pin LOW */
clk_sys_udelay(20000); /* 20 ms */


qm_gpio_set_pin(QM_GPIO_0, PIN_DHT22); /* set DHT11 pin HIGH */
clk_sys_udelay(40); /* 40 us */


cfg.direction = 0;
qm_gpio_set_config(QM_GPIO_0, &cfg); //Setting the DHT11 pin as I/P to


//start listening from sensor
qm_gpio_clear_pin(QM_GPIO_0, PIN_DHT22);
clk_sys_udelay(10); //10 us


if(!expectPulse(false))
{
QM_PUTS("Timeout waiting for start signal low pulse.");
//continue;
}


if(!expectPulse(true))
{
QM_PUTS("Timeout waiting for start signal high pulse.");
//continue;
}


for (i=0; i<80; i+=2)
{
cycles[i] = expectPulse(0);
cycles[i+1] = expectPulse(1);
}


// Inspect pulses and determine which ones are 0 (high state cycle count < low
// state cycle count), or 1 (high state cycle count > low state cycle count).
for (i=0; i<40; ++i)
{
uint32_t lowCycles = cycles[2*i];
uint32_t highCycles = cycles[2*i+1];


if ((lowCycles == 0) || (highCycles == 0))
{
QM_PUTS("Timeout waiting for pulse.");
//continue ;
}
data[i/8] <<= 1;


//Now compare the low and high cycle times to see if the bit is a 0 or 1
if (highCycles > lowCycles)
{
// High cycles are greater than 50us low cycle count, must be a 1
data[i/8] |= 1;
}


// Else high cycles are less than (or equal to, a weird case) the 50us low
// cycle count so this must be a zero. Nothing needs to be changed in the
// stored data.
}


QM_PRINTF("Receive %d %d %d %d %d\n",data[0],data[1],data[2],data[3],data[4]);
uint8_t TempF = data[2]*1.8+32;
QM_PRINTF("h : %d, t : %d, f : %d \n", data[0],data[2],TempF);
QM_PRINTF("h: %d , data:%d \n", data[0], data[1]);


//Check we read 40 bits and that the checksum matches
if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF))
{


}
else
{
QM_PUTS("Checksum failure!");
}
}
return 0;
}
  • Attachment: 2.JPG
    (Size: 59.74KB, Downloaded 31 times)
  • Attachment: 1.JPG
    (Size: 41.79KB, Downloaded 33 times)
Re: HOW TO READ DHT22 WITH C1000?? [message #1775662 is a reply to message #1775646] Thu, 02 November 2017 21:12 Go to previous message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

This forum is for questions about the Eclipse Kura framework. If you would like to try reading data from your sensor using Eclipse Kura, we can try to help. Here [1] are examples of using Kura to read GPIO pins.

[1] https://github.com/eclipse/kura/tree/develop/kura/examples/org.eclipse.kura.example.gpio

Thanks,
--Dave
Previous Topic:The Bluetooth Le bundle sends gives same values for sensor data
Next Topic:Any PDF format user manual
Goto Forum:
  


Current Time: Mon Nov 19 09:07:52 GMT 2018

Powered by FUDForum. Page generated in 0.01579 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top