Sensors, datalogger: ANN: Source (nuelectronics)

Thank you, someone, for your post asking "How do I..." in respect of the datalogger shield from...

http://www.nuelectronics.com/

That led me to visit the site... and I was delighted by what I found there. I would commend it to anyone who isn't quite as miserly as I am, and understands that their TIME is worth something.

Nuelectronics (with whom, just to be clear, I have no connection), offer...

(Skip down past the datalogger if it doesn't interest you... there's more!)

At only £12 (c. $18), a datalogging shield with Dallas 1-Wire support: NOT EVERY CHIP, but at least the DS18B20 ... and a RTC (DS1302) ... SD card interface for mass storage of sensor data ... ports for various sensor modules.

The sensors already available, each nicely mounted on a little PCB, and interconnect cable to sensor-ready socket on datalogger (or your own host devices) (See illustrations on site)...

For £2 (c.$3) each: Switch, thermistor, LDR, IR controller sensor (The IR sensor is intended for receiving signals from a TV remote control. They will sell you one which you can be SURE will "work" with the supplied software for £3... or hope that your existing controller will work, if perhaps with some software tweaking.)

For no more than £4.50 (d.$7) each: MQ-3 Alcohol gas sensor, DS18B20 (you can pay almost that for an unmounted chip!), DHT11 Temperature & Humidity Sensor Module, and buzzer output module.

(The DHT11 looks a cool little device, by the way. Not sure if it has already been discussed at this forum... I must go off and search old posts in a moment!)

So! I don't "know" that these guys are the best thing since sliced bread... but they look pretty good. I've placed my first order.

If you are in the US.... how hard can it be? You can pay with Paypal... they take care of all the nasty currency conversions, and the stuff nuelectronics sell is small, will go through the post easily. I buy things from the US for delivery in the UK frequently. Usually no hassle. Why should vice versa be hard? ("Security"? Bah.)

Our well, I could be wrong but i think that was me!
Strangly enough i’m just one or two steps in front of you!
I have one off all of the sensors, and i’m currently trying to get them working with the small peices of info from Nuelectronics. (Just how i like it - to much information means you never learn stuff!)
Right then my problem, I have a dht11 also know as a AM2303.
http://aosong.com/english/Upload/PicFiles/20091281822579047.pdf
It comes with code

#define DHT11_PIN 0      // ADC0

byte read_dht11_dat()
{
      byte i = 0;
      byte result=0;
      for(i=0; i< 8; i++){
            
            
            while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
            delayMicroseconds(30);
            
            if(PINC & _BV(DHT11_PIN)) 
                  result |=(1<<(7-i));
              while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
               
      }
      return result;
}


void setup()
{
      DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);
      
        Serial.begin(57600);
  
Serial.println("Ready");
      }
      
void loop()
{
      Serial.println("A");
        byte dht11_dat[5];
      byte dht11_in;
      byte i;
      // start condition
      // 1. pull-down i/o pin from 18ms
      PORTC &= ~_BV(DHT11_PIN);
      delay(18);
      PORTC |= _BV(DHT11_PIN);
      delayMicroseconds(40);
      
      DDRC &= ~_BV(DHT11_PIN);
      delayMicroseconds(40);
      
      dht11_in = PINC & _BV(DHT11_PIN);
      Serial.println("B");
      if(dht11_in){
            Serial.println("dht11 start condition 1 not met");
            return;
      }
      delayMicroseconds(80);
      //Serial.println("C");
      dht11_in = PINC & _BV(DHT11_PIN);
      
      if(!dht11_in){
            Serial.println("dht11 start condition 2 not met");
            return;
      }
      delayMicroseconds(80);
      // now ready for data reception
      for (i=0; i<5; i++)
            dht11_dat[i] = read_dht11_dat();
            
      DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);
      
        byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
      // check check_sum
      if(dht11_dat[4]!= dht11_check_sum)
      {
            Serial.println("DHT11 checksum error");
      }
      
      Serial.print("Current humdity = ");
      Serial.print(dht11_dat[0], DEC);
      Serial.print(".");
      Serial.print(dht11_dat[1], DEC);
      Serial.print("%  ");
      Serial.print("temperature = ");
      Serial.print(dht11_dat[2], DEC);
      Serial.print(".");
      Serial.print(dht11_dat[3], DEC);
      Serial.println("C  ");
      
      delay(2000);
}

First thing i noticed is that the decimal part is always coming back as .00 and when I start tp put break points in “serial.print (“A”);” the system jsut crashes!!!

