I have an Arduino MEGA 2560 With WiFi Built-in - ESP8266. I can up-load sketches in both controllers therefore I am okay there. I just don't know how to choose the Mega pin 53 and have the ESP8266 control that pin via a web browser. Any ideas?
I dont quite understand your Intention. You want to control your arduino via a Standard issue Client? (in your case, a webbrowser)
Hosting a Webserver sounds quite... difficult on an arduino... Especially arduino hosting with internal Routing rules...So best I can imagine are:
- switch to raspberry pi or another products with io Pins and full Stack OS. That way, you can use engines like nginx, tomcat or nodeJS to deliver your Client as Well as react to Button press
- do Not deliver HTML via arduino. Create your HTML locally on your PC / mobile and Pressing the Button just Calls the arduinos open IP + Port. You can Listen to this port. This is Actually how most Apps work. Ui data is stored on your Phone and you just get dynamic data from another side
- host your Server somewhere Else. Pressing the Button will toggle a variable. This Server also must have an API for arduino to qquery. In your loop sequence, you Send GET querries to your API and Listen to any changes. This is the cleanest solution. But as you can See, we add an extra Component to the system: a Server hosted somewhere Else.
- https://www.arduino.cc/en/Tutorial/Webserver you obviously need another Component: ethernet shield here.
Have a great one.
Hosting a Webserver sounds quite... difficult on an arduino...
The ESP8266 is quite capable of hosting a Webserver, there are examples available in the IDE when support for the ESP board is added via the Board manager
"I just don't know how to choose the Mega pin 53 and have the ESP8266 control that pin via a web browser. Any ideas?"
A simple approach might be to first use the serial monitor to send on and off commands to control the mega pin. Then have the esp send the same command to the mega when a web server running on the esp receives the command. I don't know the operating particulars of an esp mated to a mega.
I just don't know how to choose the Mega pin 53 and have the ESP8266 control that pin via a web browser. Any ideas?
consider a two byte protocol
first byte the pin
second byte 0 or 1 to indicate off or on.
Than just send from the esp to the mega the two bytes: port and newState
This can be done by serial or by i2c, what ever you have available on your mystery board you didn't link a datasheet to.
UKHeliBob:
The ESP8266 is quite capable of hosting a Webserver, there are examples available in the IDE when support for the ESP board is added via the Board manager
Oh wow I just checked it. Sorry for wrong Information. It seems quite easy as well. You have to print every HTML line one after another though, which I dont like but whatever. A Suggestion about that point might be, if you need more than just a Button, then consider developing your Page on visual Studio Code and then transferring every line to client.println(). The Syntax correction might be very useful if you are not familiar with html 5 and still want to do shiny stuff
Have a great one.
OT:
printing html5 line by line on a esp is just one method. You can put all your html in one progmem constant and send it out with one single "print". Likewise, you can construct your html in RAM and print in one single line or you can store your html in spiffs and just pass through the content to the client.
You have to print every HTML line one after another though,
As has been pointed out this is not correct as there are several methods that allow you to send the HTML code with just one "print"
Okay guys I think you may have misunderstood my intention here. I want to control an LED in the Aurdino Mega pin 53. How do I write the code? Normally I can declare the pin like this, LED=53, where 53 is the pin number and then pinMode(LED,OUTPUT), and then whether or not I put digitalWrite (LED, HIGH(or LOW)) the LED would come on. Simple right. Well in a normal Mega or Uno this works just fine. What if I wanted to control the same LED from an app from an android phone using this board: (https://www.instructables.com/id/Arduino-MEGA-2560-With-WiFi-Built-in-ESP8266/)
I tried using the example, where as a=13, I thought 13 refered to a pin on the mega, however it refers to a GPIO12 pin on the ESP8266 side of the board combo, Therefore I was asking how do I control that pin using Wifi through the ESP(which I assume is the wifi shield) and the mega. Does that make sense?
"Does that make sense?"
Sort of. That board may be somewhat of a hassle to work with. A better approach might be to get a stand alone UNO/MEGA and connect it to a stand alone ESP8266 development board like the WeMOS development boards. That way you can have a USB serial connection on each board and see individually what is going on on each board. The combined boards sounds good, but may be hard to work with.
Thank you for that reply. I did a project one time with a bluetooth shield and it worked just fine, now I wanted to try it with Wifi and I just can't understand the combo board. It seems the arduino is at 16MHZ and the 8266 is at 80MHz?