Connecting ESP8266 with ATMega16
Experience with SPI, custom protocol, one button sending signals to two microcontrollers, capacitive touch buttons
Why AVR to be added?
ESP8266 is working fine with VS1053 recording and playing audio data, sharing it via wifi, connecting to internet and playing live radio. 9 GPIOs are used in this:
4 for SPI
1 for DREQ
1 for RST and 3 for buttons).
There are no more GPIOs in esp8266 to light LEDs / have more buttons / drive a display
File to get pin/port/register variable names and values for atmega16 avr/iom16m1.h
Using SPI
When connected in single mode (ignoring vs1053), data could be sent from esp to avr but data from avr to esp did not work.
Also, cannot use this in final design since same SPI lines (miso/mosi) are shared with vs1053 but with different chip select.
Using iQc (custom protocol)
Tried connecting esp and avr using 3 wires in a custom made protocol where avr tells esp when a button is pressed & which one. AVR can separately drive OLED using I2C
Did not work. May be because of the GPIOs used (GPIO 15 & 16) that have different default values (0 & 1 respectively). If GPIO15 is set as 1 in AVR_init, esp does not boot. When esp pullup for GPIO 15 is disabled, booting happens but no reliable communication. Is this because of difference in speeds (avr at 8MHz, esp at 80 Mhz)?
Common buttons sending signal to both
Tried with 4-pair capacitive touch buttons (blue).
Can't leave buttons hanging but when pulled low/high, esp8266 does not boot.
Just one common button
Light-up LEDs using same buttons with esp
yellow led - one one side connected to Vcc (external 3.3v), other side - on button's leg where esp gpio is also connected.
as button is pressed, the button connects it to ground. LED also gets the GND so it lights up.
Worked fine. But later found that they trigger unwanted interrupts if powered by external (not from esp) Vcc (3.3/5v).
2. Connect the red capacitive button (radio)
need toggle with interrupt type = any_edge
soldered 'B' for toggle, led worked fine i.e., stayed 'on' after press (not momentary)
actual operation did not 'stop' on 2nd press, stops at 3rd press
Volatge level at each press behaves as expected (high ~2.3v when pressed once, low 0v when pressed twice), still why GPIO15 is not getting the negative edge interrupt!
Tried with external pull-up (no change), pull-down (no interrupt)
As per TP223 datasheet, 'B' puts it in 'high impedance' state when not on. May be that is why when 'off', it leaves the pin hanging hence no clear edge interrupt?
So, radio LED has to be via AVR.
Radio LED with AVR
worked fine on initial basic test
Observation 1: if avr is switched off-on while esp is on (simulating situation when main electricity is off, esp is on battery but avr is not), recorder/player interrupt get triggered randomly (electrical interference). ESP buttons / leds have to be powered by esp i.e., 3.3v
if player/recorder is on, avr should not light up radio LED on radio button press
similarly if radio is on, esp should not switch on recorder/player LED? Or should it?
leds easily go out of synch
Observation 2: capacitive button (red) that is sending signals to both esp and avr has to be on a power higher thatn 3.3. At 3.3v, behaviour is inconsistent. This gets fixed at 5v.
As per observation 1 & 2, there can't be a shared button between esp and avr. With external power (3.3/5v) comes fluctuations/electrical interference that can mess up with esp critical operations. If powered by esp, there is not enough current to relaibly trigger LED on AVR. Also, there is risk of interference on the common line.
Since there is no extra GPIO with interrupt on esp8266, there will be no radio LED. Audio feedback may be enough.
New states needed:
INVALID for recorder & player. This is to handle problem where one button is pressed while other is already pressed (& operation is going on). Code does not allow the 2nd operation but when original button is un-pressed, this one becomes in invalid state (pressed but no operation going on).
PAUSE for radio. Recorder and player when pressed will precedence over radio. Radio will be paused and resumed when recorder / player are subsequently switched off.
LEDs have to be in synch with the buttons. ON if pressed, OFF if not pressed. No extra brain needed in LED operation (neither we have the bandwidth for it).
LEDs attached directly with esp 3.3/GND do not light up good (dim getting dimmer). Max current supplied by esp8266 gpio is 12mA. If powered from outside, unwanted trigger on mains power on/off.
Esp GPIO current related link from esp8266.com
Why capacitive button can't act like a normal push self-lock switch?
Common ground
Connected 'external power gnd' with 'esp gnd'.
After this, even if the LEDs are powered with 'external 3.3v', there is no electrical interference with external power on/off. Also no strange problem of 'wierd voltages' (previosuly noted >10v across LED!). However,
the LED is still dim!
when AVR is also connected with radio button, there is electrical interference on external power on/off. So, AVR cannot be used for esp LEDs
Capacitive button replaced with simple self-lock switch (like recorder/player) so LED can be lit up (like recorder). Also radio should not play when external power is off.
Electrical interference exists even with simple button when external power is on/off.
Added level based condition in software ISR that stopped the interference. Same as in recorder/player.
Radio stops when external power is OFF.
Switches ON automatically when power is ON.
Recorder / player operation remain unaffected by mains OFF/ON. Only their LEDs go off if powered with external 3.3v. Connect with esp 3.3v if possible.
Player LED has to blink based on a condition (play_back_queue is empty or not). Added logic in play ISR, GPIO 16 blinks LED fine (bright in fact). Note: nodemcu has inbuilt LEDs for GPIO2 & 16. Can use them if casing allows! No need for external LEDs in that case.
Final on buttons: revert back to initial configuration - 2 self locking DPDT switches with LEDs that light up using the GND provided by the switches.
No comments:
Post a Comment