如何使用ArduinoIDE设置ESP32

材料清单
esp32
ambimate ms4多传感器模块
面包板和跳线
usb连接器
arduino ide(软件)
什么是ambimate ms4?
ambimate传感器模块ms4系列集成了一套传感器,用于楼宇自动化和连接家庭应用到pcb组件上。它在即用型pcb组件上提供了一组专用传感器,可轻松集成到主机产品中。
传感器包括运动,光线,温度,湿度,vso(挥发性有机化合物),co2和声音检测。通过捕获voc浓度来增加监测空气质量的能力。有许多ms4系列传感器可用 - 我建议您选择带有嵌入式麦克风的传感器来增强运动检测或者能够收听声音事件。
所有ms4系列传感器模块都可以灵活地共享一个通用的七位连接。这使得设计人员可以布置单个pcb封装,以适应生产中所有可用的传感器配置。
ms4应用
室内照明
能源管理
楼宇自动化
工作空间舒适度
区域环境控制
自动化
空气质量测量系统
ms4规范
在ms4版本1中-2314291-2有九个传感器用于:
运动(pir)
温度
湿度

运动(pir)
温度
声音(麦克风)
voc
co2
ms4 pinout
将esp32连接到ms4
按如下方式将ms4连接到esp32:
使用arduino ide设置esp32
按照下面的屏幕截图所示的步骤使用arduino ide对esp32进行编程。
单击文件》首选项
添加url链接。您可以通过逗号分隔其他链接。
https://dl.espressif.com/dl/package_esp32_index.json
单击 确定 。
单击工具》板》板管理器
搜索 esp32 并安装包。
再次转到 工具 并选择 esp32板 和 com端口。
上传源代码
复制下面的源代码,将其粘贴到arduino ide中,然后上传。您可能需要在上传过程中长按esp32板上的启动按钮。
#include
unsigned char buf[20];
unsigned char opt_sensors;
int incomingbyte = 0;
int loopcount = 0;
char showtemp = 0, showhum = 0, showlight = 0, showsound = 0, degcorf = 0, showco2 = 0, showvoc = 0, showpwr = 0, showevents = 0;
string sampperiodtxt;
float sampperiod = 1;
void setup() {
// put your setup code here, to run once:
wire.begin(); // join i2c bus (address optional for master)
serial.begin(9600); // start serial for output monitor
}
void restart_info() {
// data and basic information are acquired from the module
wire.begintransmission(0x2a); // transmit to device
wire.write(byte(0x80)); // sends instruction to read firmware version
wire.endtransmission(); // stop transmitting
wire.requestfrom(0x2a, 1); // request byte from slave device
unsigned char fw_ver = wire.read(); // receive a byte
wire.begintransmission(0x2a); // transmit to device
wire.write(byte(0x81)); // sends instruction to read firmware subversion
wire.endtransmission(); // stop transmitting
wire.requestfrom(0x2a, 1); // request byte from slave device
unsigned char fw_sub_ver = wire.read(); // receive a byte
wire.begintransmission(0x2a); // transmit to device
wire.write(byte(0x82)); // sends instruction to read optional sensors byte
wire.endtransmission(); // stop transmitting
wire.requestfrom(0x2a, 1); // request byte from slave device
opt_sensors = wire.read(); // receive a byte
delay(1000);
//if device contains additional co2 and audio sensor, it is indicated here
serial.print(“ambimate sensors: 4 core”);
if (opt_sensors & 0x01)
serial.print(“ + co2”);
if (opt_sensors & 0x04)
serial.print(“ + audio”);
serial.println(“ ”);
serial.print(“ambimate firmware version ”);
serial.print(fw_ver);
serial.print(“。”);
serial.println(fw_sub_ver);
serial.print(“select which sensors to receive data from: ”);
serial.print(“temperature [y/n]: ”);
while (serial.available() == 0);
showtemp = serial.read();
serial.println(showtemp);
serial.print(“deg c or f [c/f]: ”);
while (serial.available() == 0);
degcorf = serial.read();
serial.println(degcorf);
serial.print(“humidity [y/n]: ”);
while (serial.available() == 0);
showhum = serial.read();
serial.println(showhum);
serial.print(“ambient light [y/n]: ”);
while (serial.available() == 0);
showlight = serial.read();
serial.println(showlight);
if (opt_sensors & 0x04)
{
serial.print(“audio [y/n]: ”);
while (serial.available() == 0);
showsound = serial.read();
serial.println(showsound);
}
if (opt_sensors & 0x01)
{
serial.print(“eco2 [y/n]: ”);
while (serial.available() == 0);
showco2 = serial.read();
serial.println(showco2);
serial.print(“voc [y/n]: ”);
while (serial.available() == 0);
showvoc = serial.read();
serial.println(showvoc);
}
serial.print(“power [y/n]: ”);
while (serial.available() == 0);
showpwr = serial.read();
serial.println(showpwr);
serial.print(“pir and motion events [y/n]: ”);
while (serial.available() == 0);
showevents = serial.read();
serial.println(showevents);
serial.print(“ ”);
serial.print(“sample interval[secs]: ”);
while (serial.available() == 0);
sampperiodtxt = “”;
while (serial.available() 》 0)
{
int inchar = serial.read();
sampperiodtxt += (char)inchar;
}
serial.println(sampperiodtxt);
sampperiod = sampperiodtxt.tofloat();
if (sampperiod 《 0.5)
{
sampperiod = 0.5;
serial.print(“input exceeds limits, sample period set to minimum, 0.5 seconds ”);
}
sampperiod = sampperiod * 1000; // convert to msecs
}
//top line of headings are printed using the following
void printlabels(void) {
serial.println(“ ”);
serial.println(“ ”);
// construct the first line of the headings
if ((showtemp == ‘y’) || (showtemp == ‘y’))
serial.print(“temperature ”);
if ((showhum == ‘y’) || (showhum == ‘y’))
serial.print(“humidity ”);
if ((showlight == ‘y’) || (showlight == ‘y’))
serial.print(“light ”);
if (opt_sensors & 0x04)
{
if ((showsound == ‘y’) || (showsound == ‘y’))
serial.print(“audio ”);
}
if (opt_sensors & 0x01)
{
if ((showco2 == ‘y’) || (showco2 == ‘y’))
serial.print(“eco2 ”);
if ((showvoc == ‘y’) || (showvoc == ‘y’))
serial.print(“voc ”);
}
if ((showpwr == ‘y’) || (showpwr == ‘y’))
serial.print(“power ”);
if ((showevents == ‘y’) || (showevents == ‘y’))
serial.print(“event ”);
else
serial.print(“ ”);
// construct the second line of the headings
if ((showtemp == ‘y’) || (showtemp == ‘y’))
{
if ((degcorf == ‘f’) || (degcorf == ‘f’))
serial.print(“deg f ”);
else
serial.print(“deg c ”);
}
if ((showhum == ‘y’) || (showhum == ‘y’))
serial.print(“% ”);
if ((showlight == ‘y’) || (showlight == ‘y’))
serial.print(“lux ”);
if (opt_sensors & 0x04)
{
if ((showsound == ‘y’) || (showsound == ‘y’))
serial.print(“db ”);
}
if (opt_sensors & 0x01)
{
if ((showco2 == ‘y’) || (showco2 == ‘y’))
serial.print(“ppm ”);
if ((showvoc == ‘y’) || (showvoc == ‘y’))
serial.print(“ppb ”);
}
if ((showpwr == ‘y’) || (showpwr == ‘y’))
serial.print(“volts”);
serial.print(“ ”);
}
//loop starts here
void loop() {
if (loopcount == 0)
{
restart_info();
loopcount = 1;
}
if (loopcount == 1)
{
printlabels();
loopcount = 2;
}
// all sensors except the co2 sensor are scanned in response to this command
wire.begintransmission(0x2a); // transmit to device
// device address is specified in datasheet
wire.write(byte(0xc0)); // sends instruction to read sensors in next byte
wire.write(0xff); // 0xff indicates to read all connected sensors
wire.endtransmission(); // stop transmitting
// delay to make sure all sensors are scanned by the ambimate
delay(100);
wire.begintransmission(0x2a); // transmit to device
wire.write(byte(0x00)); // sends instruction to read sensors in next byte
wire.endtransmission(); // stop transmitting
wire.requestfrom(0x2a, 15); // request 6 bytes from slave device
// acquire the raw data
unsigned int i = 0;
while (wire.available()) { // slave may send less than requested
buf[i] = wire.read(); // receive a byte as character and store in buffer
i++;
}
// convert the raw data to engineering units, see application spec for more information
unsigned int status = buf[0];
float temperaturec = (buf[1] * 256.0 + buf[2]) / 10.0;
float temperaturef = ((temperaturec * 9.0) / 5.0) + 32.0;
float humidity = (buf[3] * 256.0 + buf[4]) / 10.0;
unsigned int light = (buf[5] * 256.0 + buf[6]);
unsigned int audio = (buf[7] * 256.0 + buf[8]);
float batvolts = ((buf[9] * 256.0 + buf[10]) / 1024.0) * (3.3 / 0.330);
unsigned int co2_ppm = (buf[11] * 256.0 + buf[12]);
unsigned int voc_ppm = (buf[13] * 256.0 + buf[14]);
if ((showtemp == ‘y’) || (showtemp == ‘y’))
{
if ((degcorf == ‘f’) || (degcorf == ‘f’))
serial.print(temperaturef, 1);
else
serial.print(temperaturec, 1);
serial.print(“ ”);
}
if ((showhum == ‘y’) || (showhum == ‘y’))
{
serial.print(humidity, 1);
serial.print(“ ”);
}
if ((showlight == ‘y’) || (showlight == ‘y’))
{
serial.print(light);
serial.print(“ ”);
}
if (opt_sensors & 0x04)
{
if ((showsound == ‘y’) || (showsound == ‘y’))
{
serial.print(audio);
serial.print(“ ”);
}
}
if (opt_sensors & 0x01)
{
if ((showco2 == ‘y’) || (showco2 == ‘y’))
{
serial.print(co2_ppm);
serial.print(“ ”);
}
if ((showvoc == ‘y’) || (showvoc == ‘y’))
{
serial.print(voc_ppm);
serial.print(“ ”);
}
}
if ((showpwr == ‘y’) || (showpwr == ‘y’))
{
serial.print(batvolts);
serial.print(“ ”);
}
if ((showevents == ‘y’) || (showevents == ‘y’))
{
if (status & 0x80)
serial.print(“ pir_event”);
if (status & 0x02)
serial.print(“ audio_event”);
if (status & 0x01)
serial.print(“ motion_event”);
}
serial.print(“ ”);
// all sensors except the co2voc sensor are scanned at this rate.
// co2/voc sensor is only updated in ambimate every 60 seconds
delay(sampperiod - 100);
incomingbyte = serial.read();
if ((incomingbyte == ‘r’) || (incomingbyte == ‘r’))
{
//serial.print(“got r ”);
loopcount = 0;
}
}
上传代码后,点击串行监视器。
选择你想要的传感器喜欢通过输入‘ y ’来选择它。
您现在可以看到传感器数据进来。
我希望这个超级传感器模块能够为您未来的项目提供便利!

新能源的泡沫主要在上游
中央空调和风管机的区别是什么 浅谈中央空调选择方法
全球首个天基蜂窝语音通话,打通了,这个重大新闻非常值得关注
OLED下一代显示技术已经是行业共识,海信电视转战OLED趋势不可逆转
采用磁致伸缩技术的位移传感器
如何使用ArduinoIDE设置ESP32
深圳鹏坝通道正式通车!智慧灯杆助力智慧交通
STM32G431之串口详解
华为云DevRun智联生活行业加速器会为企业提供什么
你靠什么来连接这些网络设备?
国产铁电存储器PB85RS2MC可用于自动CPAP,不需要电池
TXGA DC电源插座,为各类便携式设备实现高效的直流供电
2018年会发布哪些手机 预计发布时间
电源EMI滤波器基本原理及结构_电源滤波器性能参数
锂离子电池和干电池的差别,锂离子电池和干电池哪个好
EMI/RFI 对调幅收音机有何影响?
新版发布 | 合宙Air105最新RTT支持、扫码枪TurnKey 、低功耗、拍照功能,哪个你最爱?
iphone8、华为Mate10什么时候上市最新消息汇总:配置、外观、系统、价格对比分析选谁?
STM32如何实现W25X16的汉字字库存储
「行业分析」汽车制造行业