Eines de l'usuari

Eines del lloc


public:automatismes:arduino:esp8266

Arduino com FTDI xip

Si no tinguem un conversor FTDI podem traure el xip del arduino i utilitzar els RX/TX, pins 0 i 1,

https://create.arduino.cc/projecthub/jaiprak/control-led-from-web-app-using-esp8266-serial-wifi-module-cdf419

D'aquesta manera TX del arduino va funcionar a la primera

ESP8266

No em va funcionar vaig canviar del programa

SoftwareSerial ESPserial(3, 2); RX | TX

(Vaig confondre RX-TX)

Com saber RX - TX?

En el moment que s'engega el ESP surt una cadena de caràcters per TX, no fa falta RX. Els veurem però no contesta al AT, perquè no el rep, quan conectem el RX, que està a 5V, contestarà es ESP. A la que està a 5V es el que envia, a la part el ESP el que està a 3,3V es el que envia.

Per comunicar-se amb ell sense tenir Coversor FTDI-USB. A més a més podriem utilitzar-lo en qualsevol altra aplicació:

// Basic serial communication with ESP8266
// Uses serial monitor for communication with ESP8266
//
//  Pins
//  Arduino pin 2 (RX) to ESP8266 TX
//  Arduino pin 3 to voltage divider then to ESP8266 RX
//  Connect GND from the Arduiono to GND on the ESP8266
//  Pull ESP8266 CH_PD HIGH
//
// When a command is entered in to the serial monitor on the computer 
// the Arduino will relay it to the ESP8266
//
 
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
 
void setup() 
{
    Serial.begin(9600);     // communication with the host computer
    //while (!Serial)   { ; }
 
    // Start the software serial for communication with the ESP8266
    ESPserial.begin(9600);  
 
    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");    
}
 
void loop() 
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }
 
    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }
}

ESP8266-05

1. Promblema que vaig trobar, el ESP que jo tinc es el 05, que te 5 pins, 3,3V, RX, TX, GND, Reset. Encara que la serigrafia sembla que posi GPIO no te GPIO, i el RX -TX crec que també està girat.

2. Promblema qu vai trobar amb

Arduino - wifi

El mòdul ESP8266 aparell econòmic perquè l'arduino tingui wifi. http://www.prometec.net/producto/esp-8266-01/, (5€). Comparat amb els shield que val 30€, mentre que un USB-wifi val 5 o 6€. Perquè?

Es configura com el mòduls HC-06 i HC-05 del bluetooth, comades AT, com els antics mòdems. A aquest lloc ho explica http://www.prometec.net/arduino-wifi/. Aquí una còpia amb pdf. explicacio_esp8266_prometec.net.pdf

Connexió codis AT exemple servidor

Funcio per enviar codis AT

Sense Delays, amb timeout.

Here is a function that takes a character string and a timeout. It displays the command being sent and any characters received during the timeout. You can use it to see if the response you are receiving is what you expect. It also returns a String containing the returned text so you can use the returned text in your code.

SoftwareSerial ATDevice(RXPin, TXPin);
String command(const char *toSend, unsigned long milliseconds) {
  String result;
  Serial.print("Sending: ");
  Serial.println(toSend);
  ATDevice.println(toSend);
  unsigned long startTime = millis();
  Serial.print("Received: ");
  while (millis() - startTime < milliseconds) {
    if (ATDevice.available()) {
      char c = ATDevice.read();
      Serial.write(c);
      result += c;  // append to the result string
    }
  }
Serial.println();  // new line after timeout.
return result;
}

Firmware Arduino != Firmware AT

Per defecte el ESP8266 ve amb el firmware que enten les comandes AT, però si volem programar-lo amb arduino cal canviar el firmware, per un firmware arduino, hi altres firmwares per platformIO, python, Lua…

Per fer servir el IDE d'arduino cal una connexió expecial, per aixó venen amb plaques sparkfun…adafruit…

Així que el meu ESP no pot utilitzar-se amb el IDE arduino. Cal utilitzar-lo amb comandes AT, També hi ha llibreries AT per facilitar la feina(ESP8266_AT_Arduino_Library)

itead_iteadlib_arduino_weeesp8266.zip

adrewrapp_esp8266-master.zip

exshonda_esp8266_arduino_at.zip

Explicació original:

Introduction to esp8266

Adding WiFi to any project can be difficult. There are a few off the shelf options that make it easier. One option is the official Arduino WiFi shield. This full-featured shield uses its integrated microcontroller to handle the WiFi protocol, security, and the TCP/IP stack for you. From “plug it in and go” perspective, this is an awesome option for Arduino-based projects. Plenty of example code supports the nicely designed hardware. The main downside to some people is the price.

The more popular option these days is the ESP8266, typically advertised around $5US. They are about the size of a TO-220 packaged transistor. How do they get so small? Using a technology known as “System On a Chip”, or SOC, these tiny modules pack everything on the Arduino WiFi shield inside of a single chip! SOCs are great when space is limited. If production volumes are high enough, there can even be a cost advantage.

After spending some time with an ESP8266 I bought on eBay (which I don’t recommend..), I’ve found some things you need to know before building your ESP8266 based project.

1. Not Breadboard Friendly Most modules come with male pin headers pre-soldered. However, the pinout makes it impossible to plug directly into a breadboard. This pinout style means you are going to need to use jumper wires. You might be thinking, but why do you need a breadboard? Isn’t this an entire SYSTEM on a chip?

Yes, but there’s still some stuff missing.

