Cooking Hacks Forum
https://www.cooking-hacks.com/forum/

Raspberry Pi to Arduino shields connection bridge and DHT11
https://www.cooking-hacks.com/forum/viewtopic.php?f=37&t=4243
Page 1 of 1

Author:  farruzzoli [ Wed Nov 13, 2013 2:34 am ]
Post subject:  Raspberry Pi to Arduino shields connection bridge and DHT11

Hi i have an Arduino shields connection bridge on my raspberry and i'm trying to compile this code:

#include "arduPi.h"
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);


int uscita=0;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
Serial.println("DHTxx test!");
dht.begin();

}

// the loop routine runs over and over again forever:
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}

uscita=1;
// wait for a second
}



int main (){
setup();
while(uscita==0){
loop();
}
return (0);
}

but the result is :


pi@raspberrypi /usr/ardupi $ g++ -lrt -lpthread gettempumid.cpp arduPi.o -o gettempumid
In file included from gettempumid.cpp:2:0:
DHT.h:6:23: fatal error: WProgram.h: No such file or directory
compilation terminated.

in the same directory there the dht library :DHT.cpp and DHT.h

where is WProgram.h ?? how can i compile my code ? where i can found an example of dht sensor compiled with Arduino shields connection bridge ?

Any a suggestion ?

Thanks.

Author:  robans [ Wed Nov 13, 2013 4:33 pm ]
Post subject:  Re: Raspberry Pi to Arduino shields connection bridge and DH

Hi farruzzoli,
I have the same problem and I tried various ways, but i think these shield is only for simple code is not a really "arduino wrapper", i solved the problem connecting directly to rasp GPIO look here :

http://www.rpiblog.com/2012/11/interfac ... idity.html


Don't waste your time !

;-)

Author:  libelium-dev [ Thu Nov 14, 2013 9:15 am ]
Post subject:  Re: Raspberry Pi to Arduino shields connection bridge and DH

Hi farruzzoli,

Probably one of the DHT files require some other file.
My suggestion is not to use that DHT library. This sensor use a very simple one-wire protocol to send data.

You can write a function to retrieve the data using the one-wire wire protocol.
For example:

Code:

//Include arduPi library
#include "arduPi.h"

#define MAX_TIME 85 
#define DHT11PIN 7 
int dht11_val[5]={0,0,0,0,0}; 

void dht11_read_val();

void dht11_read_val() 

  uint8_t lststate=HIGH; 
  uint8_t counter=0; 
  uint8_t j=0,i; 
  float farenheit; 
  for(i=0;i<5;i++) 
     dht11_val[i]=0; 
  pinMode(DHT11PIN,OUTPUT); 
  digitalWrite(DHT11PIN,LOW); 
  delay(18); 
  digitalWrite(DHT11PIN,HIGH); 
  delayMicroseconds(40); 
  pinMode(DHT11PIN,INPUT); 
  for(i=0;i<MAX_TIME;i++) 
  { 
    counter=0; 
    while(digitalRead(DHT11PIN)==lststate){ 
      counter++; 
      delayMicroseconds(1); 
      if(counter==255) 
        break; 
    } 
    lststate=digitalRead(DHT11PIN); 
    if(counter==255) 
       break; 
    // top 3 transistions are ignored 
    if((i>=4)&&(i%2==0)){ 
      dht11_val[j/8]<<=1; 
      if(counter>16) 
        dht11_val[j/8]|=1; 
      j++; 
    } 
  } 
  // verify cheksum and print the verified data 
  if((j>=40)&&(dht11_val[4]==((dht11_val[0]+dht11_val[1]+dht11_val[2]+dht11_val[3])& 0xFF))) 
  { 
    farenheit=dht11_val[2]*9./5.+32; 
    printf("Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",dht11_val[0],dht11_val[1],dht11_val[2],dht11_val[3],farenheit); 
  } 
  else 
    printf("Invalid Data!!\n"); 
}

void setup(){
    printf("Sensor (DHT11) readings every 3 seconds\n"); 
}

void loop(){
    dht11_read_val();
    delay(3000);
}

int main (){
   setup();
   while(1){
      loop();
   }
   return (0);
}


Using this code the data pin of DHT11 should be connected to pin 7 of the bridge.
This code can be compiled as follows (code saved on a file called test_dht.cpp):

Code:
g++ -lrt -lpthread arduPi.o test_dht.cpp -o test_dht


After this you can run it: sudo ./test_dht
Regards

Author:  farruzzoli [ Thu Nov 14, 2013 6:12 pm ]
Post subject:  Re: Raspberry Pi to Arduino shields connection bridge and DH

Thanks very much !!

Code is OK and it works perfectly !!

Author:  libelium-dev [ Fri Nov 15, 2013 8:17 am ]
Post subject:  Re: Raspberry Pi to Arduino shields connection bridge and DH

Hi farruzzoli,

Thanks for your contribution to the Cooking Hacks community.

Regards.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/