This should be straight forward but not so, I have tried about a dozen different ways, with mills and delays, serial.end, serial.read... but can't get LED to turn on after turning off?
What direction should I take.
It does not matter what data is on serial and I don't need to read it, all I need is when serial data is coming in, then trigger pin high, when not low.
If you never read the data from the serial port once one byte arrives that is it, the serial available call will always return a value of more than zero. It can never get back to zero again.
The line
if (Serial.available());
Will always do nothing because you have a semicolon at the end, thus ending your if statement without doing anything.
yes, I must admit the sketch I posted was copy paste and delete parts here and there for the forum for the mere fact that I was getting no where with all my sketches, I have about 10 different ones saves but don't want to bore you all with that....
The sketch was meant to only show the idea, I know its like bad grammar to an English professor for which I profusely apologize.
With the pin triggering for a short period I could add a delay, which I know you guys would say is bad practice, but my project is such....
I want to use attiny to trigger bootloader mode for an esp8266, that is- when attiny sees serial connecting to RX it will hold gpio0 low, reset pin low for a short while, then release back to high and so on causing esp8266 to go into bootloader mode.
Why? I am using HC 05 bluetooth to program esp automatically. The HC 05 only has RX and TX, I know EN pin goes high or low upon active serial, but can't use because it will block serial communication.
hc 05 sharing serial TX with RX esp8266 and (software serial RX) attiny
Robin2:
That is why I wrote the closing sentence in Reply #6.
...R
yes I know and when I add a delay it keeps blinking. How do I avoid that, and say if there is data on serial hold pin high for x amount of time and then low? Do I use millis? as in blink without delay example?
Robin2:
As well as what the others have said you will need to clear the data from Serial f you want your trigger to go back to low. You can do that with
However you should consider that carefully as I suspect it is not what you actually need. You have not told us what you project is trying to do.
...R
I am not sure if you are the author of an identical reply I read somewhere in this forum:) yes, in this project the attiny upon receiving serial data triggers two pins low (in a sequence), then both high thereby placing esp8266 in sketch upload mode.
The serial data's actual destination is the esp8266, not the attiny. And depending on if it is a sketch coming through RX (on attiny), places esp8266 into flash mode. If it comes to tx it bypasses the attiny (see photo above), thereby you can have esp8266 send serial data to arduino ide without placing esp8266 into flashmode.
you need to ground the gpio0 only for the reset. so a delay will do it.
pinMode(ESP_GPIO0_PIN, OUTPUT);
digitalWrite(ESP_GPIO0_PIN, LOW);
pinMode(ESP_CH_EN_PIN, OUTPUT);
digitalWrite(ESP_CH_EN_PIN, LOW);
delay(5);
pinMode(ESP_CH_EN_PIN, INPUT); // let it to esp module pull-up resistor
delay(50);
pinMode(ESP_GPIO0_PIN, INPUT); // let it to esp module pull-up resistor
set a boolean variable true after you detected data on Serial and make the reset.
in some intervals read all data from Serial, wait 100 ms and check if more data are still available, if not the flashing is over. set the boolean flag to false
In the mean time to answer your question with a question- can you use arduino serial monitor with OTA and esp8266? What I mean is that to my knowledge you cannot sent data from esp8266 to arduino serial monitor, say you want to read time on esp8266, can this data be sent to serial monitor OTA? I don't think so, besides the fact that the first sketch you always have to connect usb serial to esp8266 to upload OTA, not to mention memory limits with OTA... just a few I can think of I am sure there are more...
... another factor, which I don't want to sound funny about is why did Espressif come out with esp32?
mixamode:
can you use arduino serial monitor with OTA and esp8266?
I use Eclipse IDE. there is the port for the Serial Monitor independent from the upload port. But the truth is I do not use SM, because I log to telnet.
you can open a second Arduino IDE, if only the port selection is the problem.
mixamode:
What I mean is that to my knowledge you cannot sent data from esp8266 to arduino serial monitor, say you want to read time on esp8266, can this data be sent to serial monitor OTA?
OTA telnet
mixamode:
the fact that the first sketch you always have to connect usb serial to esp8266 to upload OTA,
that is true, but bluetooth? it is a usb cable length range. a ftdi with dtr will do.
mixamode:
not to mention memory limits with OTA...
valid argument, but only with very small flash memory
I work with Uno WiFi. It connects on-board chips ATmega328 to ESP8266 on Serial1 (an additional on board UART connected to Atmega as I2C device)
On UNO WiFi you can't disconnect the ESP from ATMega and connect it to USB adapter for flashing like you do it with a module. The solution is a software bridge, a sketch EspProxy in ATmega which copies bytes from USB to ESP and back.
Flashing tools send DTR signal to USB chip to trigger the reset of the processor to bootloader. The signal causes the reset of the ATmega with the EspProxy sketch. And EspProxy calls in setup() a reset or a reset to bootloader of ESP. This way the ESP is in bootloader mode if the tool or IDE requires it.
EspProxy detects esp flashing sync frame and resets ESP to botloader.
I think that UnoWifi has a usb to serial adaptor, where all the magic takes place I suspect apart from pin manipulation in software. I have noted that there is a break on TX on my FTDI adaptor as serial data comes in, this break is exploited as a signal to place esp8266 into flash mode in some cases. The HC 05 does not transmit any break on TX line. Which is where the problem is.
So even to do this simple trick (see image attached)with HC 05 will not work. In other words if a physical USB to serial device is involved it will not work with HC 05, since they operate differently, that is why there are different kinds of usb to serial adaptors.