Jump to content
Forum sending old emails Read more... ×
sendiptangshu

Checksum error in DHT11 interface with MSP430G2553

Recommended Posts

I have been trying to interface DHT11 sensor with MSP430G2553. But I always end up getting a checksum error. I have attched the code and the library I am using. My sensor is the normal one with 4 pins coming out of it. I connect pin1 to Vcc(3.3V), pin2 to data pin(P1_3) and pin4 to GND. Please help. 

#include <dht.h>

dht DHT;

#define DHT11_PIN 5

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  Serial.print("DHT11, \t");
  int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
		Serial.print("OK,\t"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.print("Checksum error,\t"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.print("Time out error,\t"); 
		break;
    default: 
		Serial.print("Unknown error,\t"); 
		break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(2000);
}
//
// END OF FILE

 

dht.zip

Share this post


Link to post
Share on other sites

It would seem that the code in dht.cpp:

int dht::read11(uint8_t pin)
{
    // READ VALUES
    int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP);
    if (rv != DHTLIB_OK)
    {
        humidity    = DHTLIB_INVALID_VALUE;
        temperature = DHTLIB_INVALID_VALUE;
        return rv;
    }

    // CONVERT AND STORE
    humidity    = bits[0];  // bits[1] == 0;
    temperature = bits[2];  // bits[3] == 0;

    // TEST CHECKSUM
    // bits[1] && bits[3] both 0
    uint8_t sum = bits[0] + bits[2];
    if (bits[4] != sum)
    {
        return DHTLIB_ERROR_CHECKSUM;
    }
    return DHTLIB_OK;
}

Is unhappy with the checksum - OK, Obvious.  so why???

Take a look at the sample code for the DHT11 found in this pdf, perhaps it will help you figure out why your readings are failing the check sum.  It looks like their sample code for checking the bits of the return values are what's being done in the cpp code.

If you are using Energia exclusively, you'll be challenged to debug your code at this level; you need something like CCS to see what's happening at the lower level of the code.

 

Share this post


Link to post
Share on other sites

Sorry, it does not seem to work. Could you provide the connection diagram? Currently, I am connecting pin1 to 3.3V, pin2 to P1_0(jumper removed), pin4 to GND. 10k resistor between pin2 and Vcc. Anything else? Launchpad is MSP-EXP430G2553 Rev 1.5. Energia version 1.6.10E18- Windows 7.

Share this post


Link to post
Share on other sites

Do not connect it to 5v. This will make the DHT output a 5 volt signal on the signal pin. The MSP430 I/O's are not 5 V tolerant and supplying 5 volt signals to the I/O's will damage the MSP430.

I used the Sketch as is and connected it as you have it connected and works OK.

  1. Try a different pin (e.g. PIN 10).
  2. Did you uncomment #define DHTTYPE DHT11   // DHT 11 and comment all the other types at the top of the Sketch?

Robert

Share this post


Link to post
Share on other sites

That is indeed not what it needs to be. Which version of the MSP430 core do you have installed? (Check tools->Boards->Boards Manager...).

Is the sensor on a breakout board or is it a bare sensor? Check to make sure that the pullup is correctly installed by measuring the voltage on the signal pin. If you have access to a scope then check if there is a signal on the signal pin.

 

Share this post


Link to post
Share on other sites

Energia MSP430 Boards by Energia 1.0.3 - This is what appears to be installed. The sensor is bare with 4 pins coming out of the casing. It is not a breakout board. I am sure, there is signal on signal pin because the same sensor works on Arduino with the same library.

Share this post


Link to post
Share on other sites

Is it necessary to have the external oscillator installed? I can't think of anything else that can go wrong. I am facing similar issues with my HDC1080 as well. The I2C protocol just wont work, no matter what. I am unable to interface any temperature and humidty sensor with the MSp430. What a pity!

Share this post


Link to post
Share on other sites

The library that you refers to is for Arduino
From dht11_test.ino:

//
// FILE: dht11_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: DHT library test sketch for DHT11 && Arduino
// URL:
//
// Released to the public domain
//

From dth.cpp:

int dht :: _ readSensor (uint8_t pin, uint8_t wakeupDelay)
{
     // INIT BUFFERVAR TO RECEIVE DATA
     uint8_t mask = 128;
     uint8_t idx = 0;

     // replace digitalRead () with Direct Port Reads.
     // reduces footprint ~ 100 bytes => portability issue?
     // direct port read is about 3x faster
     uint8_t bit = digitalPinToBitMask (pin);
     uint8_t port = digitalPinToPort (pin);
     volatile uint8_t * PIR = portInputRegister (port);

I think it requires conversion from avr controller to msp controller.

How about trying the library that @energia suggested.
 

Share this post


Link to post
Share on other sites

Let's do some sanity checks on the chip itself.

Does the RED LED blink when you upload the Sketch File->Examples->01.Basics->Blink? Make sure you install the jumper next to the LED.

Robert

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×