Quick question - I am working on a project which I almost have running... I have a bunch of peripherals hooked up to my Arduino reading things such as temp, load, logging to sd card, keeping date and time etc. I have an ESP8266-01 that I also almost have working. Presumably, it'll run on 115200 baud, so - I want this project to operate standalone (IE in an electrical box) and transmit data thru the esp to a get request to thingspeak. The question is - do I need to keep my arduino plugged into a computer to run AT commands thru ESP8266? I currently have my code using AT commands to push get requests to html for thingspeak. I am waiting on a new ESP (cant flash mine after removing at firmware, assuming its a bad chip) so I cant test, but would it be able to still transmit using at commands without it being connected to a pc (no serial monitor)?
You only need to have the Arduino connected to the PC to upload a program. After that it can quite happily work without the PC connection - as long as it has a suitable power supply, of course.
Does that also pertain to AT commands? I assumed (perhaps incorrectly) the serial monitor was required to process AT commands.
Edit: So the serial monitor just displays AT commands then? It runs independently on the ESP and just displays on the serial monitor?
For clarity, this is a snippet of the code im using:
(IN SETUP)
// start debug serial
Serial.begin(9600);
// start HW serial for ESP8266 (change baud depending on firmware)
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
(IN LOOP)
// make a string for assembling the data to log:
String dataString = "12,13,14,15";
String getData = "GET/update?api_key="+ API +"&"+ field +"="+String(dataString);
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(dataString.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
This code is extremely parsed from multiple sources and not at all finalized for my purposes - I
just want to know if using AT commands this way is appropriate for a standalone project (devoid
of a usb connection to a PC)
Bumping your Thread after 2 hours is very unreasonable. After two days it would be fine.
You don't need the Serial Monitor to produce a message to send to an ESP8266 unless you want the user to be able to generate a new message that you had not conceived of when writing the program.
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Don't bump your thread after an hour. Because of the different time-zones the person who knows the answer may be asleep, or away for the day. Maybe after a couple of days.
If your question didn't get an answer, honestly review it to see if you posted enough information to help people answer you. Did you even ask a question?
Some other quotes:
Post a complete sketch (program code)! If you don't you waste time while people ask you to do that. However, with coding problems, if possible post a "minimal" sketch that demonstrates the problem - not hundreds of lines of code. If the problem goes away in the minimal sketch, it wasn't where you thought it was.
If you want to receive good answers to your questions in the Arduino forums - be sure to provide us with your complete source code, your schematic and/or hookup diagram (we much prefer a schematic if you have one),
...and so much more good advice. You really should read it.
Do you think using AT commands is appropriate, then? I am just wondering if the sendCommand choice with AT commands is the best way of sending this string to the thingspeak api, and if it would work sansa serial monitor.
Is there a different way I could go about achieving the same thing? I would need to run this code through the arduino mega, so running it as a Generic ESP module with the ESP8266WiFi library wouldnt work for me.
As per Paul, attached is a wiring diagram of my setup (wifi module TBD as you will see), the file "Current Code" is what I have working (serial & digital inputs and assignments to string) while the file "wifitest" is what I am experimenting with to get the ESP8266 to function before implementation of my main project. Please excuse my hack programming.
Thank you for the continued help, I appreciate it more then you know and apologize again for any offence from me bumping the post.
Note the wiring diagram shows an ESP8266 12E, however I am using a ESP8266-01 (couldnt find the right pic on digikey's free software)
Edit: Current wiring of ESP8266-01 is as follows:
ESP Mega
VCC 3.3v
GND GND
CH_PD 3.3v
TX TX
RX RX
Im unsure of the TX and RX configuration as well, I have heard wire tx to tx and rx to rx but also tx to rx and rx to tx (I believe one is for flashing and the other for execution?)
Usually the AT commands are sent between communicating serial devices. Serial monitor serves as such for checking but you're supposed to be sending the codes to what you want to communicate with
"I want this project to operate standalone (IE in an electrical box) and transmit data thru the esp to a get request to thingspeak."
is thingspeak via radio and not a user at a serial monitor.
Paul, kindly I'm not sure what you are referring to, I read it over I thought since I had multiple files I would include them as attachments instead of in code tags.
The current code file's functionality is to read in input from two s-type load cells (will eventually be 5) which interface through HX711 modules, a water sensor which operates on the A0 pin, a thermocouple probe on digital pin's 45, 47 & 49, gather time from an RTC module (ZS-042) and append the date and time to a data string (will implement advice about using char's) which is then logged to an sd card.
Then I would like to send the same string using the ESP8266-01 to thingspeak using a get command (if possible).
I would like to have this whole setup within an electrical housing box fed from external power and have the ESP continue to send data.
The wifitest file is the code I've been experimenting with to get the ESP module to use AT commands to send the data string to thing speak - currently it is not working because I overwrote the AT firmware with an example sketch, and for some reason (believe I fried the chip with 5v) I cannot flash the AT firmware back, so I have new ESP's on the way arriving tomorrow.
If you believe that the ESP would not be able to operate using AT commands without the serial monitor open, this is where I am looking for help. I have not been able to test wether or not AT commands can push to the ESP without the serial monitor open (I am not exactly sure how that all works).
I am using the Arduino Mega 2560 with all of the above mentioned modules, and I have read that the ESP8266WiFi library only works interfacing directly with the 'Generic ESP8266 Module' board setting in the Arduino IDE, so I am assuming my only other option is the ESP8266wifi library (community library) which I am able to use with the 'Arduino Mega 2560' board setting in the Arduino IDE.
The ESP8266 module has been confusing to say the least, I would just like to again apologize for any disrespect with the bumping, it was not all intended that way and I see how I was inconsiderate of all of your time and effort helping out on this forum. Please excuse me if I forgot to include anything, I am trying my best to piece together what has been a week long effort of wifi integration for this project.
There's the 2 devices, Mega2560 chip and ESP8266 chip.
Yes, the Mega is supposed to send AT commands (IIRC there is an alternate protocol) to the ESP8266 and get responses.
And the ESP will send AT back and forth with the thingverse devices.
Edit: Current wiring of ESP8266-01 is as follows:
ESP Mega
VCC 3.3v
GND GND
CH_PD 3.3v
TX TX
RX RX
Interface is usually Tx to Rx and vice versa.
You haven't identified the particular ESP8266 library implied in the code snippet upthread, but a typical usage is to instantiate a software serial port independent of the hardware serial port that goes to the debug monitor. It appears from your picture and the column heading quoted that you're using an Arduino Mega which has three hardware serial ports. If that's the case you'd probably use those over a software port. How that might be done depends on the particular ESP8266 library.
What you should not do is try to use the same serial port (pins) for both the debug monitor and the ESP-01 serial interface.
UPDATE: Looking at the "wifitest1.txt" file I see you've defined the esp8266 to be on Arduino pins 19 & 18 as Rx & Tx respectively, so ESP-01 Tx to Arduino D19 and ESP-01 Rx to Arduino D18.
UPDATE2: Also Vcc on Arduino is 5 V which shouldn't be applied to 3.3 V on ESP-01. You'll also want a level converter between the two boards or a voltage divider on the Arduino Tx pin (18) as a minimum. This may be why your previous ESP-01 doesn't want to flash anymore.
MrMark:
What you should not do is try to use the same serial port (pins) for both the debug monitor and the ESP-01 serial interface.
Im not quite sure what you mean by this, the debug monitor is assigned serial pins?
And actually, I had my TX in D18 and RX in D19, should I switch them? I have read so many conflicting wirings with the tx and rx pins.
Am I correct in the rest of the wiring of the ESP8266, as in should I ever need to ground any of the GPI0 pins, and should the CH_PD be wired to voltage? I am assuming grounding the GPI0 pins as I have read about would be appropriate if I were using the ESP8266WiFi library and interfacing with the ESP board directly?
EDIT:
MrMark:
UPDATE2: Also Vcc on Arduino is 5 V which shouldn't be applied to 3.3 V on ESP-01. You'll also want a level converter between the two boards or a voltage divider on the Arduino Tx pin (18) as a minimum. This may be why your previous ESP-01 doesn't want to flash anymore.
I mistakingly wrote VCC instead of 3.3V, I actually have it wired to 3.3V (I did at one point wire it to 5V as per someones suggestion, which I agree likely fried the chip hence the refusal to flash).
Do I need a level converter if I am wiring the ESP-01 it to 3.3V as it should be?
Acuitive:
Im not quite sure what you mean by this, the debug monitor is assigned serial pins?
Yes, on the Arduino board Tx0 Tx1/Rx0 Rx1 goes to the onboard serial to USB converter which goes to the host PC via USB. It can be used as either a serial channel to a peripheral device or to the USB but only one or the other.
And actually, I had my TX in D18 and RX in D19, should I switch them? I have read so many conflicting wirings with the tx and rx pins.
I'm pretty sure it's the reverse of what you had, but I don't have one at hand.
Am I correct in the rest of the wiring of the ESP8266, as in should I ever need to ground any of the GPI0 pins, and should the CH_PD be wired to voltage? I am assuming grounding the GPI0 pins as I have read about would be appropriate if I were using the ESP8266WiFi library and interfacing with the ESP board directly?
Best practice would be to pull up CH_PD, RST, and GPIO2 to 3.3V through a 10k resistor and to ground GPIO0
EDIT:
I mistakingly wrote VCC instead of 3.3V, I actually have it wired to 3.3V (I did at one point wire it to 5V as per someones suggestion, which I agree likely fried the chip hence the refusal to flash).
Live and learn. To get the ESP-01 in flash mode GPIO0, GPIO2, RST, and CH_PD should be pulled high through a resistor to 3.3 V. If you didn't do that, it might be worth trying the flash procedure again.
Do I need a level converter if I am wiring the ESP-01 it to 3.3V as it should be?
The transmit out of the Arduino (second argument in SoftwareSerial, 18 in your code) should have a voltage divider or level translator so as not to present 3 to 3.3V rather than 5V signal to the ESP-01 receive input. A voltage divider of Arduino D18 - 1.5k - 2.7k - GND with the ESP-01 Rx connected between the resistors would be good. I've seen debate as to whether this is absolutely necessary, but it's good practice.
Edit 1: Corrected Tx/Rx. As noted in post #15 Tx0 & Rx0 pins are shared with USB functionality.
@MrMark,
TX and RX are the ones in parallel with USB, not TX1 and RX1.
@Acuitive
You have a Mega. Do not connect the ESP to the TX and RX pins but connect the ESP to e.g. pins TX1 and RX1 and use Serial1 (not software serial) for communication.
Anywhere where you have esp8266.something, replace esp8266 by Serial1; remove SoftwareSerial completely.
If you have a 3.3V source (such as a 5V to 3.3V buck converter) a 74HC4050 hex buffer chip can level 6 lines very efficiently in a nice small clean package. When I bought a dozen or so they ran me 35 cents ea.
The neatest leveling tricks I've seen start with a 3.3V source. A diode on lines with 5V to 3V stops the 5V and a pullup on the 3V side makes it so that -- if the 5V line is HIGH, the 3V side sees the nice safe pullup as HIGH and if the 5V line goes LOW, the 3V pullup gets drained through the diode and the 3V chip sees LOW.
When you use a voltage divider you get a constant current drain. If it's tiny then so what, use it. Else, switching converters are getting more common for some reason... probably battery powered devices driving the numbers sold up making them more cost efficient all the time.
You dont like my diagram eh? Lol I dont blame you...
So I got everything working - as I expected, my ESP was shot from either 5V supply (suggested by someone on a forum) or the chip just went bad, couldnt reflash AT firmware after overwriting it.
Got new ESP-01's in today, works like a charm.
I also was able to confirm that the AT commands work sansa serial monitor.
I took suggestions from all of you in terms of char usage, Serial1 over SoftwareSerial (much better solution, I must agree).
Thank you all for the help, now to throw it in a box and get'er going!
Acuitive:
You dont like my diagram eh? Lol I dont blame you...
At first I thought it was no more informative than a list of parts, but then I noticed that you have Arduino pin numbers so it is probably an effective way of showing lots of parts in an uncluttered way.
I think what initially confused me was the fact that the pin numbers are on the side away from the Arduino - consequently it did not occur to me that they might be pin numbers.