ESP8266 温湿度计 WIFI
http://www.micropython.org.cn/forum.php?mod=viewthread&tid=464&page=2#lastpost
将ESP8266模块作为 Simple HTTP server,手机浏览器当做 客户端,获取温度数据。
有个问题要注意:ESP8266的IP要在路由器中分配一个固定的地址。
源码如下:(第一次写micropython代码,很乱)
What do we need
- an Arduino Yún board
- a Sharp Optical Dust Sensor (GP2Y1010AU0F)
- a breadboard
- a 220 uF capacitor
- a 150 Ohm resistor
- a bunch of wires
The circuit
Be sure to follow the connections shown in the fritzing circuit and in the next table :
Sharp pin 1 (V-LED) => 5V (connected to 150ohm resistor,220 uF capacitor)
Sharp pin 2 (LED-GND) => Arduino GND pin
Sharp pin 3 (LED) => Arduino pin 2
Sharp pin 4 (S-GND) => Arduino GND pin
Sharp pin 5 (Vo) => Arduino A0 pin
Sharp pin 6 (Vcc) => 5V
The code
/* Detector air quality with Arduino Yun and **
** Optical Dust Sensor (GP2Y1010AU0F) */
int dustPin = 0; // dust sensor - Arduino A0 pin
int ledP = 2;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup(){
Serial1.begin(230400);
pinMode(ledP,OUTPUT);
}
void loop(){
digitalWrite(ledP,LOW); // power on the LED
delayMicroseconds(280);
voMeasured = analogRead(dustPin); // read the dust value
delayMicroseconds(40);
digitalWrite(ledP,HIGH); // turn the LED off
delayMicroseconds(9680);
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0);
dustDensity = 0.17 * calcVoltage - 0.1;
Serial1.print("Raw Signal Value(0-1023) : ");
Serial1.print(voMeasured);
Serial1.print(" - Voltage: ");
Serial1.print(calcVoltage);
Serial1.print(" - Dust Density: ");
Serial1.println(dustDensity); // mg/m3
delay(1000);
}
Write or paste code in Arduino IDE, then load the sketch on Yún board.Python Serial Test
Read data from shell.To do this we used the included library “pyserial”. You must create a python script to be launched from a terminal. Then connect to your board with ssh, create file serialTest.py with the following code and start it with the command “python serialTest.py”. Read data now.
import serial
try:
print "Trying..."
arduino = serial.Serial('/dev/ttyATH0',230400)
except:
print "Failed to connect on"
while True:
x=arduino.readline()
print x
Referral link:
Sharp Dust Sensor GP2Y1010AUSharp Dust Sensor Sample Code





