法克啊城榛,本來(lái)我的底線是要自己建網(wǎng)站的。态兴。狠持。各種原因沒(méi)有成功只好在簡(jiǎn)書(shū)上寫了。瞻润。喘垂。
這篇文章是宗旨是怎么用arduino IDE來(lái)給ESP8266寫程序。ESP8266是我最近發(fā)現(xiàn)的很黑科技的一個(gè)東西绍撞。首先正勒,他繼承了WIFI功能,本身也有GPIO之類的傻铣,這些以前的模塊都能做到到是也沒(méi)有什么了章贞,但是價(jià)格非常之便宜,淘寶只需要25塊錢非洲,比普通的Arduino還要便宜一些鸭限。而最diao的是他只要安裝一個(gè)插件,就可以直接用Arduino IDE寫程序怪蔑,就像是給Arduino寫程序一樣里覆。很多Arduino的庫(kù)也可以直接使用。
首先缆瓣,幾乎所有的部分都是來(lái)自于 Adafruit的網(wǎng)站
恩喧枷,然后需要把Arduino升級(jí)到1.6.4以上。
這里開(kāi)始可能電腦要翻墻弓坞,但是如果的電信的網(wǎng)絡(luò)好像也可以不翻
之后對(duì)話框下面會(huì)有一個(gè)進(jìn)度調(diào),要下載大約6m的文件渡冻,但是速度很慢戚扳。
之后就可以把我的代碼拷進(jìn)來(lái),整體界面和processing很像
然后就可以像給Arduino寫程序一樣寫了。
燒寫
這時(shí)候要拔掉控制板的220v插頭超歌。
燒寫程序的時(shí)候要先把控制板查到usb口上砍艾,然后在插口旁邊有兩個(gè)按鈕,先按住標(biāo)有flash的按鈕巍举,然后按住標(biāo)有reset的按鈕脆荷,板子上的藍(lán)燈會(huì)閃爍一下,然后點(diǎn)擊arduino上的upload或者下載按鈕。
UPDATE:
做了一個(gè)閃電云蜓谋,然后拿回來(lái)以后不知道為什么就不能用了梦皮,直接接引腳是有用的,用usb供電就不行桃焕,用萬(wàn)用表量了一下VCC有一個(gè)限流電阻好像是斷了剑肯。用杜邦線短接以后就行了。
然后不知道為什么現(xiàn)在燒程序不用想以前那樣按按鈕了观堂。退子。。
然后這里是天氣云(只能實(shí)現(xiàn)一個(gè)天氣類型的展示)的代碼
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
#define SENSOR_PIN 15
#define PIXEL_PIN 5
#define PIXEL_COUNT 60
#define LED_IN 4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
const char* ssid = "X imlab";
const char* password = "";
const char* host = "query.yahooapis.com";
void setup() {
Serial.begin(115200);
delay(10);
pinMode(SENSOR_PIN, INPUT);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
pinMode(LED_IN, OUTPUT);
}
void loop() {
if(digitalRead(SENSOR_PIN) == HIGH){
digitalWrite(LED_IN, LOW);
delay(100);
digitalWrite(LED_IN, HIGH);
if(WiFi.status() != WL_CONNECTED){
rainbowCycle(5);
colorWipe(strip.Color(0,0,0), 0);
Serial.println("connecting to WiFi");
} else {
Serial.print("connected to ");
Serial.print(ssid);
Serial.println(", and now show the weather");
digitalWrite(LED_IN, LOW);
delay(100);
digitalWrite(LED_IN, HIGH);
int code_now = getWeatherCode();
while(code_now == -1){
code_now = getWeatherCode();
}
Serial.print("weather code is");
Serial.println(code_now);
displayWeather(code_now);
}
delay(6000);
}else{
delay(200);
}
}
int getWeatherCode(){
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return -1;
}
// We now create a URI for the request
String url = "/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.placefinder%20where%20text%3D\"shenzhen\")%20and%20u%3D\"c\"%0A&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=";
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(150);
// Read all the lines of the reply from server and print them to Serial
String str = "";
while(client.available()){
String line = client.readStringUntil('\r');
str += line;
}
//Serial.println(str);
//get the code of weather now see here: https://developer.yahoo.com/weather/documentation.html
int weather_code_begin = str.indexOf("condition\"")+20;
int weather_code_end = str.indexOf("\"", weather_code_begin);
// Serial.print("begin at ");
// Serial.println(weather_code_begin);
// Serial.print("end with");
// Serial.println(weather_code_end);
if(weather_code_end == -1){
return -1;
}
int weather_code = str.substring(weather_code_begin,weather_code_end).toInt();
Serial.print("code = ");
Serial.println(weather_code);
return weather_code;
}
void displayWeather(int code_now){
switch (code_now) {
case 25:
// code
for(int i=0; i<255; i++){
colorWipe(strip.Color(0,0,i), 0);
delay(20);
}
delay(1000);
break;
case 33:
//fair (night)
colorWipe(strip.Color(73, 147, 255),3);
break;
case 34:
//fair (day)
colorWipe(strip.Color(24,216,243),10);
colorWipe(strip.Color(0, 0, 0), 0);
colorWipe(strip.Color(24,216,243),10);
break;
case 36:
// hot
for(int i=0; i<255; i++){
colorWipe(strip.Color(i,0,0), 0);
delay(20);
}
delay(1000);
break;
}
colorWipe(strip.Color(0, 0, 0), 0);
}
void colorWipe_short(uint16_t be, uint16_t en, uint32_t c, uint8_t wait){
for (uint16_t i = be; i < en; i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}