Go Down

Topic: esp 8266 on board mega.. talk to me like I am an idiot (Read 143 times) previous topic - next topic

mojuave1

Please someone talk to me like I am an idiot and explain how I work with/program an esp8266 after the "flashing" EVERY single video or post in forum or instructable websites has ever said anything past "YOU JUST FLASHED THE ESP NOW YOU ARE DONE AND READY" ready for what? whats the IP address? where do I get the IP address?

Apparently I am too stupid to see how installing/flashing firmware allows me to use the wifi as a target source to send information

Klaus_K

What library are you using? The libraries usually come with nice examples which will show you the basics.

To your questions, first your system will most likely be two processors without you knowing. The WiFi module has a separate processor handling all the complicated stuff. The software/firmware is already on the module when you get it. Updates are provided separate and downloaded with the Tools Menu -> WiFi Firmware updater or some other tools that might come with your module. You only need to download the latest version if something does not work. Sometimes the developer fix bugs and make enhancements.

Then you need to write some code for the Arduino. If you installed the libararies there will be examples specific to the libaries you are using. Use the examples to get you started.

In general you do not need to know the IP address of your board. The IP address is just a number used by the TCP/IP protocol to identify your board. The other devices might need to know the IP address. But only when you are a server. When you are a client you will automatically send your IP address with the request. Then the server will answer to that IP address. Magic :)

If you have an example that connects to your WiFi network. You will need to type somewhere in the code your WiFi SSID and PASSWORD. This will allow your board to tell your WiFi router that it is allowed to connect to your WiFi network. Most examples I have seen use a file called arduino_secrets.h. In this file you change the two strings.

#define SECRET_SSID ""
#define SECRET_PASS ""

On your router runs a service/program called DHCP. This will give your Arduino an IP address and the network functions you are calling will make use of it.

If you want to know the IP address, there is usually a function which looks like below. This depends on the WiFi library you are using. Check the examples that come with it.

IPAddress ip = WiFi.localIP();

You might need to know the IP address of another device which you want to talk to. If the device is a PC or Raspberry Pi you can find out from the terminal or desktop. If it is a thing without a monitor, you can check in your routers web interface. There is usually a page that shows you everything on the local network. You might need to assign a fixed IP address to devices on your network that function as a server.

Once you have the information, there will be code like

status = WiFi.begin(ssid, pass); // Connecting to your wifi
Udp.begin(localPort);
sendNTPpacket(timeServer);

You need to compile this program and download it to the Arduino.

Then magic things start to happen. Hope this helps.

Juraj

post a photo of your board with esp8266 module so we can see what you have and how is it wired.
is it Robotdyn Mega+WiFi?

my recommendation is to flash AT firmware 1.7.1 to esp8266 and use my WiFiEspAT library in ATmega.
I can guide you

mojuave1

I think it comes down to I am just not understanding the code and setup so lets see if this is helpful.
I no longer wish to do wifi and just want to do an ethernet shield on this project so here is the code for the project to control 16 relays through the com port. How do I change this to ethernet? My IP adress will be 192.168.1.60 as static setup. My mac address is unknown so what I read is I just make one up.

What I read I assume the shield is programmed with the arduino and I need ethernet.begin() code in there somewhere.

 // Includes the watchdog timer library
 #include <avr/wdt.h>
 
 // This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.
 #define CHANNEL_COUNT 16

 // speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.
 #define VIXEN_COM_SPEED 57600
 
 // Timeout waiting for serial input before going to random mode (in milliseconds).
 #define TIME_OUT 1000
 
 // If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"
 #define NOT_INVERTED 0
 #define INVERTED 1
 #define MODE NOT_INVERTED

 // which pins control which channels
 // You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels.
 // DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.
 #define CH01 22
 #define CH02 33
 #define CH03 24
 #define CH04 25
 #define CH05 26
 #define CH06 27
 #define CH07 28
 #define CH08 29
 #define CH09 30
 #define CH10 31
 #define CH11 32
 #define CH12 33
 #define CH13 34
 #define CH14 35
 #define CH15 36
 #define CH16 37
 
 
 int channels[] = {CH01,CH02,CH03,CH04,CH05 ,CH06,CH07,CH08,CH09,
 CH10,CH11,CH12,CH13,CH14,CH15,CH16};

 int incomingByte[CHANNEL_COUNT];

int i = 0;     // Loop counter
volatile unsigned long  timer_a = 0; // new line

//setup the pins/ inputs & outputs
void setup(){

  // enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.
  wdt_enable(WDTO_1S);
 
  // specifically for the UNO
  sei(); 

// initalize PWM Channels / Pins
 for (i=0; i < CHANNEL_COUNT; i++){
    pinMode(channels, OUTPUT);
  }

// set all the realys to off to start with
if (MODE == NOT_INVERTED) {
 for (i=0; i < CHANNEL_COUNT; i++){
     digitalWrite(channels, LOW);

 }
}

else {
 for (i=0; i < CHANNEL_COUNT; i++){
     digitalWrite(channels, HIGH);
 }
}

 testSequence();
 
// set up Serial according to the speed defined above.
  Serial.begin(VIXEN_COM_SPEED);
}

void loop()
{
   if (Serial.available() >= (CHANNEL_COUNT+2)) {
     wdt_reset(); // resets the watchdog
     timer_a = millis (); // new line
     int uno = Serial.read();
     if (uno == 126){
       
       int dos = Serial.read();
       if (dos == 33){
   
         for (i=0; i < CHANNEL_COUNT; i++) {
             // read each byte
          incomingByte = Serial.read();
         }
    if (MODE == NOT_INVERTED) {
      for (i=0; i < CHANNEL_COUNT; i++){
      int value = incomingByte;
      if (value <= 127) {
        digitalWrite(channels, LOW);
      }
      else {
        digitalWrite(channels, HIGH);
      }
      }
     }
     else {
     for (i=0; i < CHANNEL_COUNT; i++){
      int value = incomingByte;
      if (value < 127) {
        digitalWrite(channels, HIGH);
      }
      else {
        digitalWrite(channels, LOW);
      }
      }
     }

       }
     }
   }
// Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds
   else {
     wdt_reset(); // resets the watchdog
     unsigned long diff = millis() - timer_a;
     if (diff >= TIME_OUT) {
       timer_a = millis ();
       int random_a = 0;
       for (i=0; i < CHANNEL_COUNT; i++){
         random_a = random(0, 2);
         if (random_a == 0) {
           digitalWrite(channels, LOW);
         }
         else {
           digitalWrite(channels, HIGH);
         }
       }
     }
   }
}

void testSequence(){

if (MODE == NOT_INVERTED) {
 for (i=0; i < CHANNEL_COUNT; i++){
   wdt_reset(); // resets the watchdog
   digitalWrite(channels, HIGH);
   delay (500);
   digitalWrite(channels, LOW);
 }
}

else {
 for (i=0; i < CHANNEL_COUNT; i++){
   wdt_reset(); // resets the watchdog
   digitalWrite(channels, LOW);
   delay (500);
   digitalWrite(channels, HIGH);
   }
 }
}


In addition I read I will need to include these 2 libraries as well

#include <SPI.h>
#include <Ethernet.h>

any help fixing this code to be with my ethernet shield would be appreciated

mojuave1

post a photo of your board with esp8266 module so we can see what you have and how is it wired.
is it Robotdyn Mega+WiFi?

my recommendation is to flash AT firmware 1.7.1 to esp8266 and use my WiFiEspAT library in ATmega.
I can guide you
My board is an Amazon Robotyn Mega + Wifi, not named brand but identicle. I have the sketch to do what I need so at this point doing WiFi or ethernet is fine. I have another mega I bought a shield for as well so getting that to work on the code side would be great

mojuave1

What library are you using? The libraries usually come with nice examples which will show you the basics.

To your questions, first your system will most likely be two processors without you knowing. The WiFi module has a separate processor handling all the complicated stuff. The software/firmware is already on the module when you get it. Updates are provided separate and downloaded with the Tools Menu -> WiFi Firmware updater or some other tools that might come with your module. You only need to download the latest version if something does not work. Sometimes the developer fix bugs and make enhancements.

Then you need to write some code for the Arduino. If you installed the libararies there will be examples specific to the libaries you are using. Use the examples to get you started.

In general you do not need to know the IP address of your board. The IP address is just a number used by the TCP/IP protocol to identify your board. The other devices might need to know the IP address. But only when you are a server. When you are a client you will automatically send your IP address with the request. Then the server will answer to that IP address. Magic :)

If you have an example that connects to your WiFi network. You will need to type somewhere in the code your WiFi SSID and PASSWORD. This will allow your board to tell your WiFi router that it is allowed to connect to your WiFi network. Most examples I have seen use a file called arduino_secrets.h. In this file you change the two strings.

#define SECRET_SSID ""
#define SECRET_PASS ""

On your router runs a service/program called DHCP. This will give your Arduino an IP address and the network functions you are calling will make use of it.

If you want to know the IP address, there is usually a function which looks like below. This depends on the WiFi library you are using. Check the examples that come with it.

IPAddress ip = WiFi.localIP();

You might need to know the IP address of another device which you want to talk to. If the device is a PC or Raspberry Pi you can find out from the terminal or desktop. If it is a thing without a monitor, you can check in your routers web interface. There is usually a page that shows you everything on the local network. You might need to assign a fixed IP address to devices on your network that function as a server.

Once you have the information, there will be code like

status = WiFi.begin(ssid, pass); // Connecting to your wifi
Udp.begin(localPort);
sendNTPpacket(timeServer);

You need to compile this program and download it to the Arduino.

Then magic things start to happen. Hope this helps.
My program does need to know the IP so it knows where to send the data. I have a dedicated router for this and would be best to set it up as a static within the range if not everytime I run the program I will need to hunt down the IP to reconfigure if it changes. I am not actually online and disabled the password.

I downloaded the library for generic esp-8266 installed but where do you get the code specific example for the library ?

Klaus_K

Once you have installed the library go to File -> Examples. The examples should be shown there if the library has been packaged correctly. Sometimes I need to close and restart Arduino IDE to see the new examples.

You can also go to the folder where your project is and there should be a new folder libraries. Inside should be the library for your esp-8266. Some libraries end up in other folders. This depends on the supplier.

Go Up