2. Not 5V Compatible The ESP8266 modules are based on 3.3V power and I/O (aka 3v3) . If you are going to connect the ESP8266 to an Arduino, LaunchPad, or any other 5V-based Microcontroller system, you’ll need to do some logic conversion. Directly connecting to 5V I/O, like that from an Uno, can destroy the I/O of the sensitive ESP8266 chip.

See the section below on the connection nightmare for an example diagram.

3. Power Hungry Don’t be fooled into thinking that because the board runs at 3.3V or has a small footprint that it is a “low power” device. The current draw is high when WiFi runs. In my tests, I saw my little board draw over 50mA while idle. When WiFi went active, there are large spikes.

The built-in regulator on an FTDI chip or even the slightly larger 3.3V regulator on an Arduino board is not enough. You need to use a dedicated 3.3V source or dedicated, high current, regulator. When trying to power from my Uno, my ESP8266 would not boot and I got no blinking blue lights.

4. Two ways to use the ESP8266 Keep in mind that inside of that SOC, is a microcontroller. When powered, these little boards are running some code or firmware. The default firmware that ships allow them to work as a “UART to WiFi” adapter.

However, it is also possible to overwrite this firmware and make the board do something else.

UART or Serial Interface The default firmware makes it relatively easy to add WiFi to a project. Open up a serial port at 9600 or 115200-baud and you can start sending ASCII string commands. What kind of commands? So-called “AT-Commands.”

Back when computers used modems to communicate at 300 baud, the Hayes Corporation created a command set that the industry quickly adopted. The Hayes command style is still used today, even though Hayes is long gone. (In fact, your super modern smartphone uses it…)

It works like this. The types in a command and gets response. Hopefully like this:

AT -something
OK
Sometimes, however, it’ll say:

Then you have to figure out what you (not the modem) did wrong.

That is how the ESP8266 communicates, by default, with the outside world. Using this handy ESP8266 command chart, you can see the different types of commands. It is relatively straightforward, for example, to list all of the WiFi Hotspots it detects, Connect to One (even if it has WPA2), and then send a raw HTTP request to our friend google.com.

AT
OK
 
AT+RST
OK
 
AT+CWLAP
6,”Hi There”, -85, “f8:7b:8c:1e:7c:6d"
 
AT+CWJAP=“Hi There”,”-yeah-right"
OK
 
AT+CIFSR
192.168.1.249
OK

Crude but effective.

Standalone system The second use model is to program directly the microcontroller inside of the ESP8266 SOC. In fact, you can even use the latest Arduino Board Manager to install support for ESP8266s into the Arduino IDE. So if you are familiar with Arduino, this sounds great. Just install support, write your code, connect the board, and upload.

Connecting the ESP8266 is a nightmare

The third step in that sequence, connect the board, is the problem.

Most of the common ESP8266 modules are NOT designed for external programming. The intended use is a low-cost Serial/UART communication. Some of the signals from the SOC may not be broken out and to save cost passive components like pull-up and pull-down resistors are missing.

Here’s a schematic of the extra hardware necessary to make it possible to program a cheap ESP8266 through the Arduino IDE.

ESP8266 to Serial Schematic Schematic via ESP8266 Arduino on GitHub

Yikes! What a mess!

Even after doing all of that I still couldn’t get my module to program through the IDE. Eventually, I gave up and decided to look for alternatives.

There are Alternative Boards Vendors like Sparkfun, Seeedstudio’s Grove UART WiFi, and Adafruit HUZZAH make their own variants of boards based on the ESP8266. They all carry a higher price tag than the cheap boards found on eBay.

The difference is property connected signals, clean breakouts, and strong vendor support. I ordered some boards from Adafruit after writing this post, and can’t wait for them to show up.

If you are just getting started with the ESP8266, I highly recommend going with one of these boards first. You can always switch to the lower cost boards once you get your project going.

Conclusion

The IoT fever has hit the maker community with the availability of the ESP8266. As long as you understand how it is powered, how it connects to a circuit, and the difference between ESP8266 boards, adding WiFi to any project is a breeze.

For more information check out this vibrant ESP8266 Community Forum.

Another excellent resource is this NURDspace ESP8266 Wiki page.

Eina per programar inclés personlaitzar firmwares. https://esp8266.ru/esplorer/

Arduino(ETHShield) UDP Processing

https://github.com/esp8266/Arduino/blob/4897e0006b5b0123a2fa31f67b14a3fff65ce561/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino

/*
  UDPSendReceive.pde:
 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender

 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.

 created 21 Aug 2010
 by Michael Margolis

 This code is in the public domain.
 */


#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip);
  Udp.begin(localPort);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}


/*
  Processing sketch to run with this example
 =====================================================

 // Processing UDP example to send and receive string data from Arduino
 // press any key to send the "Hello Arduino" message


 import hypermedia.net.*;

 UDP udp;  // define the UDP object


 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true ); 		// <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message
 }

 void draw()
 {
 }

 void keyPressed() {
 String ip       = "192.168.1.177";	// the remote IP address
 int port        = 8888;		// the destination port

 udp.send("Hello World", ip, port );   // the message to send

 }

 void receive( byte[] data ) { 			// <-- default handler
 //void receive( byte[] data, String ip, int port ) {	// <-- extended handler

 for(int i=0; i < data.length; i++)
 print(char(data[i]));
 println();
 }
 */
public/automatismes/arduino/esp8266.txt · Darrera modificació: 2017/07/05 12:11 per crevert