esp32 esp8266 Arduino IDE

Arduino IDE

File> Preferences
เลือก Additional Board Manager URLs

https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

 

Tools > Board > Boards Manager

Tools > Board > Boards Manager…
กดหา ESP32 เลือก
ESP32 by Espressif Systems
กด ติดตั้ง

 

 

ที่มา:https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/

 

 

Arduino Nano +DHT22

#include “DHT.h”
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE, 6);

void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);

Serial.print(“Humidity: “);
Serial.print(h);
Serial.print(” %\t”);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.print(” *C “);
Serial.print(f);
Serial.print(” *F\t”);
Serial.print(“Heat index: “);
Serial.print(hi);
Serial.println(” *F”);

}

output

DHTxx test!
Humidity: 93.10 % Temperature: 29.90 *C 85.82 *F Heat index: 106.62 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.30 % Temperature: 29.90 *C 85.82 *F Heat index: 106.74 *F
Humidity: 93.20 % Temperature: 29.90 *C 85.82 *F Heat index: 106.68 *F

remark ตัว DHT22 ที่ทดสอบ ไม่ค่อยดีนัก

credit:http://arduino-er.blogspot.com/2015/05/arduino-nano-dht11-temperature-humidity.html

nodmcu V3 (Lolin) DHT11 with DeepSleep

การหลับ Deepsleep จะเป็นหน่วย microsecond

#include <ESP8266WiFi.h>
#include “DHT.h”
//deep sleep  wire GPIO16 (D0) to RST Pin
#define DHTPIN D4 // ขา Out ของ Sensor ต่อเข้าขา D4 ของ Esp8266
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Serial.begin(9600);
Serial.println(“Humidity and temperature\n\n”);
delay(700);
}

void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(“Current humidity = “);
Serial.print(h);
Serial.print(“% “);
Serial.print(“temperature = “);
Serial.print(t);
Serial.println(“C “);
//ESP.deepSleep(30e6); // Deep sleep mode for 30 seconds
//ESP.deepSleep(60e6); // Deep sleep mode for 60 seconds
ESP.deepSleep(300e6); // Deep sleep mode for (~5 min) 300 seconds
delay(800);
}

credit:https://roboindia.com/tutorials/DHT11-NodeMCU-arduino

 

nodmcu V3 (Lolin) DHT11 #1

nodmcu-dht11-d4

#include “DHT.h”

#define DHTPIN D4 // ขา Out ของ Sensor ต่อเข้าขา D4 ของ Esp8266
#define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Serial.begin(9600);
Serial.println(“Humidity and temperature\n\n”);
delay(700);
}

void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print(“Current humidity = “);
Serial.print(h);
Serial.print(“% “);
Serial.print(“temperature = “);
Serial.print(t);
Serial.println(“C “);
delay(800);
}

nodmcu-dht11-d4-output

credit:https://roboindia.com/tutorials/DHT11-NodeMCU-arduino

 

nodemcu 0.9 am2305 ds18b20 thingspeak

// www.arduinesp.com
//
// Plot DTH11 data on thingspeak.com using an ESP8266
// April 11 2015
// Author: Jeroen Beemster
// Website: www.arduinesp.com
// ใช้กับ กล่อง วัดอุณหภูมิที่บ้าน
// 20-3-2017 ใช้งานครั้งแรก DHT22
// 19-5-2017 เพิ่ม DS18B20
// 18-12-2017 ซ่อมครั้งที่ 1 เปลี่ยน DHT22 เป็น AM2305
// 26-2-2018 เปลี่ยน accesspoint ใหม่ ตั้งรหัสใหม่ เปลี่ยน thingspeak acc ใหม่
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include “ThingSpeak.h”

// replace with your channel’s thingspeak API key,
unsigned long myChannelNumber = xxxxxx;
const char * myWriteAPIKey = “xxxxxxxxxxxxxx”;

const char* ssid = “SMART_xxx”;
const char* password = “xxxxxxxxxxx”;

#define DHTPIN1 D1 // d0 dht22 ext
// #define DHTPIN2 D2 // d1 dht22 mushroom
DHT dht1(DHTPIN1,DHT22,15);
// DHT dht2(DHTPIN2,DHT22,15);
#define sensorPin D2 // Data wire is plugged into pin D3 on NodeMCU
OneWire oneWire(sensorPin); // Setup the oneWire Sensor
DallasTemperature DS18B20(&oneWire); // Pass reference to Dallas Temperature.
WiFiClient client;

ADC_MODE(ADC_VCC);
// int vcc;
void setup() {
Serial.begin(115200);
delay(10);
dht1.begin();
//dht2.begin();
WiFi.begin(ssid, password);

Serial.println();
Serial.println();
Serial.print(“Connecting to “);
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IP address: “);
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}

void loop() {

float h1 = dht1.readHumidity();
float t1 = dht1.readTemperature();
float vcc = 0.00f;
vcc = ESP.getVcc()/1024.00f;
// uint32_t vcc = ESP.getVcc()/1000.0;
DS18B20.requestTemperatures();
float t2 = DS18B20.getTempCByIndex(0);
//if (isnan(h1) || isnan(t1) ||isnan(h2) || isnan(t2)) {
if (isnan(h1) || isnan(t1) ) {
Serial.println(“Failed to read from EXT DHT sensor 1 !”);
//return;
t1=0;
h1=0;
}
else if (isnan(t2) ) {
Serial.println(“Failed to read from DS18B20 mushroom sensor 2 !”);
//return;
t2=0;
//h2=0;
}
Serial.print(“Temperature 1: “);
Serial.print(t1);
Serial.print(” C Humidity 1: “);
Serial.print(h1);
Serial.print(” % Voltage : “);
Serial.print(vcc);
Serial.print(” V MushRoom Temperature 2: “);
Serial.print(t2);
Serial.println(” C”);
//Serial.print(” C MushRoom Humidity 2: “);
//Serial.print(h2);
//Serial.println(“% send to Thingspeak”);

ThingSpeak.setField(1,t1);
ThingSpeak.setField(2,h1);
ThingSpeak.setField(3,vcc);
ThingSpeak.setField(4,t2);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
Serial.println(“Waiting”);
delay(20000);
// ThingSpeak will only accept updates every 15 seconds.
// delay 1 minitue delay 1000=1sec

client.stop();

Serial.println(“Wifi Disconnect”);
WiFi.disconnect();
//delay(60000);
delay(100);
//โดย 1,000,000 microseconds = 1 second)
Serial.println(“”);
Serial.println(“Deep Sleep 5 min”);
// deep sleep 1 min
//ESP.deepSleep(60 * 1000000, WAKE_RF_DEFAULT);
//deep sleep 5 min
ESP.deepSleep(360 * 1000000, WAKE_RF_DEFAULT);
//ESP.deepSleep(5*60 * 1000000);
//node.dsleep(60 * 1000000);
delay(500); // wait for deep sleep to happen
}

ESP-01 AT Firmware AI-Thinker

http://wiki.ai-thinker.com/_media/esp8266/ai-thinker_esp8266_at_firmware_dout_v1.5.4.1-a_20171130.rar

 

Ai-Thinker_ESP8266_DOUT_8Mbit_v1.5.4.1-a_20171130.bin

 

esp-01-at-ai-thinker-firmware

Youtube Auto for android auto

  1. download android auto    https://www.apkmirror.com/apk/google-inc/android-auto/android-auto-2-8-5745-release/android-auto-maps-media-messaging-voice-2-8-574513-release-android-apk-download/
  2. Youtube  Auto http://www.thekirankumar.com/blog/2017/12/29/play-youtube-video-android-auto-app/

ESP32 MircoPython Install

https://www.python.org/downloads/

download ตัว python-2.7.14 ที่ https://www.python.org/ftp/python/2.7.14/python-2.7.14.msi

ติดตั้ง

โปรแกรมจะสร้าง folder ที่ c:\python27

cmd ออก command prompt

พิมพ์ cd\python27  แล้ว Enter

cd Scripts

pip install esptool    //ติดตั้ง esptool

pip install adafruit-ampy

esptool.py –port COM3 flash_id   //ตรวจสอบ การเชื่อมต่อ

esptool.py –port COM3 erase_flash //ลบ flash ของเดิมออก รอติดตั้ง micropython

สลับไป เปิดเวป https://www.micropython.org/downloads/#esp32

download firmware http://micropython.org/resources/firmware/esp32-20171224-v1.9.3-217-g5de064fb.bin

เมื่อได้ไฟล์ esp32-20171224-v1.9.3-217-g5de064fb.bin มาแล้ว

copy ไปไว้ใน c:\python27 แล้ว rename เป็น esp.bin

กลับไปที่ cmd พิมพ์

esptool.py –chip esp32 –port COM3 write_flash -z 0x1000 c:\python27\esp.bin  เพื่อ upload firmware ใส่ใน esp32

เห็นหน้าตาคล้ายจอแสดงผล ในตอน compile esp32 มากเลย

หลังจาก flash สำเร็จ ลองติดต่อโดยใช้ putty

เลือก Serial COM3 115200

เท่านี้ก็เรียบโร้ย

อ้อ ลืมตัว editor

 

 

download มาแล้วใส่ใน C:\Program Files\ESPlorer

ส่ง shortcut ESPlorer.bat มาบนจอ เท่านี้ก้ใช้ได้

 

 

ที่มา:https://www.youtube.com/watch?v=ay2yuGId7Ag

 

 

 

 

 

 

 

 

 

ESP8266 ESP-01 Blynk Virtual port Relay

esp-01-relay

/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Sketch generator: http://examples.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example runs directly on ESP8266 chip.
*
* Note: This requires ESP8266 support package:
* https://github.com/esp8266/Arduino
*
* Please be sure to select the right ESP8266 module
* in the Tools -> Board menu!
*
* Change WiFi ssid, pass, and Blynk auth token to run 🙂
*
**************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxx”;

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “yyyyyyyyyyyyyyy”;
char pass[] = “zzzzzzzzzz”;

void setup()
{
Serial.begin(9600);
pinMode(0, OUTPUT);
pinMode(2, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
BLYNK_WRITE(V1)
{
int i=param.asInt();
if (i==1)
{
delay(300);
digitalWrite(0, HIGH);
digitalWrite(2, HIGH);
delay(1750); // delay 1000 = 1 sec
digitalWrite(0, LOW);
digitalWrite(2, LOW);
}
else
{
digitalWrite(0, LOW);
digitalWrite(2, LOW);
}
}

void loop()
{
Blynk.run();
}

 

 

credit:http://docs.blynk.cc/#blynk-main-operations-get-data-from-hardware

https://community.blynk.cc/t/blynk-virtual-pin-blynk-write/7001/3

ESP8266 ESP-01 Relay Blynk #1

esp-01-relay

/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Sketch generator: http://examples.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
* This example code is in public domain.
*
**************************************************************
* This example runs directly on ESP8266 chip.
*
* Note: This requires ESP8266 support package:
* https://github.com/esp8266/Arduino
*
* Please be sure to select the right ESP8266 module
* in the Tools -> Board menu!
*
* Change WiFi ssid, pass, and Blynk auth token to run 🙂
*
**************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “xxxxxxxxxxxxxxxxxxxxxxxxxxxx”;

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “yyyyyyy”;
char pass[] = “zzzzzzzzz”;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}

void loop()
{
Blynk.run();
}