İçeriğe geç

Arduino+ESP8266

※ Note: The ESP8266 has a 3.3V operating voltage. In this guide, 5V is applied to the RX and TX pins of the ESP8266, so the ESP8266 board may be broken. ※ Due to a bug in the WiFiEsp library, sensor data transmission is possible, but actuator commands can not be received at arduino side.

Arrangements: Arduino, Arduino AC power, ESP8266

Please apply AC power to Arduino.

1. ESP8266 F/W update

1.1 Circuit configuration

FlashCircuit
Esp8266Arduino
RxRx
TxTx
CH_PD3.3V
VCC3.3V
GNDGND
GPIO0GND
ArduinoArduino
RESETGND

1.2 ESP8266 Flash Tool, SDK Download

1.3 Flash ESP8266 Firmware

  • Execute FLASH_TOOL_DIR/ESPFlashDownloadTool_V3.4.4.exe
  • Set the Download Patch Config window of Flash Tool as below.FileAddressSDK_DIR/bin/esp_init_data_default.bin0xfc000SDK_DIR/bin/boot_v1.6.bin0x00000SDK_DIR/bin/blank.bin0xfe000SDK_DIR/bin/at/1024+1024/user1.2048.new.5.bin0x01000
  • After selecting, press Start at the bottom.   – If downloading does not work, try setting BaudRate to 115200.   – If it continues to fail, turn off both Arduino and Esp8266, wait 5 minutes and try again.
  • Remember the MAC address shown at the bottom left of FlashTool. We will use it later when registering the gateway.

1.4 Verify flashing and Baudrate set

  • With nothing connected to the GPIO0 pin of the ESP8266, turn the board off and then on.
  • Runs the Adunino IDE and turns on the serial monitor.
  • Change the setting part to Both NL & CR, 115200 BaudRate in the bottom-right of the serial monitor.
  • To check whether ESP8266 is booted normally, send AT command and check whether OK response is coming.
  • Send AT + GMR command to check the firmware version.   – Finally, to set the Baudrate of the ESP8266 to 9600, transmit AT + UART_DEF = 9600,8,1,0,0.
  • If it is set to 9600 normally, it should be reset to 9600 as the baud rate of the serial monitor.       > All AT commands must be capitalized.
commandresponsedescription
ATOKVerify normal operation of AT command
AT+GMRAT version:1.3.0.0(Jul 14 2016 18:54:01)
SDK version:2.0.0(656edbf)
compile time:Jul 19 2016 18:44:22
OK
Check to firmware version
AT+UART_DEF=9600,8,1,0,0OKsetting of Baudrate

2. Thing+ Guide for Arduino with ESP8266

2.1 Circuit configuration

RunningCircuit
Esp8266Arduino
RxGPIO7
TxGPIO6
CH_PD3.3V
VCC3.3V
GNDGND

2.2 Install libraries

  • Scketch -> Include Library -> Manage Libraries -> Search and Install WiFiEsp
  • Scketch -> Include Library -> Manage Libraries -> Search and Install Thingplus
  • Scketch -> Include Library -> Manage Libraries -> Search and Install ArduinoJson
  • Scketch -> Include Library -> Manage Libraries -> Search and Install PubSubClient
  • Scketch -> Include Library -> Manage Libraries -> Search and Install Time
  • Scketch -> Include Library -> Manage Libraries -> Search and Install Timer

Reference : Install arduino firmware

2.2.1 Modifying the PubSubClient’s Header File

  • Arduino Library Directory PathWindows : My Documents\Arduino\libraries\ Mac : ~/Documents/Arduino/libraries/ Linux : /home/<your user name>/sketchbook/libraries
  • LibrayPath/PubSubClient/src/PubSubClient.h Open the file and make the following changes.
  • MQTT_MAX_PACKET_SIZE 196
  • MQTT_KEEPALIVE 120

2.2.2 config setting

  • open LibraryPath/Thingplus/src/Thingplus.cpp and modify as the following.(at line: 230)
    • mqtt.thingplus.net -> mqtt.sandbox.thingplus.net
void ThingplusClass::begin(Client& client, byte mac[], const char *apikey) {
	const char *server = "mqtt.sandbox.thingplus.net";
	const int port = 1883;

	this->mac = mac;
	snprintf(this->gatewayId, sizeof(this->gatewayId), PSTR("%02x%02x%02x%02x%02x%02x"),
			mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
	this->apikey = apikey;

	this->mqtt.setCallback(mqttSubscribeCallback);
	this->mqtt.setServer(server, port);
	this->mqtt.setClient(client);
}

3. Register gateway

Reference : Register Gateway

  • In this guide, we will use LibrayPath/Thingplus/examples/ArduinoEsp8266/ArduinoEsp8266.ino as it is an example of connecting the esp8266 to the Arduino board.
Kategori:ArduinoElektronik

İlk Yorumu Siz Yapın

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir