Hi, Dennis Lee Bieber

Thanks for the valuable effort but i am unaware of the python language and 
hence it would be really appreciable if you could provide me your help in 
C/C++ language only.

On Tuesday, March 22, 2016 at 10:47:45 AM UTC+5:30, Sumit Bhut wrote:
>
> Hello friends, 
>
> I'm compilited this code for interface BBB with DHT11(temperature-humidity 
> sensor) this code is compiled and run successfully but OUTPUT 
> is 
> *0'c temperature - 0% humidity ....Plz *, find error this code...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *Code-#include <stdio.h>#include <stdlib.h>#include <string.h>#include 
> <time.h>#include <stdint.h>#include <sys/time.h>#include <unistd.h>#define 
> MAXTIMINGS    85#define DHTPIN        48int dht11_dat[5] = { 0, 0, 0, 0, 0 
> };void inputdirection(int pin);int readpin(int pinnum);void 
> outputdirection();void writepin(int pinnum, int value);void pauseSec(int 
> sec);void pauseNanoSec(long nano);void outputdirection(){        char 
> buf[10];        char buf2[50] = "/sys/class/gpio/gpio";            FILE 
> *in,*indir;                in = fopen("/sys/class/gpio/export", "w");    
>                 fseek(in,0,SEEK_SET);                        
> fprintf(in,"%d",48);                            fflush(in);                
>                                                 sprintf(buf,"%i",48);    
>                                 strcat(buf2,strcat(buf,"/direction"));    
>                                     indir = fopen(buf2, "w");            
>                                 fseek(indir,0,SEEK_SET);                    
>                             fprintf(indir,"out");                        
>                             fflush(indir);                                
>                         fclose(in);                                        
>                     fclose(indir);}void inputdirection(int pin){        
> char buf[10];        char buf2[50] = "/sys/class/gpio/gpio";        FILE 
> *in,*indir;            in = fopen("/sys/class/gpio/export", "w");        
>         fseek(in,0,SEEK_SET);                    fprintf(in,"%d",48);    
>                     fflush(in);                                            
>             sprintf(buf,"%i",48);                                
> strcat(buf2,strcat(buf,"/direction"));                                    
> indir = fopen(buf2, "w");                                        
> fseek(indir,0,SEEK_SET);                                            
> fprintf(indir,"in");                                                
> fflush(indir);                                                    
> fclose(in);                                                        
> fclose(indir);}int readpin(int pinnum){    int value;        FILE 
> *inval;                inval = fopen("/sys/class/gpio/gpio48/value", 
> "r");                        fseek(inval,0,SEEK_SET);                    
>             fscanf(inval,"%d",&value);                                    
>     fclose(inval);                                        return value;}    
> void writepin(int pinnum, int value){        FILE *val;            char 
> buf[5];                char buf2[50] = "/sys/class/gpio/gpio";            
>         sprintf(buf,"%i",pinnum);                        
> strcat(buf2,strcat(buf,"/value"));                            val = 
> fopen(buf2, "w");                                fseek(val,0,SEEK_SET);    
>                                 fprintf(val,"%d",value);                    
>                     fflush(val);                                            
> fclose(val);}void pauseSec(int sec){        time_t now,later;            
> now = time(NULL);                later = time(NULL);                    
> while((later - now) < (double)sec)                                later = 
> time(NULL);}void pauseNanoSec(long nano){        struct timespec tmr1;    
>         tmr1.tv_sec = 0;                tmr1.tv_nsec = nano;                
>     }  void read_dht11_dat(){    uint8_t laststate    = 1;    uint8_t 
> counter        = 0;    uint8_t j        = 0, i;    float    f; /* 
> fahrenheit */     dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] 
> = dht11_dat[4] = 0;     /* pull pin down for 18 milliseconds */    
> outputdirection();    writepin(48,0);    usleep(18000);    /* then pull it 
> up for 40 microseconds */    writepin(48,1);        usleep(40);    /* 
> prepare to read the pin */    inputdirection(48);     /* detect change and 
> read data */    for ( i = 0; i < MAXTIMINGS; i++ )    {        counter = 
> 0;        while ( readpin(48) == laststate )        {            
> counter++;            usleep( 1 );            if ( counter == 255 )        
>     {                break;            }        }        laststate = 
> readpin(48);         if ( counter == 255 )            break;         /* 
> ignore first 3 transitions */        if ( (i >= 4) && (i % 2 == 0) )        
> {            /* shove each bit into the storage bytes */            
> dht11_dat[j / 8] <<= 1;            if ( counter > 16 )                
> dht11_dat[j / 8] |= 1;            j++;        }    }     /*     * check we 
> read 40 bits (8bit x 5 ) + verify checksum in the last byte     * print it 
> out if data is good     */    /*if ( (j >= 40) &&         (dht11_dat[4] == 
> ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) 
> )    {*/        f = dht11_dat[2] * 9. / 5. + 32;        printf( "Humidity = 
> %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",            dht11_dat[0], 
> dht11_dat[1], dht11_dat[2], dht11_dat[3], f );    /*}else  {        printf( 
> "Data not good, skip\n" );    }*/}int main()    {        while ( 1 )    
> {        read_dht11_dat();    pauseSec( 1 ); /* wait 1sec to refresh */    
> }     return(0);}* 
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to