Hi, i'm new using esp-01, i already worked in esp8266, but this time i'm struggling with this problem, so i have a arduino mega connected to esp-01, how i suppose to send data to sql(phpmyadmin) from arduino board?
arduino(MEGA)----esp-01
RX(0)-----------------------TX
TX(1)-----------------------RX
3v3---------------------3v3
gnd---------------------gnd
"(use port 1 and 0) not tx1,2,3...."
i can't program esp-01 board like esp8266, anyone have a code or something i can look into?
the question was about how you want to program the ESP.
if you want to use the IDE to directly program the ESP using C++, then the easiest way is to use an USB to Serial Adapter. there are tons of tutorials for this, here is one example (first google hit)
if you want to use AT commands, then look for the AT command guide and send those commands over the serial line
i have arduino mega connected to a RFID reader when detects the rfid card it will move the servo motor, (this part is working)
the problem is, i want to send data to a database when this event occurs, but to do that. i need connecting the arduino to esp-01, but i don't know how to code esp-01 using arduino mega board.
An ESP-01 is an ESP8266, but no it doesn't have a USB port, you can program it directly though using either a programmer or by using the USB port of an Arduino. Check this tutorial
You will need more than 1 resistor. You need a voltage divider.
Here is a connection circuit. The 3v3 regulator on the Mega2560 is only rated for 150mA, but can supply 300mA into a short circuit. The ESP-01 can draw 170mA on TX so the 100uF Low ESR is there to supply the peak current Edit -- The 100uF does not seem to do much according to the scope. I am seeing 0.6V dips about 0.5mS wide, but the ESP still 'works' but clearly a real supply would be better. See this project for an example of a 'real' supply for the ESP or use a Adafruit ESP8266 breakout board
There is of course. You can use the Arduino as a programmer. With a Mega that has a few hwSerial one could even upload using Serial-passthrough, but the easiest is just to
load a blank sketch (or blink) onto the Arduino.
connect the ESP's RX to the Arduino RX (which is the USB's chip TX) (via divider of course)
connect the ESP's TX to the Arduino TX
Pull the ESP's GPIO 0 'LOW' and reset the unit to put it in flash mode.
Now once you have installed the ESP-core in the IDE you can upload a sketch of your choosing.
As a test you could upload a simple 'blink' , keep in mind that the builtin led on an ESP-01 is on GPIO 1 (TX-pin as well) and is active 'LOW'
This is a decent tutorial, only the bit about the Arduino not being able to provide enough 3.3v current is not really correct. An Uno and a Mega and probably also a DUE can easily provide the 300mA peak current that the ESP needs at times.
i try connect esp-01 with my wamp, but gives this error
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
Connection failed.
Recording data.
ERROR: Class requires connected server.
my code:
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//172,19,0,89
//127,0,0,1
IPAddress server_addr(172,19,0,89); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = ""; // MySQL user login password
// Sample query
char INSERT_SQL[] = "INSERT INTO cardbd.teste (inteiro) VALUES (17)";
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
}
void loop() {
delay(2000);
Serial.println("Recording data.");
// Initiate the query class instance
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
// Execute the query
cur_mem->execute(INSERT_SQL);
// Note: since there are no results, we do not need to read any data
// Deleting the cursor also frees up memory used
delete cur_mem;
}
DBname: cardbd
table: teste
structure of the table: inteiro (type int)