Anybody got any idea’s what’s going wrong, how i read the protocol it looks ok, but i’m not sure, so i’m hoping the forum can help!

Also the NTC and LDR routines from Nuelectronics dont have any conversion at the moment from voltage to temp but i am working on that!

Thanks

Pete

milneandfletch

thx :slight_smile: I’ve modified the code for DHT22 and it works on my Arduino Duemilanove.

#define DHT11_PIN 0      // ADC0

byte read_dht11_dat()
{
      byte i = 0;
      byte result=0;
      for(i=0; i< 8; i++){

            while(!(PINC & _BV(DHT11_PIN)));  // wait 50us finish
                delayMicroseconds(30);
                if(PINC & _BV(DHT11_PIN)) 
                           result |=(1<<(7-i));
                while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
                
      }
      return result;
}


void setup()
{
      DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);

        Serial.begin(57600);
  
Serial.println("Ready");
      }

void loop()
{
      //Serial.println("A");
        byte dht11_dat[5];
      byte dht11_in;
      byte i;
      // start condition
      // 1. pull-down i/o pin from 18ms
      PORTC &= ~_BV(DHT11_PIN);
      //delay(18);  //DHT11 must >=18ms
        delay(5);  //DHT22 must 1~10ms
      PORTC |= _BV(DHT11_PIN);  // pull-up 20-40us
        delayMicroseconds(40);

      DDRC &= ~_BV(DHT11_PIN);
      delayMicroseconds(40);

      dht11_in = PINC & _BV(DHT11_PIN);
      //Serial.println("B"); //miss first 2 bits on DHT22
      if(dht11_in){
            Serial.println("dht11 start condition 1 not met");
            return;
      }
      delayMicroseconds(80);
      dht11_in = PINC & _BV(DHT11_PIN);

      if(!dht11_in){
            Serial.println("dht11 start condition 2 not met");
            return;
      }
      delayMicroseconds(80);

        // now ready for data reception
      for (i=0; i<5; i++)
            dht11_dat[i] = read_dht11_dat();

        DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);

        byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
      
        // check check_sum
      if(dht11_dat[4] != dht11_check_sum)
            Serial.println("DHT11 checksum error");

//debug
for (i=0; i<5; i++) {
            Serial.print(dht11_dat[i], HEX);
                Serial.print(' ');
}
Serial.print("check_sum=");
Serial.print(dht11_check_sum, HEX);
Serial.println(' ');
//end of debug

int HighByte, LowByte, TReading, SignBit, Whole, Fract;   //DHT22
HighByte = dht11_dat[0];   //DHT22
LowByte = dht11_dat[1];   //DHT22
TReading = (HighByte << 8) + LowByte;   //DHT22
Whole = TReading / 10;   //DHT22
Fract = TReading % 10;   //DHT22

      Serial.print("Current humdity = ");
//      Serial.print(dht11_dat[0], DEC);  //DHT11
//      Serial.print(".");  //DHT11
//      Serial.print(dht11_dat[1], DEC);  //DHT11
      Serial.print(Whole);  //DHT22
      Serial.print(".");   //DHT22
      Serial.print(Fract);   //DHT22
      Serial.print("%  ");   //DHT22

HighByte = dht11_dat[2];
LowByte = dht11_dat[3];
TReading = (HighByte << 8) + LowByte;
  if (SignBit) // negative
       TReading = (TReading ^ 0xffff) + 1;
Whole = TReading / 10;
Fract = TReading % 10;

      Serial.print("temperature = ");
//      Serial.print(dht11_dat[2], DEC);  //DHT11
//      Serial.print(".");  //DHT11
//      Serial.print(dht11_dat[3], DEC);  //DHT11

        SignBit = TReading & 0x8000;  // test most sig bit
        if (SignBit) // If its negative
               Serial.print("-");
      Serial.print(Whole);  //DHT22
      Serial.print(".");  //DHT22
      Serial.print(Fract);  //DHT22
      Serial.println("C  ");  //DHT22

      //delay(2000);  //DHT11
        delay(3000);  //DHT22
}

DHT22
http://aosong.com/english/Upload/PicFiles/20091281821398746.pdf

Hi Quine, Thanks ever so much for looking at this, i've been going around in circles! The interesting things is, this is what i get printed out - 21 0 18 0 39 check_sum=39 Current humdity = 844.8% temperature = 614.4C

So that data i am getting out is suggesting that i'm not getting the decimal part! My info on this part, which has been sold to me as a dht11! is blue, is yours?? any idea's where i can find a better datasheet? It may be possible that i dont get decimal parts which would be a shame but would explain what's happening!

