sendiptangshu 0 Posted May 26, 2018 Share Posted May 26, 2018 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 Quote Link to post Share on other sites
NurseBob 111 Posted May 27, 2018 Share Posted May 27, 2018 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. Quote Link to post Share on other sites
energia 484 Posted May 29, 2018 Share Posted May 29, 2018 Not sure why this library is not producing the proper result. I have been using the following library which works for me on all LaunchPads: https://github.com/Seeed-Studio/Grove_Temperature_And_Humidity_Sensor/releases Please give this one a try. Quote Link to post Share on other sites
sendiptangshu 0 Posted May 30, 2018 Author Share Posted May 30, 2018 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. Quote Link to post Share on other sites
quasar5456 0 Posted May 30, 2018 Share Posted May 30, 2018 (Don't do this for the reason stated in the following post) Original: Try connecting Pin1 to a 5V supply. Quote Link to post Share on other sites
energia 484 Posted May 30, 2018 Share Posted May 30, 2018 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. Try a different pin (e.g. PIN 10). Did you uncomment #define DHTTYPE DHT11 // DHT 11 and comment all the other types at the top of the Sketch? Robert Quote Link to post Share on other sites
sendiptangshu 0 Posted May 30, 2018 Author Share Posted May 30, 2018 Yes, I still get wrong output. Something like this. Quote Link to post Share on other sites
energia 484 Posted May 30, 2018 Share Posted May 30, 2018 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. Quote Link to post Share on other sites
sendiptangshu 0 Posted May 30, 2018 Author Share Posted May 30, 2018 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. Quote Link to post Share on other sites
energia 484 Posted May 30, 2018 Share Posted May 30, 2018 I can't think of anything else that might be wrong. I am not able to reproduce it here and thus hard for me to debug this. Quote Link to post Share on other sites
sendiptangshu 0 Posted May 31, 2018 Author Share Posted May 31, 2018 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! Quote Link to post Share on other sites
Frida 4 Posted May 31, 2018 Share Posted May 31, 2018 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. Quote Link to post Share on other sites
sendiptangshu 0 Posted May 31, 2018 Author Share Posted May 31, 2018 I am using the library that @energia suggested. Do you have any idea what the changes might be if we use the other library by Rob Tillaart? Quote Link to post Share on other sites
energia 484 Posted May 31, 2018 Share Posted May 31, 2018 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 Quote Link to post Share on other sites
sendiptangshu 0 Posted May 31, 2018 Author Share Posted May 31, 2018 Yes, definitely, it works as expected. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.