Noduino Partical
来自Jack's Lab
目录 |
1 概述
Sharp GP2Y1010AU0F 灰尘颗粒传感器
此传感器为模拟接口,需要使用 ADC 读取传感器输出的电压值
Noduino 所用之 ESP8285/ESP8266 SoC 内置一个 ADC,精度尚可,芯片引脚为 TOUT,其测量电压电压范围为 0 - 1V
Noduino 开发板,做了一些处理,外接了一个 3:1 分压电路,引出到板上的标准接口为 A0,测量电压范围可到 0 - 3.3V
system_adc_read() 输出 0 - 1024 之间的一个整数,其单位为 1/1024V,因此,板之 A0 口电压计算如下:
3.0 * system_adc_read() / 1024
Datasheet: http://www.sparkfun.com/datasheets/Sensors/gp2y1010au_e.pdf
2 开发环境准备
根据您的系统,选择如下快速指南:
- Getting Started with Noduino SDK on Linux
- Getting Started with Noduino SDK on Mac OS X
- Getting Started with Noduino SDK on Windows
3 硬件准备
硬件接口:
Sharp pin 1 (V-LED) => 3.3V (connected to 150ohm resister) Sharp pin 2 (LED-GND) => GND Sharp pin 3 (LED) => Noduino D7 (GPIO16) Sharp pin 4 (S-GND) => GND Sharp pin 5 (Vo) => Noduino A0 pin Sharp pin 6 (Vcc) => 3.3V
4 Schemmatics
5 编译烧写
进入你的 sharp 目录:
$ cd /PATH/TO/noduino-sdk/examples/noduino/sharp
编译、上传一步完成:
$ make flash
不同平台下,你的串口设备号可能不一样,确认一下你的串口设备,Linux 下 Falcon 开发板可能被识别为 /dev/ttyUSB1(dmesg 查看),则:
$ make flash ESPPORT=/dev/ttyUSB1
Windows 下 Falcon 开发板可能被识别为 COM6(控制面板 --> 设备管理器里查看),则:
$ make flash ESPPORT=COM6
6 查看结果
上传完之后,用串口工具,用 115200 的波特率打开串口,即可看到串口在持续输出传感器测得的值:
Windows 下可用串口调试助手这类工具看
Linux 下推荐使用 picocom:
$ sudo apt-get install picocom $ picocom -b 115200 /dev/ttyUSB1 picocom v1.7 port is : /dev/ttyUSB2 flowcontrol : none baudrate is : 115200 parity is : none databits are : 8 escape is : C-a local echo is : no noinit is : no noreset is : no nolock is : no send_cmd is : sz -vv receive_cmd is : rz -vv imap is : omap is : emap is : crcrlf,delbs, Terminal ready ...... ......
Ctrl + a q 退出 picocom
7 代码示例
#include "noduino.h" int dustVal = 0; int ledPower = 16; int delayTime = 280; int delayTime2 = 40; int offTime = 9680; irom void setup() { serial_begin(115200); //disable the wifi wifi_set_opmode(NULL_MODE); pinMode(ledPower,OUTPUT); digitalWrite(ledPower,HIGH); serial_printf("Sharp GP2Y1010AU0F Particle Sensor Example\r\n"); } void loop() { digitalWrite(ledPower,LOW); // power on the LED delayMicroseconds(delayTime); dustVal = system_adc_read(); // read the dust value via A0 pin delayMicroseconds(delayTime2); digitalWrite(ledPower,HIGH); // turn the LED off delayMicroseconds(offTime); delay(3000); serial_printf("dush val = %d\r\n", dustVal); }
More details:
8 扩展阅读
- 更多问题参考: