Page 1 of 1

atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 10:34 am
by kabouras_33
Hello guys
So i had some atmega328p around (empty not Arduino) and I gave a try to a dht22 sensor.Well to my surprise no readings....
Another problem also that maybe related
I try to use an external oscillator 16Mhz with low_fuse 0xff,high_fuse 0xde,and extended 0x05 but nothing....no led blinks it only works when I set project options to 1Mhz :?: :?: :?:
Some pointers basically to make the dht22 work??(the sensor is good works in arduino uno)

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 10:53 am
by Benj
Hello,

The DHT22 requires accurate timings and a clock > 1MHz.

This is a useful trick for getting your project running as expected.

https://www.matrixtsl.com/wiki/index.ph ... ED_flasher

I would guess it's to do with your configuration settings.

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 11:01 am
by kabouras_33
I am sure it has to do with conf settings too but......only at 1Mhz i can make the flasher...i literally tried every choice in the configurations to set the 16Mhz crystal but it just doesn't work....notice in pic18f....is working great.
Do you have a quick example for flasher for atmega328p?

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 11:25 am
by Benj
Are you driving the Atmega with a 16MHz crystal? Are your load capacitors correct? Can you post your circuit so we can check.

You settings look ok to me for 16MHz operation.

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 11:33 am
by kabouras_33
I do not have any schematics yet (breadboard :D :D )but its fairly simple
pin1 & 7 -> 5v
pin8 & 22 -> grd
pin 9 & 10 -> crystal osc 16Mhz with 2 22pf caps to grd

dht22
pin 1 -> 5v
pin 2 -> atmega pin4
pin 4 -> grd

Thats it.....
and I am programming it using and arduino uno as isp with avr dude:
avrdude -c arduino -p m328p -P COM27 -b 19200 -U flash:w:home_garage.hex

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 12:07 pm
by viktor_au
Try this version

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 12:15 pm
by kabouras_33
Thanks Viktor,
But sadly no......all code works .....the esp01,the MQTT,the button ...except the dht22.....

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 5:37 pm
by kabouras_33
Ok I found the problem...looks like flow code doesn't set the fuses when you burn the hex file, you have to burn the fuses before and then burn your hex file...

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 10:14 pm
by viktor_au
Hello kabouras

Please pay attention to switch.

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 11:01 pm
by kabouras_33
Thanks Victor!!
Yes you are right i removed it but the problem was that flowcode doesnt burn the configs like it does with pics..thats why it was always working only with 1Mhz no matter what i chose...
I had to burn rhe fuses first with a different set of instructions first for lfuse then hfuse and after that i burn the hex and boom all working perfectly at 16Mhz external crystal including the dht22....i think this is a bug but the workaround, worked :wink:

Re: atmega328p DHT22 problem

Posted: Wed Dec 09, 2020 11:04 pm
by kabouras_33
By the way the dht22_sample variable is to return 1 for no data and 2 for crc error i believe so i dont see any reason why the switch does not work...but i did not need it so did not try...i will test it tomorrow though :mrgreen: :mrgreen:

Re: atmega328p DHT22 problem

Posted: Thu Dec 10, 2020 4:35 am
by viktor_au
Understood kabouras

What is the reason you don't use Arduino boards?
Easy to program...

Re: atmega328p DHT22 problem

Posted: Thu Dec 10, 2020 10:49 am
by kabouras_33
Well, the reason is that I develop and manufacture product orders from clients(custom designs)and products for ships automation...engine control, temperatures etc... now this system costs some money :wink: (not small) the problem with Arduino, raspberry etc is that the people know them and they know how much they cost...plus the fault image is that they are some kind of toys for kids :evil: .Anyway if I try to introduce a product that sells for 10000 euro lets say with an Arduino....well you are doomed...so I develop my own PCBs, my own enclosures etc...
www.aomi-tech.grwww.aomi-tech.gr

Re: atmega328p DHT22 problem

Posted: Thu Dec 10, 2020 11:39 am
by viktor_au
Business development is not DIY.
I used to work with PIC and used some programs to make PCBs, etc.
But for some small house related projects Arduino is good enough.
Not for you, I understood.
You have raised a good points.
Thank you.