Thanks

Pete

It seems no difference on data format between the English version of DHT22 datasheet and the one of DHT11. Actually they are different. :frowning:

Sorry I didn’t check the English version before. Follows the description from the Chinese version.

http://www.aosong.com/Upload/PicFiles/20091121029421455.pdf
DHT11
DATA=8 bit integral RH data + 8 bit decimal RH data + 8 bit integral T data + 8 bit decimal T data + 8 bit check-sum

http://www.aosong.com/Upload/PicFiles/2009121016446072.pdf
while DHT22
DATA=16 bit RH data + 16 bit T data + 8 bit check-sum, and the most sig bit of T data indicates the negative.

so,

21 0 18 0 39 check_sum=39
Current humdity = 844.8% temperature = 614.4C

should be 33.0% 24.0C with DHT11

there is one mistake about the position of the “SignBit =” line in post #2 which cannot be modified any more, so I have to changed it in the new post.

#define DHT11_PIN 0      // ADC0

byte read_dht11_dat()
{
      byte i = 0;
      byte result=0;
      for(i=0; i< 8; i++){

            while(!(PINC & _BV(DHT11_PIN)));  // wait 50us finish
                delayMicroseconds(30);
                if(PINC & _BV(DHT11_PIN))
                           result |=(1<<(7-i));
                while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
                
      }
      return result;
}


void setup()
{
      DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);

        Serial.begin(57600);
  
Serial.println("Ready");
      }

void loop()
{
      //Serial.println("A");
        byte dht11_dat[5];
      byte dht11_in;
      byte i;
      // start condition
      // 1. pull-down i/o pin from 18ms
      PORTC &= ~_BV(DHT11_PIN);
      //delay(18);  //DHT11 must >=18ms
        delay(5);  //DHT22 must 1~10ms
      PORTC |= _BV(DHT11_PIN);  // pull-up 20-40us
        delayMicroseconds(40);

      DDRC &= ~_BV(DHT11_PIN);
      delayMicroseconds(40);

      dht11_in = PINC & _BV(DHT11_PIN);
      //Serial.println("B"); //miss first 2 bits on DHT22
      if(dht11_in){
            Serial.println("dht11 start condition 1 not met");
            return;
      }
      delayMicroseconds(80);
      dht11_in = PINC & _BV(DHT11_PIN);

      if(!dht11_in){
            Serial.println("dht11 start condition 2 not met");
            return;
      }
      delayMicroseconds(80);

        // now ready for data reception
      for (i=0; i<5; i++)
            dht11_dat[i] = read_dht11_dat();

        DDRC |= _BV(DHT11_PIN);
      PORTC |= _BV(DHT11_PIN);

        byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];

        // check check_sum
      if(dht11_dat[4] != dht11_check_sum)
            Serial.println("DHT11 checksum error");

//debug
for (i=0; i<5; i++) {
            Serial.print(dht11_dat[i], HEX);
                Serial.print(' ');
}
Serial.print("check_sum=");
Serial.print(dht11_check_sum, HEX);
Serial.println(' ');
//end of debug

int HighByte, LowByte, TReading, SignBit, Whole, Fract;   //DHT22
HighByte = dht11_dat[0];   //DHT22
LowByte = dht11_dat[1];   //DHT22
TReading = (HighByte << 8) + LowByte;   //DHT22
Whole = TReading / 10;   //DHT22
Fract = TReading % 10;   //DHT22

      Serial.print("Current humdity = ");
//      Serial.print(dht11_dat[0], DEC);  //DHT11
//      Serial.print(".");  //DHT11
//      Serial.print(dht11_dat[1], DEC);  //DHT11
      Serial.print(Whole);  //DHT22
      Serial.print(".");   //DHT22
      Serial.print(Fract);   //DHT22
      Serial.print("%  ");   //DHT22

HighByte = dht11_dat[2];
LowByte = dht11_dat[3];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
       TReading = (TReading ^ 0xffff) + 1;
Whole = TReading / 10;
Fract = TReading % 10;

      Serial.print("temperature = ");
//      Serial.print(dht11_dat[2], DEC);  //DHT11
//      Serial.print(".");  //DHT11
//      Serial.print(dht11_dat[3], DEC);  //DHT11

        if (SignBit) // If its negative
               Serial.print("-");
      Serial.print(Whole);  //DHT22
      Serial.print(".");  //DHT22
      Serial.print(Fract);  //DHT22
      Serial.println("C  ");  //DHT22

      //delay(2000);  //DHT11
        delay(3000);  //DHT22
}