The DHT11/22 are a basic, low-cost digital temperature and humidity sensors. They uses a capacitive humidity sensor and a thermistor to measure the surrounding
air, and spits out a digital signal on the data pin (no analog input pins needed). Compared to the DHT11, DHT22 is more precise, more accurate and works in a bigger
range of temperature/humidity.
This library use DHT11/22 sensor to read temperature and humidity on Atmega micro.
Setup the data port connected to the micro pin in file dht.h
This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.
DHT11
- Power supply 3.5/5.5V DC
- Measuring range Humidity: 20/90 %RH
- Measuring range Temperature: 0/50 Celsius.
DHT22
- Power supply 3.5/5.5V DC
- Measuring range Humidity: 0/100 %RH
- Measuring range Temperature: -40/80 Celsius.
Changelog
- 03: prevent blocking if something goes wrong
- 02: first release
Code
Notes
- read risk disclaimer
- excuse my bad english
DHT22 has a temperature range of -40~80 (according to the datasheet), not -40~125.
ReplyDeleteThanks for your feedback, it was my copy and paste mistake. Now is correct.
DeleteHello Davide, do you know what is wrong? I am getting this error:
DeleteError undefined reference to `dht_gettemperaturehumidity(float*, float*)'
i need schema this project,, and what dht11 like dht22,, thank.s very much your answers
ReplyDeleteExcellent! Thank you Davide.
ReplyDeletePeter, USA
Thank you for your feedback! ;)
DeleteThank you ! working !! :)
ReplyDeleteThank you for your feedback!
DeleteHello!
ReplyDeleteI need the results will be show on LCD. Could you tell me what should I change on your library?
You need to add an lcd driver, which will depends on the lcd you chose, for example if you chose a HD44780 base, you will find a lot of library, like the Fleury one. Then you have to transform values you get from this library to ascii value using dtostrf, sprintf, or ltoa for example. Then you can output value to your LCD. Talking about LCD, take a look to AVR Freaks, it's a good starting point.
DeleteCould I send to you my code to check (I'm begginer)
DeleteHello, i'm sorry but actually i'm involved in a project... what i can do is point you to a solution, but you have to code it out.. that's the fun part also ;)
DeleteIf you are really a beginner, Arduino could be easier for you to enter electronics. Arduino framework is much more easier than writing plain avrgcc code.
Ok, thank You. Sht works, but I have question: is this code works with minus temperature for dht22 sensor?
DeleteIt should, never tryed it but it should, let me know. :)
DeleteHi again! I try, code works with minus temperature for dht22 sensor :)
DeleteThank you for feedback!
DeleteHey I need code for interfacing dht11 with atmega32...........I have connected port B with LCD (PB0-PB3 for data pins of LCD , PB4 for enable signal , PD3 for RS and PD6 for RW) and PD0 and PD1 for RX and TX of GSM modem............so how can I do it..........thanks in advance
ReplyDeleteYou have to change the port depending on the microcontroller you use. Check the datasheet of the microcontroller.
DeleteAlso setup this library to work on DHT11, look at the header file attached to the code.
Hi, I am using your library with atmega 324PA and dht11 to print the data on LCD. I have working LCD, but I can't get the program to put the data on it. I changed the ports and sensor type in header file and checked the wiring, so this should not be a problem. What else do I need to change to get things work?
ReplyDeleteThanks in advance
Check that your hardware (dht11), works on other microcontroller. Check if and where the code stop working.
DeleteIf you have a logic analizer, check the comunication bus, if not, simply use uart to debug your code.
In a first stage i should use uart to debug the code.
This comment has been removed by a blog administrator.
DeleteThansk for really fast answer! The hardware is OK, checked on arduino and worked fine. I am quite a beginner, so I am not so good in debugging, but when I go step by step, it gets stuck in _delay_loop_1(delay_basic.h).
ReplyDeleteThere is any _delay_loop_1, and delay_basic direct call in my code. It is called by the _delay_ms and _delay_us. Compile your code with avrgcc. Checked you ATmega fuses, and your ATmega F_CPU. Also try to investigate where and if in the dht library the code stops.
DeleteHello, I tried the dht library code on atmega8 @ 1MZ internal RC, but only get "error" printed out. Any ideas? It is a DHT22 from adafruit.
ReplyDeleteIf you are using the place code provided as example here, "error" means dht_gettemperaturehumidity return -1, so it can get any data from the DHT22.
DeleteThat code was written and checked using avrgcc as compiler.
There are a few think you could do: check that your hardware is properly wired, check that your DHT22 works on other microcontroller, try on arduino as example. debug your bus from micro to sensor with a logic analyzer, or use a simpler uart method for debugging, just put some output to your uart to expose to you preferred serial terminal the content of registers on the sensor. In a few words, check where is the "error", and try to fix it :)
There is a wide variation in the DHT22 level timings, as reported also by others. For instance, my sensor aware signal is 180us instead of the advertised 20-40us. Therefore, I modified your code to WAIT for the sensor aware high level rather than DELAY 40us and test the level. This works fine for my sensor. Apart from this glitch, grazie mille for publishing your code :)
DeleteWell done!
DeleteAlso thanks for your feedback, it may be usefull for other users.
Could you try to do some effort first so that someone can point you in the right direction? what have you tried and did not work? any error? did you even had a time reading through the code and try understanding what could be the problem in your case?
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteWorks with atmega 32 adnd DHT 11. Thanks
ReplyDeleteThank you for the feedback!
DeleteHey artineo, can you please send me the code for the working of atmega32 with dht11, my email id is nkhlvjy@gmail.com. Thanks in advance
DeleteHello! I write my own c code to read DHT11 sensor. I realize the timing diagrams and create functions for decoding logical levels. Could you please tell me the order of the bytes? My intention is to save each bits coming trough the dataline to 5pcs of arrays and then read only humidity datas and put on LCD. I'd need to know which 8bits come first after i've triggered the sensor. If you have any doubt of my idea please tell me. Cheers: Balázs
ReplyDeleteHello, you can found the byte order in the dht_getdata function in file dht.c
DeleteWhat's worng with my code? I get -1 shown on my LCD instead of actual humidity value.
Deletehttp://pastebin.com/kL7ty79f
It could be a timing problem. Double check your FCU. Check that you have properly set fuse for your 3.6864 crystal. Also check the code using the internal 1Mhz crystal.
DeleteI tested it in ISIS first, but now it is running on my MCU. So it works fine thanks for you help and congrats for your source code.
DeleteGood! Thanks for that feedback.
DeleteHi davide, I have written a code for the Thermo hygro series of sensors. The problem after using the ATMEGA 32 is that the code is working in DHT 11 but it is nto working in the DHT 22. I see the timing diagrams are the same for the communication. Not able to figure out where the problem seems to be. Could you elaborate on the exact difference in the way the bits are read.
ReplyDeleteHello, you can find the difference in the code source. Look at the DHT_TYPE and DHT_FLOAT definition.
DeleteOh thanks a lot Mr Gironi. Had overlooked that one :)
DeleteHey Sujith, can you please send me the code for the working of atmega32 with dht11, my email id is nkhlvjy@gmail.com. Thanks in advance
Deletehello Davide, i am going to display the real time tempr and humidity value in lcd . To do this, how can i pass the parameter in main function to call the function :
ReplyDelete"int8_t dht_getdata(int8_t *temperature, int8_t *humidity) " to get the sensor values.. please give me some hint..
Hello, there are many way to solve your problem, it's depend on how you would act.
DeleteYou can simply get temperature and humidy, and then display it using you lcdprint function.
int8_t temperature = 0;
int8_t humidity = 0;
if(dht_gettemperaturehumidity(&temperature, &humidity) != -1) {
itoa(temperature, printbuff, 10);
lcd_puts(printbuff);
itoa(humidity, printbuff, 10);
lcd_puts(printbuff);
}
Hello sir sir it's urgent
DeleteCan you help me to interface dht11 with Atmel 16 with using dht lib respectively
Hello ateeb, this library works with ATmega 16, it's just a matter of setting ports in the right way.
Deletethank you Davide.. Its working... yeah...:D thank u so much..
ReplyDeleteHappy to hear that!
Deletethanks for your help and quick response... its working 100%.. but one question.."Is the decimal part of both temp and humidity always zero??" i got the decimal part always constant ( i.e. 0 ) in LCD..
Deleteitoa is the integer to string conversion function.
Deleteto convert from double to string you should use dtostrf.
So it will be
double temperature = 0;
double humidity = 0;
...
dtostrf(temperature, 3, 3, printbuff);
...
dtostrf(humidity, 3, 3, printbuff);
...
I have problem with DHT11/Atmega32 .(
ReplyDeletemy code:
char printbuff[10];
int8_t temperature = 0;
int8_t humidity = 0;
if(dht_gettemperaturehumidity(&temperature, &humidity) != -1) {
itoa(temperature, printbuff, 10);
lcd_clrscr();
lcd_gotoxy(1, 2); //znak,radek
lcd_puts(printbuff);
itoa(humidity, printbuff, 10);
lcd_puts(printbuff);
}
I changed only:
//setup port
#define DHT_DDR DDRD
#define DHT_PORT PORTD
#define DHT_PIN PIND
#define DHT_INPUTPIN PD7
//sensor type
#define DHT_DHT11 1
//#define DHT_DHT22 2
//#define DHT_TYPE DHT_DHT22
LCD show temp and humidity = 0
Hello,
DeleteAnyway double check your wiring, also check your fuse. Check that the sensor works with other hardware. At a first step, use the sample mail file and output to uart, That way you will be shure if it is the LCD library or the DHT one that does not work.
I tried it with uart.... Atmega still send error..
DeleteI changed only this part of code : (dht.h)
//sensor type
#define DHT_DHT11 1
//#define DHT_DHT22 2
#define DHT_TYPE DHT_DHT11 //there was DHT22
fuses:
BOOTSZ0
BOOTSZ1
EESAVE
CKOPT
SPIEN
JTAGEN
=> PROGRAMMED (0), other UNPROGRAMMED (1)
I have Atmega32P ...I hope "P" is not a problem...
Thanks for quick reply!!
DeleteIts OK!
Problem was in F_CPU. I forgot include .h file with defined F_CPU...and other libraries set default wrong F_CPU..
Happy to hear this ;)
DeleteThis comment has been removed by the author.
ReplyDeleteHello Davide,
ReplyDeletei'm a beginer in AVR project,
Can you tell me what must i do with this library ?
I wat to make a project to display temperature and humidity in lcd using DHT11 and Atmega8
Please help me Davide...
Hello, you have to compile this library with avrgcc. You can found a lot of tutorial on how to compile avrgcc. Then you have to find an lcd library. First make a uart library work, because you will need it for simple debugging. Then, test the DHT11 library, then test the LCD library. When you have got all tested, make a single project with the DHT11 and LCD library togheter. If you are really a beginnner, consider to take a look at the Arduino project. it is farily simple then avrgcc compile, and it comes with a great community forum, and many libraries.
DeleteThank you David for your fast respon, but i'm sorry David i make the project using code vision avr and there is an error with the library when i try to compile. Can i stay use the cvavr compiler with some change of te library ?
DeleteI do not use code vision, so i does not know which change you have to do in order to make this code compile.
DeleteHow could I use your source code to implement DHT 11 to display on JX 128 ? Regards,
ReplyDeleteHello, I suppose you mean the JX-Mega128 board. If so, you have to compile this code for ATmega128, then you could use this code.
DeleteThanks for your fast response, I got a problem about your header files. There are errors if "DHD_DDR undeclared", "undefined reference to uart_init" and etc. I spend plenty of time to solve this but it won't work
DeleteHow to solve this ?
PS I use avr studio4
Regards,
Mix
It's sounds like a compiler problem to me, it seems you haven't added the header files to you complier environment. Check that.
Deletehello Davide, I have problem with DHT11/Atmega32
ReplyDeletemy code
int main(void)
{
char printbuff[100];
lcd_init(LCD_DISP_ON); // initialize LCD
//init interrupt
sei();
int8_t temperature = 0;
int8_t humidity = 0;
for (;;)
{
humidity = dht11_gethumidity();
temperature = dht11_gettemperature();
lcd_puts("temperature: ");
itoa(temperature, printbuff, 10);
lcd_puts(printbuff);
lcd_puts("C");
lcd_puts("\r\n");
lcd_puts("humidity: ");
itoa(humidity, printbuff, 10);
lcd_puts(printbuff);
lcd_puts("%");
lcd_puts("\r\n");
//lcd_puts("\r\n");
_delay_ms(1500);
}
return 0;
}
it display -1 values for temperature and humidity. Please help me Davide...thanks..
sorry im using atmega16
DeleteHello, doublecheck your wiring. Check your fuse, most of the time it's a timing iussue. If you have a logic analyzer you can see what's happen on the ATmega to DHT11 bus.
DeleteHello! and thanks for your tutorial! Im actually using ATmega8 and atmel studio 7. when i build the firmware it shows this kind of error: attempt to use poisoned "SIG_UART_RECV"
ReplyDeleteSomeone know what its mean?
Thanks
Hello, and thank you for your feedback.
DeleteIt's an error from the usart lib. You are using an out of date interrupt name, see you compiler documentation for the updated register name (as example, for avr-libc you can look here: http://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html)
Note: this project it is written and tested using avrgcc and the Eclipse AVR plugin.
This comment has been removed by the author.
ReplyDeleteHello Davide!
ReplyDeleteThanks for your contribution.
And I need a big help from you.
I want to save the temperature and humidity results on a text document.How can i do this, I am using Atmega32A MCU.
Please help me!!
Hello, thank you for your feedback. Do you mean save to a text document using a SD card, or save to a text document using the ATmega32 connected to a PC?
DeleteThanks for your quick response.
DeleteYes, we need to save temperature and humidity readings on to SD card embedded in a raspberyPI.
Thanks agin!
You can just output data to uart, and then read it back with the serial port of the Raspberry, you just need to setup a small serial protocol. A simple one could be just sending temperature and humidity in ASCII forma. Each line splitted by a comma (,) and terminated by a Line Feed (\10).
Deletedtostrf could be your friend here for humidity and temperature to ascii convertion. Or event the sprintf function.
Thank you david.
DeleteCould you show me an example code for this purpose.
If it possible,it will be a great favour for me..
Hello, on ATmega side, something like this should do the work: http://pastebin.com/T5BA0n1e
DeleteI let you write the Raspberry code by you, it shouldn't be so difficult, you have just to read until "end of line" character, then split by ";" to an array on array[0] you get temperatur, on array[1] humidity.
what this library can be use in code vision AVR or C language?
ReplyDeleteHello, this library is developed and tested with avrgcc. You have to port it in order to make it works on the CodeVision AVR compiler.
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteI'm getting error I read the comments but I didn't understand What should I do , please help me I tried the code with atmega16 and DHT11 I get either error or zero values for both temp and humidity, please help me I can't understand where the problem comes from :( I'm trying this code for 5 days for now !
ReplyDeleteHello, my suggestion is to use a logic analizer to debug the DATA cable, just look at it, see if it matches the DHT11 datasheet protocol.
Deletecan i use this code with ATmega32????
ReplyDeleteHello, it should work. "vladan vesý" write a comment above there. He said he works on ATmega32.
Deletethanks to reply....
ReplyDeletebut how to show text on disply 16*2 ??
what i do changing in code?
If you are using the sample code here, you have to change the uart_puts in the main.c file, with your LCD library output functions. You can find a good LCD library on the Peter Fleury AVR-Software web page.
Delete#include
ReplyDelete#include
#define F_CPU 1000000
#include
#include
#define enable 5
#define registerselection 6
void send_a_command(unsigned char command);
void send_a_character(unsigned char character);
void send_a_string(char *string_of_characters);
int main(void)
{
DDRB = 0xFF;
DDRD = 0b11111011;
_delay_ms(50);
GICR|=(1< 0)
{
send_a_character(*string_of_characters++);
}
}
thanks for your suport...
ReplyDeleteabove is my full coding of ultrasonic sensor .
and sir i have to interface the sensor(dht11/22) this sensor is interface in portA i have to include the code of sensor in above
program
Hello, I do not know about your sensor library, or your uart (send_ library), so this may not work, anyway, try something like this http://pastebin.com/rzujVpRn (expires in 2 weeks),debug it if it does not works. Also remember to include libmath (-lm ) to your linker.
Deletethank u very much sir, u modify code is ok... but i debugging in avr studio only one error is occurs that "dht/dht.h no such file or directory" . i am trying add "dht22.h" . so, how to add this file? and which particular file to add in library?
ReplyDeleteIn AVRStudio, you just have to add that files to your project and change the path in my source accoring to the file path. There are a few good tutorial on AVR Studio. They will teach you how to do this in step.
DeleteCiao Davide, come stai?
ReplyDeleteI need some help from you. I've tested your library on ATmega32 with DHT11 sensor and it works very well. However when I plugged in the DHT22 it did not. I've changed in the code to:
#define DHT_TYPE DHT_DHT22
Am I suppose to change something else? I receive only some strange numbers on my LCD.
Hello. I'm fine thanks. It should works just changing that macro as you are doing there. I'm using this on other ATmega and DHT11 without problem (ex. http://davidegironi.blogspot.it/2015/08/amqumo-xively-ambient-quality-monitor.html). You also have to change you input variables, with DHT22 you should use float. You could also try cleaning and recompiling your project. Check it with avr-gcc as compiler. Check it with other DHT22 sensor.
Deletecan you please give me the code to interface dht11 with atmega32 and 16x2 lcd display
ReplyDeleteHello, according to "artineo March 6, 2015 at 5:02 PM" this works with ATmega32, anyway I've never tryied it. As 16x2 LCD library you can use the Peter Fleury one, it works great. Please do not write twice the same comment.
DeleteThis comment has been removed by the author.
Deletesorry to say this but its not complete yet
Deleteits giving two erors
Error 1 undefined reference to `dht11_gethumidity'
Error 2 undefined reference to `dht11_gettemperature'
i have already added the libraries for dht11 and uart
please tell me what to do
It may be that you are not compiling the dht11 library. Check that your avrgcc is compiling this, and that your linker is linking that. Using the Eclipse + AVR plugin get things simpler, the most of the time you just have to add code to your project, then the AVR plugin does the compiling job.
DeleteHello, Davide!
ReplyDeleteMy project: mega8, dht22, 7seg-indicator.
To display the humidity, it is necessary to assign the variable "display". In the code "display = dht_humidity();" Eclipse says that "implicit declaration of function 'dht_humidity'". What data should be put in brackets?
Thanks a lot!
Oleg
Hello, you have to include the dht library header. So '#include "dht/dht.h'"
DeleteThanks for answer!
DeleteAlready did. It did not help.
Could you give an example of the appeal to this library? The DHT22 sensor.
Thanks!
Hi
ReplyDeletei just want to display integer part. I don't want decimal. What should i do ? i want to display only integer part in 7 segment.
Hello, you could set DHT_FLOAT to 0, then set int8_t temperature and int8_t humidity variables. Run dht_gettemperaturehumidity(&temperature, &humidity), then use the itoa function to load a char buffer with the int value, something like itoa(temperature, tempprintbuff, 10) and itoa(humidity, tempeprintbuff, 10).
DeleteThis comment has been removed by the author.
ReplyDeleteIs there a BascomAVR version?
ReplyDeleteHello, I'm sorry but I've only got this avrgcc version.
DeleteHello Davide,
ReplyDeleteI'm Working on ATmega16 and DHT22. WHILE RUNNING YOUR MAIN CODE on AVR studio 4, I'm getting this error.(../JSG_DHT.c:61: fatal error: opening dependency file dep/JSG_DHT.o.d: No such file or directory)
Please help me to solve this !!
Hello, make sure you have linked all the library you have to compile. Also give it a try to the Eclipse + AVR plugin and avrgcc compiler, which is simpler to use than the AVR Studio to me.
DeleteThanx for your Reply !!
DeleteProblem solved.
Great! Good work.
DeleteHi Sir,
ReplyDeleteI'm a beginner, Need your help !!
My Code:
#include
#define F_CPU 8000000UL
#include
#include
#include"lcd.c"
#include"dht.c"
int main(void)
{
char printbuff[100];
lcd_init(); // initialize LCD
DDRD = 0xff;
sei();
int8_t temperature = 0;
int8_t humidity = 0;
while(1)
{
humidity = dht_getdata(temperature, &humidity);;
temperature = dht_getdata(&temperature, humidity);;
lcd_string("temperature: ");
itoa(temperature, printbuff, 10);
lcd_string(printbuff);
lcd_string("C");
lcd_string("\r\n");
lcd_string("humidity: ");
itoa(humidity, printbuff, 10);
lcd_string(printbuff);
lcd_string("%");
lcd_string("\r\n");
_delay_ms(1500);
}
return 0;
no output
Hello, please do not post code here, use pastepin instead. Then, about your problem. At fisrt start to check your lcd library and lcd output. Then mix this with the DHT. To me, the first error could be the header #include #define F_CPU 8000000UL #include #include #include"lcd.c" #include"dht.c". You should your .h (lcd.h and dht.h) files, not the .c. Then, if you are a begineer a good place to start is the avrfreaks forum, here you will find a lot of help, much more than just me replying as my time allow me to do. In addition, you could try the Arduino IDE, which is fairly simple than writing plain avrgcc code.
Deletei was very confused for some days but now i have solved it and its working...if anyone wants the full coding of dht11 and atmega32 leave your email adress i will send you the complete working code and the corresponding simulations
ReplyDeleteThank you for sharing that!
DeleteShubash Mehra, can you share it with me please?
Deletebetitomota@gmail.com
This comment has been removed by the author.
ReplyDeleteHi, Davide! Thanks a lot for your libraries which are very useful.
ReplyDeleteI've been to test library for DHT11/DHT22 on Atmega8 @ 12 MHz. No problems with DHT11, but with DHT22 I had 1.0 constant humidity. I am wondered, because temperature value is correct :)
I will try to solve this problem. Maybe my DHT22 is broken :)
With best wishes from Ukraine!
Hello, it could be something related to F_CPU, I suggest you to check the timing over the data bus. They should meet what datasheet states. Also try to run the ATmega at other frequencies, like 1Mhz just to check it it works.
DeleteThank you for your reply. I already thought about it and will try in spare time. It is surprising that the check-checksum condition is met :) Perhaps a data read request occurs too often in the main program loop.
DeleteThank you for your interest. Let me know if you find the solution, it may help other people.
DeleteUnfortunately the decreasing of frequency (internal oscillator) did not help. I had decreased frequency to 1 MHz but I got the same result. So, I think the problem is not in timings. Difficult to say the real reason. Maybe sensor is really broken.
DeleteI want to solve this problem but have no oppotunity to verify another DHT22 sensor. In future I want to use logic analyser for for data bus research. I want to still get to the truth.
The best thing is to test it against a new sensor. You could try attach the sensor to let's say an Arduino board and check it using the Arduino lib.
DeleteHi, Davide!
DeleteI tried to use a logic analyzer to view the data received from the DHT22 sensor. Everything is alright with them. Moreover, the checksum corresponds to reality.
The problem is obviously with the sensor itself, as many have already encountered a similar situation (for example, https://forum.arduino.cc/index.php?topic=240661.0).
When I try to breathe on the sensor, the humidity increases somewhere to 30-40%, but then gradually drops to 1%. I think that it's still a problem with this sensor.
There are no problems with DHT11, although the humidity in the room is 20-30%, which is somehow still not enough, since another hygrometer (with another sensor) shows 40%.
It is more likely that I will refuse to use DHT22 in the current project (I planned to install it from the outside), and DHT11 in subsequent projects in general, since in our Internet segment there are many people who complain about this sensor.
Alternatively, the sensors may be Si7021 (humidity and temperature) and BME280 (humidity, temperature, pressure). Their main advantage is a wide range of the values and the fact that they are calibrated from the factory. This is not advertising :)
Thank you a lot, Davide!
Hello, thank you for sharing your experience here. I've never go to production with a DHT11 or DHT22 project, so I've almost try 10 sensors, all of them worked. The Si7021 will be a good choice, you could also take a look to the AMT1001 that has a simple driver implemenatation. Happy coding :)
DeleteHi David!
ReplyDeletePlease Help me!(sorry my bad english)
I have an atmega128. I use your code on 1Mhz and it's working perfectly but when i try use on other Frequency like 16Mhz or 2Mhz it is not working.
Hello, no problem at all, my english is maybe worst than your. Check that your code is compiled with F_CPU 16Mhz and your ATmega fuse are properly setted up. A simple test may be to pull a pin up and down at a given frequency (in a simple manner event the _delay_ms function will fo the job), and look at that pin with a scope to check the frequency.
DeleteI compiled my code as you suggested with F_CPU 16Mhz(part of code: #define F_CPU 16000000UL
ReplyDelete#include etc...) but it didn't work. Unfortunately i haven't scope so i can't try your test method. I didn't set anything at the fuse. I don't know if it should have been. What did i wrong?Thank you in advance for your reply
Hello. If you did not set fuse, that's the wrong part. You have to set the fuses according to the desired freq. Take a look here http://www.engbedded.com/fusecalc/ or on your micro datasheet to know how you have to set the fuse. You should just set the low fuse to change the freq. Keep in mind that you made wrong settings on fuse you may "brick" your ATmega, than you have to use something like "Atmega fusebit doctor" to unbrick it.
DeleteHi David, Nice Works. I am beginner. My ATmega16L connected to DHT11 and LCD. My LCD always prints NaN as temp&humidity. Came here to try your library DHT11. But the given src folder has main.c and I am not sure how to initialize your library and read temp and humidity from void loop() and void setup() function. Since my file is .ino extension. As you already suggested I am not pasting my code here. Note: I have placed your lib in my arduino lib folder and imported using #include .
ReplyDeleteHello, this library is not for Arduino, it's a plain avrgcc library. You have to compile it with avrgcc. Take a view on a avrgcc compile tutorial. You could also look at the avrfreaks forum, you will find a lot of usefull information there.
Deletehi david, can ur code work in codevisionAvr? i'm having a project with dht22/atmega16 and using CodevisionAvr. Tks u so much
ReplyDeleteHello, unluckly i do not use codivisionAVR, this code was tested and compiled with avrgcc
DeleteThis comment has been removed by the author.
ReplyDeleteHello Davide, do you know why I am getting this error:
ReplyDeleteError undefined reference to `dht_gettemperaturehumidity(float*, float*)' GccApplication1
Hello betiito, i think you are not linking and compiling the dht.h library.
DeleteThanks dude, I will try again. Thank you for the quick response.
DeleteDo you know what is the difference between creating a C and a C/C++ project?
DeleteI think it was the issue.
Now it let me compile creating a C project.
The compiler settings are different between project. For this kind of project you have to select C project.
DeleteGood day. Do i need to specify which uC i am using to use the uart headers?
ReplyDeleteWhen I program the 328p it does not transmit anything.
Dear Isaac, at first you should try to send some data over UART with a simple uart program, then you can use the UART line to connect this device.
DeleteNeeded to fix the first HostLOWtime. > 1,1ms worked for me with Mega1284p and Dollatek DHT-22 AM2302. THX DUDE
ReplyDeleteThank you for sharing your mod!
Delete