Noduino TSL2561
来自Jack's Lab
目录 |
1 开发环境准备
根据您的系统,选择如下快速指南:
- Getting Started with Noduino SDK on Linux
- Getting Started with Noduino SDK on Mac OS X
- Getting Started with Noduino SDK on Windows
2 硬件准备
此传感器为 I2C 接口,Falcon 接线方式如下:
- Sensor_SCL --> Noduino_Falcon_D9
- Sensor_SDA --> Noduino_Falcon_D8
- Sensor_3V3 --> Noduino_Falcon_3V3
- Sensor_GND --> Noduino_Falcon_GND
NodeC / SmartNode 接线方式如下:
- Sensor_SCL --> SmartNode_IO5
- Sensor_SDA --> SmartNode_IO4
- Sensor_3V3 --> SmartNode_3V3
- Sensor_GND --> SmartNode_GND
3 编译烧写
进入你的 tsl2561 目录:
$ cd /PATH/TO/noduino-sdk/examples/noduino/tsl2561
编译、上传一步完成:
$ make flash
不同平台下,你的串口设备号可能不一样,确认一下你的串口设备,Linux 下 Falcon 开发板可能被识别为 /dev/ttyUSB1(dmesg 查看),则:
$ make flash ESPPORT=/dev/ttyUSB1
Windows 下 Falcon 开发板可能被识别为 COM6(控制面板 --> 设备管理器里查看),则:
$ make flash ESPPORT=COM6
4 查看结果
上传完之后,用串口工具,用 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
5 代码示例
#include "noduino.h"
#include "tsl2561.h"
irom void setup()
{
serial_begin(115200);
if (!tsl2561_begin(TSL2561_ADDR_LOW)) {
serial_print("Could not found TSL2561 sensor!\r\n");
while (1) {}
}
tsl2561_setGain(TSL2561_GAIN_16X); // set 16x gain (for dim situations)
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
tsl2561_setTiming(TSL2561_INTEGRATIONTIME_13MS); // shortest integration time (bright light)
}
void loop()
{
// Simple data read example. Just read the infrared, fullspecrtrum diode
// or 'visible' (difference between the two) channels.
// This can take 13-402 milliseconds! Uncomment whichever of the following you want to read
uint16_t x = tsl2561_getLuminosity(TSL2561_VISIBLE);
serial_printf("Luminosity:\t %d\r\n", x);
// More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
// That way you can do whatever math and comparisons you want!
uint32_t lum = tsl2561_getFullLuminosity();
uint16_t ir, full;
ir = lum >> 16;
full = lum & 0xFFFF;
serial_printf("IR:\t\t %d\r\n", ir);
serial_printf("Full: ", full);
serial_printf("Visible:\t %d\r\n", full - ir);
serial_printf("Lux:\t\t %d\r\n\n", tsl2561_calculateLux(full, ir));
delay(3000);
}
6 扩展阅读
- 更多问题参考: