After the pir ride i’ve added the dht - that worked without any issues; the biggest problem was that i was sure i’ve connected it to gpio4…and in reality it was connected to 5…I now have large ESP12E module layout printed out - this will probably prevent mistakes like this.
The fet needs pwm control…so I wanted to continue with that.
Wiring it up was not much an issue.
At first i’ve used the analogwrite function to pwm control the fet - after some loose wire issues I was able to do it….
However…there was a problem:
There was some flickering sometimes when the module read the dht&sent the mqtt packet …
I’ve digged into this pwm thing…and it looks like its pretty limited how can someone do pwm with this chip - basically there are only some basic timers…which will fire sometimes - with some possible jitter.
I’ve found a library which promised better pwm results…but I was not yet able to make it work..
I’ve looked into utilizing Timer1 -after some tweaking I was able to run an interrupt function at 15khz…but the flickering remained.
Now that i’m writing this…i’ve puzzled together some theory…
my known facts:
- flickering happens when the esp reads the dht
- timer interrupts are jittering
So I suspect that the chip itself can’t kick out the main thread from execution…
Few days have passed…
I’ve tried various methods to remove the flickering - the most ridiculus was: when I enabled nmi for timer1… after that I was not able to push ota updates to the device… :)
I’ve decided to simply just give up on handling this on the esp….it doesnt have hw pwm - which is a must for me.
I want dedicated hardware pwm!
So…i’ve looked around: how to provide pwm some other way….i’ve digged into various kinds of power pwm ics (for those to work; I guess that I would need some digital resistor..) and other options…. like employing a small mcu for the task (like an attiny).
I’ve looked for a solutions which maximizes the objectives:
- pwm is a must
- minimal footprint-
- i2c or spi support
- cheap ;)
After considering a few options I’ve choosen attiny85 for the task.
attiny86 for the rescue!
I had a single attiny85 board at hand - i’ve checked the schemantic; it had direct access to the chip, so its great.
After a couple hours of hacking.. (eclipsearduino doesn’t handle attinycore board out of the box correctly - so i had to fix that ;)…
I was able to load some blink++ to that board; i’ve loaded the ‘production fw’ into the chip: i2c read => analogwrite.
Hooking up with the esp was - as always - a bit problematic….wdt resets/etc - but after connecting the right wires to the right pins: I was able to control the fet using mqtt - without any flicker…and I’ve at least 2 possibly usable pins left on the tiny!
cheers!comments powered by Disqus