流水源

  • 2024-10-30
  • 回复了主题帖: ST NUCLEO-WB09KE无法烧录问题

    这个问题有解决吗?

  • 2024-10-29
  • 发表了主题帖: 【2024 DigiKey 创意大赛】+基于Teensy4.1环境温湿度和气压监测

    本帖最后由 流水源 于 2024-10-29 23:48 编辑 一 作品简介 本次作品主要主要实现环境的温湿度以及大气压的监测显示。主控MCU使用的是Teensy4.1开发板,环境参数检测使用的是BME680传感器。BME680传感器集成了测量气体,温湿度,大气压等参数。外加电子罗盘传感器ICM20948,ICM20948可以检测3轴加速度,3轴角速度和3轴磁感应,用于设备姿态检测。设备上外加了3.5寸显示屏用于显示数据。做这个设备可以很方便观察当前环境状态,可以用于户外探险环境温湿度及大气压,海拔高度监测及电子罗盘功能,也可以用于家庭室内环境监测。 特意为本次项目做了一个Teensy4.1的扩展底板,底板上安装了BME680和ICM20948传感器,以及LCD显示屏。整体如下:     二 系统框图 整个系统框图如下所示。整体设计比较简单,主要实现数据读取和显示。BME680和ICM20948这两个传感器都是用I2C接口驱动,但是设备地址不一样,所以两个传感器接在同一个I2C接口,而LCD屏使用SPI接口驱动。     三、软件功能说明 本次软件开发使用的是ArduinoIDE开发环境开发的,之前用过几次Arduino开发,觉得这个很方便,基本上驱动都写好了,只用写应用。而且Teensy4.1推荐的开发环境也是用Arduino。 用arduino开发我们首先要安装Teensy4.1开发板。 开发板安装网址: https://www.pjrc.com/teensy/package_teensy_index.json     安装之后就可以开发选择Teensy4.1开发板的例子了。   接着我们还要下载BME680和ICM20948的驱动库了。 BME680传感器我选择的是Adafruit BME680的库。   ICM20948可以用下面2个库。我使用的是第2个库。   LCD驱动库选择如下DFRobot GDL。这个LCD是DFRobot的一个显示屏模块。     开发过程中参考了例子代码,然后将例子代码整合。     下面是设备初始化过程:     然后是传感器数据监测显示界面:     显示界面可以根据陀螺仪的姿态自动切换横竖屏显示。     通过串口打印数据如下:     四、作品源码 五、作品功能演示视频 [localvideo]d6b20522b222f9493ce8015108d0a829[/localvideo]   六、项目总结 通过本次大赛有一些收获,也发现了自己的一些不足。利用本次大赛我更加熟悉使用ArduinoIDE的开发环境使用,也学习了对BME680和ICM20948传感器的驱动使用.,特别是关于ICM20948这个9轴陀螺仪的姿态的计算方式。本次大赛时间有限,项目做的有点简陋,后面有机会继续完善一下,继续加点新功能。            

  • 2024-10-27
  • 加入了学习《 【2024 DigiKey创意大赛】 《智能起居室环境控制台》任务报告汇总》,观看 【2024 DigiKey创意大赛】 《智能起居室环境控制台》任务报告汇总

  • 2024-10-09
  • 发表了主题帖: 【2024 DigiKey 创意大赛】使用Teensy4.1读取传感器测试

    本次特意做了一个Teensy4.1的扩展底板,加上了传感器座子和LCD屏接口。实现了BME680和ICM20948传感器的数据读取和显示。   扩展版如下: 底板扩展了LCD屏接口,网口,USB HOST,arduino接口,can,rs485,rs232。     开发使用的是arduino ide。直接下载teensy4.1开发板资料库和传感器BME680,ICM20948驱动。 https://www.pjrc.com/teensy/package_teensy_index.json  Teensy4.1开发板添加网址。       lcd显示数据效果。              

  • 2024-08-31
  • 回复了主题帖: >>征集 | 使用 MCU,哪些问题最令你头大?

    MCU选型主要问题: 首先是外设资源要方便查看对比,需要的外设资源是否足够。 再就是开发工具是否容易上手,开发库SDK和demo例子是否容易应用。 最后就是开发遇到问题,能有技术支持。

  • 2024-08-27
  • 发表了主题帖: 【Follow me第二季第1期】+任务提交汇总

    本帖最后由 流水源 于 2024-10-9 20:56 编辑 主要任务提交汇总: 入门开发环境使用的是arduino ide开发的。搭建环境很简单,就不多说了。具体搭建如下帖子。 【Follow me第二季第1期】arduino开发环境的搭建和点灯 https://bbs.eeworld.com.cn/thread-1289879-1-1.html   下面是基础任务一(必做):控制板载炫彩LED,跑马灯点亮和颜色变换。主要使用了Adafruit Circuit Playground Express开发板,通过USB供电。 在如下帖子,实现彩灯跑马变幻颜色。 【Follow me第二季第1期】arduino控制板载炫彩跑马灯 https://bbs.eeworld.com.cn/thread-1289916-1-1.html       上面就是红绿蓝3种不同颜色的灯循环跑马效果了。 代码: ///////////////////////////////////////////////////////////////////////////////////////// //11111111111111111111111111111111111111111111111111111111111111111111111111111111111111 #if TASK_NUM == 1 #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> //基础任务一(必做):控制板载炫彩LED,跑马灯点亮和颜色变换 Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); Serial.begin(115200); cplay.begin(); cplay.setBrightness(50); } // the loop function runs over and over again forever void loop() { Serial.println(cplay.lightSensor()); Serial.println(cplay.temperature()); digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 25*i+25, 0, 0); // 设置LED为red色 delay(100); } cplay.clearPixels(); delay(100); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 0, 0, 25*i+25); // 设置LED为blue色 delay(100); } cplay.clearPixels(); delay(100); // wait for a second for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 0, 25*i+25, 0); // 设置LED为green色 delay(100); } cplay.clearPixels(); delay(100); // wait for a second } #endif   接着基础任务二(必做):监测环境温度和光线,通过板载LED展示舒适程度。主要使用了Adafruit Circuit Playground Express开发板,通过USB供电。 具体查看如下帖子: 【Follow me第二季第1期】监测环境温度和光线,通过板载LED展示舒适程度 https://bbs.eeworld.com.cn/thread-1290437-1-1.html 主要是取温度和光照一个舒适的数据范围,在范围内,所有10个彩灯为绿色呼吸。 前5颗彩灯标识温度舒适范围,在舒适范围内5个灯绿色呼吸,高于舒适温度范围用红色灯标识,灯的数量越多表示温度越高。低于舒适温度范围用蓝色灯标识,灯的数量越多表示温度越低。 后5颗彩灯标识光照舒适范围,在舒适范围内5个灯绿色呼吸,高于舒适光照范围用红色灯标识,灯的数量越多表示光照越强。低于舒适光照范围用蓝色灯标识,灯的数量越多表示光照越弱。 下面全绿灯表示温度和光照都在设置的舒适数据范围。     下面是光照超出舒适范围,太亮了。有一边显示红灯。   下面是温度不在舒适范围,太冷了。使用蓝色灯标识。   代码如下: #if TASK_NUM == 2 //2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> //基础任务二(必做):监测环境温度和光线,通过板载LED展示舒适程度 Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 uint32_t lightbress; uint8_t l_dir; int light_val; int temp_val; int g_state; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); Serial.begin(115200); cplay.begin(); cplay.setBrightness(50); lightbress = 0; l_dir = 0; g_state = 0; } // the loop function runs over and over again forever void loop() { light_val = cplay.lightSensor(); temp_val = cplay.temperature() * 100; Serial.println(light_val); Serial.println(temp_val); switch(g_state) { case 0: for (int i = 0; i < 10; i++) { cplay.strip.setPixelColor(i, 0, lightbress * 10, 0); // 设置LED为green色 } cplay.strip.show(); if(l_dir == 0) { lightbress++; if(lightbress == 15) l_dir = 1; }else { if(lightbress) lightbress--; else l_dir = 0; } if((light_val > 510) || (light_val < 190) || (temp_val > 3250)||(temp_val < 2950)) { lightbress = 0; g_state = 1; } break; case 1: //温度 int level; uint8_t r_color,g_color,b_color; if(temp_val > 3200) { level = (temp_val - 3200)/100; r_color = lightbress * 10; b_color = 0; g_color = 0; }else if(temp_val < 3000) { level = (3000 - temp_val)/100; b_color = lightbress * 10; r_color = 0; g_color = 0; }else { g_color = lightbress * 10; r_color = 0; b_color = 0; } if(level >= 5) level = 5; for (int i = 0; i < 5; i++) { if(i<level) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // 设置LED为blue red色 else cplay.strip.setPixelColor(i, 0, g_color, 0); // 设置LED为blue red色 } //光照 if(light_val > 500) { level = (light_val - 500)/80; r_color = lightbress * 10; b_color = 0; g_color = 0; }else if(light_val < 200) { level = (200 - light_val)/30; b_color = lightbress * 10; r_color = 0; g_color = 0; }else { g_color = lightbress * 10; r_color = 0; b_color = 0; } if(level >= 5) level = 5; for (int i = 5; i < 10; i++) { if(i>=(10-level)) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // 设置LED为blue red色 else cplay.strip.setPixelColor(i, 0, g_color, 0); // 设置LED为blue red色 } cplay.strip.show(); lightbress++; if(lightbress == 15) lightbress = 0; if((light_val <= 500) && (light_val >= 200) && (temp_val <= 3250) && (temp_val >= 2950)) { lightbress = 0; g_state = 0; } break; } delay(100); } #endif   接着是基础任务三(必做):接近检测——设定安全距离并通过板载LED展示,检测到入侵时,发起声音报警。 使用的是光照传感器来检测距离远近的。用手从远往近挡住光线传感器可以看到亮灯数变化。   具体帖子如下: 【Follow me第二季第1期】接近检测设定安全距离并通过板载LED展示 https://bbs.eeworld.com.cn/thread-1290460-1-1.html 使用光照来检测距离,环境光有很大影响。后面我尝试使用了红外发射和接收管来做了一下。但是使用红外时检测距离不是很大。 代码如下: #if TASK_NUM == 3 //333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333 //基础任务三(必做):接近检测——设定安全距离并通过板载LED展示,检测到入侵时,发起声音报警 #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 int light_val; int level; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); Serial.begin(115200); cplay.begin(); cplay.setBrightness(50); pinMode(CPLAY_IR_EMITTER, OUTPUT); digitalWrite(CPLAY_IR_EMITTER, LOW); // When not sending PWM, we want it low pinMode(A10, INPUT); } void loop() { uint8_t r_color,g_color,b_color; // light_val = cplay.lightSensor(); // Serial.println(light_val); // if(light_val < 350) // { // level = (350-light_val)/30; // if (CircuitPlayground.slideSwitch()) { // CircuitPlayground.speaker.enable(true); // Serial.println("Slide to the left"); // } // }else // { // level = 0; // CircuitPlayground.speaker.enable(false); // } // if(level > 7) // { // r_color = 0x50; // g_color = 0; // b_color = 0; // CircuitPlayground.playTone(500 + level * 500, 100); // }else if(level >4) // { // r_color = 0; // g_color = 0x50; // b_color = 0; // CircuitPlayground.playTone(500 + level * 500, 100); // }else // { // r_color = 0; // g_color = 0; // b_color = 0x50; // CircuitPlayground.playTone(500 + level * 500, 100); // } // for (int i = 0; i < 10; i++) // { // if(i<level) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // // else cplay.strip.setPixelColor(i, 0, 0, 0); // // } // cplay.strip.show(); // Measure the proximity level and use it to light up its LEDs. digitalWrite(CPLAY_IR_EMITTER, HIGH); delay(10); digitalWrite(CPLAY_IR_EMITTER, LOW); int prox = analogRead(A10); if(prox > 650) level = 11; else if(prox < 300) level = 0; else level = (prox - 300)/34; Serial.print("IR_Vol:");Serial.println(prox); Serial.print("Level: ");Serial.println(level); for (int i = 0; i < 10; i++) { if(i<level) cplay.strip.setPixelColor(i, 250, 0, 0); // else cplay.strip.setPixelColor(i, 0, 0, 0); // } CircuitPlayground.strip.show(); if (level > 4) { CircuitPlayground.playTone(330, 100); } delay(100); } #endif   再接着是进阶任务(必做):制作不倒翁——展示不倒翁运动过程中的不同灯光效果。 这个是通过读取加速度传感器来实现不同姿态显示灯光。通过Z轴加速度来确定倾斜的角度大小,角度越小就显示红色灯,角度越大实现蓝色灯垂下的效果。 通过X,Y轴加速度的数值来确定方位,通过正负值分为4个象限来显示周围的灯。 下面是倾斜不同角度的灯光效果。       当水平放置时,所有灯为红色,并且有个绿灯跑马灯效果。   代码: #if TASK_NUM == 4 //444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444 //进阶任务(必做):制作不倒翁——展示不倒翁运动过程中的不同灯光效果 #include <Adafruit_CircuitPlayground.h> #define LED_PIN 13 int x,y,z; uint8_t r,g,b; uint8_t led_color[16][4]; uint8_t led_num,led_index; // the setup function runs once when you press reset or power the board void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(115200); Serial.println("Circuit Playground test!"); CircuitPlayground.begin(); CircuitPlayground.strip.setBrightness(255); led_num = 6; led_index = 0; } void loop() { x = CircuitPlayground.motionX() * 100; y = CircuitPlayground.motionY() * 100; z = CircuitPlayground.motionZ() * 100; if((z > 900) || (z < -900)) led_num = 6; else if((z > 830) || (z < -830)) led_num = 5; else if((z > 750) || (z < -750)) led_num = 4; else if((z > 600) || (z < -600)) led_num = 3; else if((z > 300) || (z < -300)) led_num = 2; else led_num = 1; if(led_num < 6) { if((x>0) && (y>0)) //1 { int ttan = 100*y / x; if(ttan < 26) led_index = 9; else if(ttan < 100) led_index = 10; else if(ttan < 373) led_index = 11; else led_index = 0; }else if((x<0) && (y>0)) //2 { int ttan = 0 - (100*y / x); if(ttan < 26) led_index = 3; else if(ttan < 100) led_index = 2; else if(ttan < 373) led_index = 1; else led_index = 0; }else if((x<0) && (y<0)) //3 { int ttan = (100*y / x); if(ttan < 26) led_index = 3; else if(ttan < 100) led_index = 4; else if(ttan < 373) led_index = 5; else led_index = 6; }else if((x>0) && (y<0)) //4 { int ttan = 0 - (100*y / x); if(ttan < 26) led_index = 9; else if(ttan < 100) led_index = 8; else if(ttan < 373) led_index = 7; else led_index = 6; } }else { led_index ++; led_index %= 12; } for (int i = 1; i <= 6; i++) { if(i<=led_num) { led_color[(led_index + i) % 12 ][0] = 0x80; led_color[(led_index + i) % 12 ][1] = 0; led_color[(led_index + i) % 12 ][2] = 0; led_color[(12 + led_index - i) % 12 ][0] = 0x80; led_color[(12 + led_index - i) % 12 ][1] = 0; led_color[(12 + led_index - i) % 12 ][2] = 0; }else { led_color[(led_index + i) % 12 ][0] = 0; led_color[(led_index + i) % 12 ][1] = 0; led_color[(led_index + i) % 12 ][2] = 0x30; led_color[(12 + led_index - i) % 12 ][0] = 0; led_color[(12 + led_index - i) % 12 ][1] = 0; led_color[(12 + led_index - i) % 12 ][2] = 0x30; } } led_color[(led_index )][0] = 0; led_color[(led_index )][1] = 0xF0; led_color[(led_index )][2] = 0; for (int i = 1; i < 12; i++) { if(i<6) { CircuitPlayground.strip.setPixelColor(i-1,led_color[i][0], led_color[i][1], led_color[i][2]); // } else if(i>6) { CircuitPlayground.strip.setPixelColor(i-2,led_color[i][0], led_color[i][1], led_color[i][2]); // } } CircuitPlayground.strip.show(); /************* TEST ACCEL */ // Display the results (acceleration is measured in m/s*s) Serial.print("X: "); Serial.print(x); Serial.print(" \tY: "); Serial.print(y); Serial.print(" \tZ: "); Serial.print(z); Serial.println(" m/s^2"); delay(50); digitalWrite(LED_PIN, HIGH); delay(50); digitalWrite(LED_PIN, LOW); } #endif   最后是创意任务:钢琴弹奏,通过触摸引脚弹奏音乐,并配合灯光效果。 板上有7个触摸端口,正好可以对应do、re、mi、fa、sol、la、si 7个音节。这里还实现了通过左右按键来改变低,中,高音。   主要代码如下: #if TASK_NUM == 5 //5555555555555555555555555555555555555555555555555555555555555555555555555555555 //创意任务三:水果钢琴——通过触摸水果弹奏音乐,并配合灯光效果 #include <Adafruit_CircuitPlayground.h> #define LED_PIN 13 #define TONE_DURATION_MS 80 // Duration in milliseconds to play a tone when touched. uint16_t CAP_THRESHOLD = 200; // Threshold for a capacitive touch (higher = less sensitive). uint8_t playSound; uint16_t cap_val; uint8_t music_lmh = 1; //0-低音,1-中音,2-高音 uint16_t music_hz_tbl[3][8]= //音频对照表 { {262, 294, 330, 349, 392, 440, 494, 0}, {523, 587, 659, 698, 784, 880, 988, 0}, {1046, 1175, 1318, 1397, 1568, 1760, 1976, 0}, }; void setup() { pinMode(LED_PIN, OUTPUT); Serial.begin(115200); Serial.println("Circuit Playground test!"); CircuitPlayground.begin(); CAP_THRESHOLD = 600; } void loop() { if (CircuitPlayground.slideSwitch()) { if(playSound) Serial.println("Slide to the left"); playSound = 0; } else { if(!playSound) Serial.println("Slide to the right"); playSound = 1; } /************* TEST BOTH BUTTONS */ if (CircuitPlayground.leftButton()) { Serial.println("Left level ++"); music_lmh++; if(music_lmh>2) music_lmh=2; while(CircuitPlayground.leftButton()) delay(10); } if (CircuitPlayground.rightButton()) { Serial.println("Right level --"); if(music_lmh) music_lmh--; while(CircuitPlayground.rightButton()) delay(10); } //清除灯 for (int i=0; i<10; ++i) { CircuitPlayground.strip.setPixelColor(i, 0); } CircuitPlayground.strip.show(); //11111111111111111111111111111111 cap_val = CircuitPlayground.readCap(3); if (cap_val >= CAP_THRESHOLD) { Serial.print("#1:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(0)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][0], TONE_DURATION_MS); // 262hz = C4 } } //2222222222222222222222222222222 cap_val = CircuitPlayground.readCap(2); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t#2:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][1], TONE_DURATION_MS); // 294hz = D4 } } //333333333333333333333333333333333 cap_val = CircuitPlayground.readCap(0); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t\t#3:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10*3)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][2], TONE_DURATION_MS); // 330hz = E4 } } //4444444444444444444444444444444444 cap_val = CircuitPlayground.readCap(1); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t\t\t#4:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10*4)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][3], TONE_DURATION_MS); // 349hz = F4 } } //555555555555555555555555555555555 cap_val = CircuitPlayground.readCap(6); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t\t\t\t#5:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10*5)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][4], TONE_DURATION_MS); // 392hz = G4 } } //66666666666666666666666666666666666 cap_val = CircuitPlayground.readCap(9); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t\t\t\t\t#6:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10*6)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][5], TONE_DURATION_MS); // 440hz = A4 delay(5); } } //7777777777777777777777777777777777777 cap_val = CircuitPlayground.readCap(10); if (cap_val >= CAP_THRESHOLD) { Serial.print("\t\t\t\t\t\t#7:"); Serial.println(cap_val); if (playSound) { for (int i=0; i<10; ++i) CircuitPlayground.strip.setPixelColor(i, CircuitPlayground.colorWheel(256/10*8)); CircuitPlayground.strip.show(); CircuitPlayground.playTone(music_hz_tbl[music_lmh][6], TONE_DURATION_MS); // 494hz = B4 } } delay(30); } #endif   代码文件:   最后总结:     第一次参加这个活动,比较顺利完成了上述任务。这次参加活动主要使用了arduino ide来开发,也是初次使用这个arduino。以前也听说了很多arduino的优势,但是没怎么用过。当初参加活动也是为了学习一下arduino的开发方式。所以开始的时候花了不少时间熟悉这个arduino开发环境,总的来说用过之后感觉用这个arduino开发太方便了,外设所有驱动都写好了,直接写应用就可以了。再就是这个Adafruit Circuit Playground Express开发板上面板载外设多,功能强大,不需要外接设备就可以做很多创意了,这也是吸引我的地方。   下面就是整个任务的视频效果。 视频: [localvideo]49fb950afe097f7e6b1cd3624da1432c[/localvideo]    

  • 2024-08-25
  • 加入了学习《【Follow me第二季第1期】汇总任务报告》,观看 【Follow me第二季第1期】汇总任务报告

  • 2024-08-14
  • 回复了主题帖: 【Follow me第二季第1期】接近检测设定安全距离并通过板载LED展示

    秦天qintian0303 发表于 2024-8-13 21:03 有一个人用这种方法后就大家都用这种方法了,只能说也算是一种方法,不过明显是希望用红外反射的方法进行 ... 就是红外应该只是个开关信号,就做不了渐变

  • 回复了主题帖: 【Follow me第二季第1期】接近检测设定安全距离并通过板载LED展示

    wangerxian 发表于 2024-8-13 19:13 光线传感器测量接近距离?那环境光影响不是很大咯? 环境光如果在变化肯定是有影响的。利用红外的进行接近检测还没研究出来,晚点尝试一下红外的

  • 回复了主题帖: 【2024 DigiKey 创意大赛】开箱贴

    wangerxian 发表于 2024-8-13 19:20 哪个板子上有这么多传感器?没看到呀。 那2个小板子上都是传感器

  • 2024-08-13
  • 发表了主题帖: 【Follow me第二季第1期】接近检测设定安全距离并通过板载LED展示

    下面实现基础任务三(必做):接近检测——设定安全距离并通过板载LED展示,检测到入侵时,发起声音报警。 原理是利用光线传感器来确定距离远近。当光线变弱时说明接近中,当光线数据增大说明远离中。 本次实现当接近光线变弱,数据变小时,点亮彩灯,越近亮的彩灯数越多。而且接近过程中,根据距离远近,灯光由蓝色变绿色然后变红色。 使用arduino开发,代码如下: #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 int light_val; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); Serial.begin(115200); cplay.begin(); cplay.setBrightness(50); } void loop() { int level; uint8_t r_color,g_color,b_color; light_val = cplay.lightSensor(); Serial.println(light_val); if(light_val < 350) { level = (350-light_val)/30; if (CircuitPlayground.slideSwitch()) { CircuitPlayground.speaker.enable(true); Serial.println("Slide to the left"); } }else { level = 0; CircuitPlayground.speaker.enable(false); } if(level > 7) { r_color = 0x50; g_color = 0; b_color = 0; CircuitPlayground.playTone(500 + level * 500, 100); }else if(level >4) { r_color = 0; g_color = 0x50; b_color = 0; CircuitPlayground.playTone(500 + level * 500, 100); }else { r_color = 0; g_color = 0; b_color = 0x50; CircuitPlayground.playTone(500 + level * 500, 100); } for (int i = 0; i < 10; i++) { if(i<level) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // else cplay.strip.setPixelColor(i, 0, 0, 0); // } cplay.strip.show(); if (CircuitPlayground.leftButton()) { Serial.println("Left button pressed!"); } if (CircuitPlayground.rightButton()) { Serial.println("Right button pressed!"); } delay(100); }   实现的效果如下: [localvideo]42e4bf800212bd86da5f8ed8d26ba80d[/localvideo]    

  • 发表了主题帖: 【Follow me第二季第1期】监测环境温度和光线,通过板载LED展示舒适程度

    本帖最后由 流水源 于 2024-8-13 15:13 编辑 本次实现的是基础任务二(必做):监测环境温度和光线,通过板载LED展示舒适程度。 通过读取板上温度传感器和光线检测传感器。设定适宜的温度和光照范围。 当在适宜的范围内,10个彩灯为绿色呼吸状态。 当温度超过上限,一边显示红色呼吸,超出越多亮的灯越多。当温度低于下限时,显示蓝色呼吸,低的越多,亮的灯越多。 当光照超过上限,另一边显示红色呼吸,超出越多亮的灯越多。当光照低于下限时,显示蓝色呼吸,低的越多,亮的灯越多。 还是使用arduino开发,代码如下: #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> //基础任务二(必做):监测环境温度和光线,通过板载LED展示舒适程度 Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 uint32_t lightbress; uint8_t l_dir; int light_val; int temp_val; int g_state; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); Serial.begin(115200); cplay.begin(); cplay.setBrightness(50); lightbress = 0; l_dir = 0; g_state = 0; } // the loop function runs over and over again forever void loop() { light_val = cplay.lightSensor(); temp_val = cplay.temperature() * 100; Serial.println(light_val); Serial.println(temp_val); switch(g_state) { case 0: for (int i = 0; i < 10; i++) { cplay.strip.setPixelColor(i, 0, lightbress * 10, 0); // 设置LED为green色 } cplay.strip.show(); if(l_dir == 0) { lightbress++; if(lightbress == 15) l_dir = 1; }else { if(lightbress) lightbress--; else l_dir = 0; } if((light_val > 510) || (light_val < 190) || (temp_val > 3250)||(temp_val < 2950)) { lightbress = 0; g_state = 1; } break; case 1: //温度 int level; uint8_t r_color,g_color,b_color; if(temp_val > 3200) { level = (temp_val - 3200)/100; r_color = lightbress * 10; b_color = 0; g_color = 0; }else if(temp_val < 3000) { level = (3000 - temp_val)/100; b_color = lightbress * 10; r_color = 0; g_color = 0; }else { g_color = lightbress * 10; r_color = 0; b_color = 0; } if(level >= 5) level = 5; for (int i = 0; i < 5; i++) { if(i<level) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // 设置LED为blue red色 else cplay.strip.setPixelColor(i, 0, g_color, 0); // 设置LED为blue red色 } //光照 if(light_val > 500) { level = (light_val - 500)/80; r_color = lightbress * 10; b_color = 0; g_color = 0; }else if(light_val < 200) { level = (200 - light_val)/30; b_color = lightbress * 10; r_color = 0; g_color = 0; }else { g_color = lightbress * 10; r_color = 0; b_color = 0; } if(level >= 5) level = 5; for (int i = 5; i < 10; i++) { if(i>=(10-level)) cplay.strip.setPixelColor(i, r_color, g_color, b_color); // 设置LED为blue red色 else cplay.strip.setPixelColor(i, 0, g_color, 0); // 设置LED为blue red色 } cplay.strip.show(); lightbress++; if(lightbress == 15) lightbress = 0; if((light_val <= 500) && (light_val >= 200) && (temp_val <= 3250) && (temp_val >= 2950)) { lightbress = 0; g_state = 0; } break; } delay(100); }   编译下载后,实现效果如下: 正常舒适范围: [localvideo]4e6f90ad23efbd97714a4e45c1b91b67[/localvideo] 光照下: [localvideo]35252238660bd592abf722704ef30c51[/localvideo] 把板子放到空调下吹冷,然后温度上升到舒适 [localvideo]7da3e50341728545cd2f46c720a5dead[/localvideo]        

  • 发表了主题帖: 【2024 DigiKey 创意大赛】开箱贴

    买了RT1062 Teensy 4.1 i.MX ARM® Cortex®-M7 MPU 评估板,AK09916,ICM-20948加速计,陀螺仪,磁力计,传感器Qwiic,STEMMA QT平台评估扩展板,BME680气体,湿度,压力,温度传感器Qwiic,STEMMA QT平台评估扩展板。主要是RT1062 NXP的mpu和各种传感器。这次得捷发货挺快的。 下一步开始搞项目了。                  

  • 2024-08-07
  • 发表了主题帖: 【Follow me第二季第1期】arduino控制板载炫彩跑马灯

    首先升级安装Adafruit_Circuit_Playground库,目前是V1.12.0版本。     然后在arduino代码中添加Adafruit_Circuit_Playground库。       然后初始化Adafruit_Circuit_Playground库,以及彩灯初始化。   炫彩跑马灯代码如下: #include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> Adafruit_CircuitPlayground cplay = Adafruit_CircuitPlayground(); #define LED_PIN 13 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); cplay.begin(); cplay.setBrightness(50); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 25*i+25, 0, 0); // 设置LED为red色 delay(100); } cplay.clearPixels(); delay(300); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 0, 0, 25*i+25); // 设置LED为blue色 delay(100); } cplay.clearPixels(); delay(100); // wait for a second for (int i = 0; i < 10; i++) { cplay.setPixelColor(i, 0, 25*i+25, 0); // 设置LED为green色 delay(100); } cplay.clearPixels(); delay(100); // wait for a second } 编译下载之后就可以看到跑马灯了。     效果如下: [localvideo]59a5277baecd047e05a53e7e8a073322[/localvideo]                      

  • 加入了学习《【Follow me第二季第1期】使用Makecode图形化完成任务》,观看 【Follow me第二季第1期】使用Makecode图形化完成任务

  • 发表了主题帖: 【Follow me第二季第1期】arduino开发环境的搭建和点灯

    参考资料:https://learn.adafruit.com/adafruit-circuit-playground-express/set-up-arduino-ide 首先打开arduino软件,在开发板管理器搜索 Arduino SAMD Boards,然后安装开发板即可。   这里我已经安装完成了。   下一步就可以编写代码编译点灯了。如果板子驱动无法自动安装,可以安装如下驱动软件:   选择开发板和下载串口:     先写个简单的点灯代码。LED灯在D13端口。 #define LED_PIN 13 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(300); // wait for a second digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW delay(100); // wait for a second } 编译下载:   点灯效果,D13红灯亮灭。        

  • 2024-05-20
  • 发表了主题帖: 【Beetle ESP32 C6迷你开发板】+通过网络获取天气信息

    ESP32-C6支持很多无线通信协议,下面就通过wifi获取天气信息。 本次获取天气使用的是心知天气服务。使用该服务需要注册心知天气账号,获取个人使用的API KEY。 下面是获取天气的接口:   也可以获取3天内的天气(免费版):   下面就是代码实现了。首先就是需要WIFI,JSON,和HTTPClient库支持。 #include <WiFi.h> #include <Arduino_JSON.h> #include <HTTPClient.h> const char *ssid = "SSID"; //WIFI名称 const char *pwd = "PWD"; //WIFI密码 //填入你获得的API Key String openWeatherMapApiKey = "API KEY"; //String http_api_str = "https://api.seniverse.com/v3/weather/now.json?key=your_api_key&location=beijing&language=zh-Hans&unit=c" //now //返回例子 //{"results":[ //{"location":{"id":"WX4FBXXFKE4F","name":"北京","country":"CN","path":"北京,北京,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"}, //"now":{"text":"晴","code":"0","temperature":"22"},"last_update":"2024-05-20T10:22:03+08:00"} //]} //3Day https://api.seniverse.com/v3/weather/daily.json?key=your_api_key&location=beijing&language=zh-Hans&unit=c&start=0&days=3 //返回例子 //{"results": //[{"location":{"id":"WS0E9D8WN298","name":"广州","country":"CN","path":"广州,广州,广东,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"}, //"daily":[ // {"date":"2024-05-20","text_day":"大雨","code_day":"15","text_night":"雷阵雨","code_night":"11","high":"25","low":"21","rainfall":"29.50","precip":"0.92","wind_direction":"东","wind_direction_degree":"90","wind_speed":"23.4","wind_scale":"4","humidity":"91"}, // {"date":"2024-05-21","text_day":"雷阵雨","code_day":"11","text_night":"雷阵雨","code_night":"11","high":"27","low":"21","rainfall":"1.29","precip":"0.24","wind_direction":"无持续风向","wind_direction_degree":"","wind_speed":"8.4","wind_scale":"2","humidity":"87"}, // {"date":"2024-05-22","text_day":"雷阵雨","code_day":"11","text_night":"雷阵雨","code_night":"11","high":"28","low":"24","rainfall":"0.88","precip":"0.22","wind_direction":"无持续风向","wind_direction_degree":"","wind_speed":"3.0","wind_scale":"1","humidity":"91"}], //"last_update":"2024-05-20T08:00:00+08:00"} //]} 获取天气服务的JSON数据。  //获取天气JSON数据 String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; //连接网址 http.begin(client, serverName); //发送HTTP站点请求 int httpResponseCode = http.GET(); //该数组用于储存获得的数据 String payload = "{}"; //将获得的数据放入数组 if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } //释放资源 http.end(); //返回获得的数据用于Json处理 return payload; } 初始化连接WIFI热点: WiFi.mode(WIFI_MODE_STA); Serial.println(WiFi.macAddress()); WiFi.begin(ssid, pwd); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected!"); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); 定时循环获取天气信息: //发送HTTP获取请求 if ((millis() - lastTime) > timerDelay) { timerDelay = 60000; //检测WIFI是否已经连接 if(WiFi.status()== WL_CONNECTED) { String serverPath = "http://api.seniverse.com/v3/weather/now.json?key=" + openWeatherMapApiKey + "&location=" + city + "&language=en&unit=c"; Serial.println("======================================================================="); //将组合好的URL放入httpGETRequest函数中通过HTTP获取请求以获得文本 jsonBuffer = httpGETRequest(serverPath.c_str()); Serial.println(jsonBuffer); //将解析的Json对象值储存在Jsonu缓冲区中 JSONVar myObject = JSON.parse(jsonBuffer); //判断解析是否成功 if (JSON.typeof(myObject) == "undefined") { Serial.println("Parsing input failed!"); return; } Serial.println("======================================================================="); // Serial.print("JSON object = "); // Serial.println(myObject); Serial.print("Weather: "); Serial.println(myObject["results"][0]["now"]["text"]); Serial.print("Code: "); Serial.println(myObject["results"][0]["now"]["code"]); Serial.print("Temperature: "); Serial.println(myObject["results"][0]["now"]["temperature"]); Serial.println("======================================================================="); } else { Serial.println("WiFi Disconnected"); } lastTime = millis(); } 下面是打印输出的天气信息:   整体代码如下: #include <WiFi.h> #include <Wire.h> #include <Arduino_JSON.h> #include <HTTPClient.h> #include <RPR-0521RS.h> #include <shtc3.h> RPR0521RS rpr0521rs; SHTC3 d_shtc3; #define myLED 15 //设置引脚15为LED引脚 const char *ssid = "SSID"; //WIFI名称 const char *pwd = "PWD"; //WIFI密码 //填入你获得的API Key String openWeatherMapApiKey = "API KEY";//你的心知天气API KEY //String http_api_str = "https://api.seniverse.com/v3/weather/now.json?key=your_api_key&location=beijing&language=zh-Hans&unit=c" //now //返回例子 //{"results":[ //{"location":{"id":"WX4FBXXFKE4F","name":"北京","country":"CN","path":"北京,北京,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"}, //"now":{"text":"晴","code":"0","temperature":"22"},"last_update":"2024-05-20T10:22:03+08:00"} //]} //3Day https://api.seniverse.com/v3/weather/daily.json?key=your_api_key&location=beijing&language=zh-Hans&unit=c&start=0&days=3 //返回例子 //{"results": //[{"location":{"id":"WS0E9D8WN298","name":"广州","country":"CN","path":"广州,广州,广东,中国","timezone":"Asia/Shanghai","timezone_offset":"+08:00"}, //"daily":[ // {"date":"2024-05-20","text_day":"大雨","code_day":"15","text_night":"雷阵雨","code_night":"11","high":"25","low":"21","rainfall":"29.50","precip":"0.92","wind_direction":"东","wind_direction_degree":"90","wind_speed":"23.4","wind_scale":"4","humidity":"91"}, // {"date":"2024-05-21","text_day":"雷阵雨","code_day":"11","text_night":"雷阵雨","code_night":"11","high":"27","low":"21","rainfall":"1.29","precip":"0.24","wind_direction":"无持续风向","wind_direction_degree":"","wind_speed":"8.4","wind_scale":"2","humidity":"87"}, // {"date":"2024-05-22","text_day":"雷阵雨","code_day":"11","text_night":"雷阵雨","code_night":"11","high":"28","low":"24","rainfall":"0.88","precip":"0.22","wind_direction":"无持续风向","wind_direction_degree":"","wind_speed":"3.0","wind_scale":"1","humidity":"91"}], //"last_update":"2024-05-20T08:00:00+08:00"} //]} const char *ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 8 * 3600; const int daylightOffset_sec = 0; // 填写城市名以及国家简写 String city = "GuangZhou"; String jsonBuffer; unsigned long lastTime = 0; //设置每10分钟获得一次天气数据 unsigned long timerDelay = 10000; //打印时间 void printLocalTime() { struct tm timeinfo; if (!getLocalTime(&timeinfo)) { Serial.println("Failed to obtain time"); return; } Serial.println(&timeinfo, "%F %T %A"); // 格式化输出 } //获取天气JSON数据 String httpGETRequest(const char* serverName) { WiFiClient client; HTTPClient http; //连接网址 http.begin(client, serverName); //发送HTTP站点请求 int httpResponseCode = http.GET(); //该数组用于储存获得的数据 String payload = "{}"; //将获得的数据放入数组 if (httpResponseCode>0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); payload = http.getString(); } else { Serial.print("Error code: "); Serial.println(httpResponseCode); } //释放资源 http.end(); //返回获得的数据用于Json处理 return payload; } //==================================================================================================================================================== void setup() { byte rc; pinMode(myLED, OUTPUT); digitalWrite(myLED, HIGH); Serial.begin(115200); Serial.println("******************************** senser test *******************************************"); //set the resolution to 12 bits (0-4096) analogReadResolution(12); Wire.begin(); rc = rpr0521rs.init(); Serial.print(F("RPR-0521RS Init = ")); Serial.println(rc); rc = d_shtc3.Init(); Serial.print(F("SHTC3 Init = ")); Serial.println(rc); WiFi.mode(WIFI_MODE_STA); Serial.println(WiFi.macAddress()); WiFi.begin(ssid, pwd); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected!"); Serial.print("Connected to WiFi network with IP Address: "); Serial.println(WiFi.localIP()); // 从网络时间服务器上获取并设置时间 // 获取成功后芯片会使用RTC时钟保持时间的更新 configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printLocalTime(); lastTime = millis(); } //==================================================================================================================================================== void loop() { byte rc; byte near_far; unsigned short ps_val; float als_val; int temp; int rh; digitalWrite(myLED, HIGH); delay(100); printLocalTime(); Serial.println("----------------------------------------"); // read the analog / millivolts value for pin 2: int analogValue = analogRead(0); int analogVolts = analogReadMilliVolts(0); // print out the values you read: Serial.print("ADC analog value = "); Serial.println(analogValue); Serial.print("ADC millivolts value = "); Serial.print(analogVolts); Serial.println("mV"); // Please adjust the calculation coefficient according to the actual measurement. Serial.print("BAT millivolts value = "); Serial.print(analogVolts * 2.1218 + 1000); Serial.println("mV"); Serial.println("----------------------------------------"); delay(100); rc = rpr0521rs.get_psalsval(&ps_val, &als_val); if (rc == 0) { Serial.print(F("RPR-0521RS (Proximity) = ")); Serial.print(ps_val); near_far = rpr0521rs.check_near_far(ps_val); if (near_far == RPR0521RS_NEAR_VAL) { Serial.print(F(" Near,")); } else { Serial.print(F(" Far,")); } if (als_val != RPR0521RS_ERROR) { Serial.print(F("\t (Ambient Light) = ")); Serial.print(als_val); Serial.println(F("[lx].")); } } delay(100); rc = d_shtc3.GetMode1_TempRH(&temp, &rh); if (rc == 0) { Serial.print(F("SHTC3 Temp = ")); Serial.print(temp); Serial.print("^C,"); Serial.print(F(" \t RH = ")); Serial.print(rh); Serial.println("%"); Serial.println(); } digitalWrite(myLED, LOW); delay(800); //发送HTTP获取请求 if ((millis() - lastTime) > timerDelay) { timerDelay = 60000; //检测WIFI是否已经连接 if(WiFi.status()== WL_CONNECTED) { String serverPath = "http://api.seniverse.com/v3/weather/now.json?key=" + openWeatherMapApiKey + "&location=" + city + "&language=en&unit=c"; Serial.println("======================================================================="); //将组合好的URL放入httpGETRequest函数中通过HTTP获取请求以获得文本 jsonBuffer = httpGETRequest(serverPath.c_str()); Serial.println(jsonBuffer); //将解析的Json对象值储存在Jsonu缓冲区中 JSONVar myObject = JSON.parse(jsonBuffer); //判断解析是否成功 if (JSON.typeof(myObject) == "undefined") { Serial.println("Parsing input failed!"); return; } Serial.println("======================================================================="); // Serial.print("JSON object = "); // Serial.println(myObject); Serial.print("Weather: "); Serial.println(myObject["results"][0]["now"]["text"]); Serial.print("Code: "); Serial.println(myObject["results"][0]["now"]["code"]); Serial.print("Temperature: "); Serial.println(myObject["results"][0]["now"]["temperature"]); // Serial.print("Pressure: "); // //myObject["now"]["pressure"]前为{}前的引号内容,后为读取哪一个引号后数据 // Serial.println(myObject["now"]["pressure"]); // Serial.print("Humidity: "); // Serial.println(myObject["now"]["humidity"]); // Serial.print("Wind Speed: "); // Serial.println(myObject["now"]["wind_speed"]); Serial.println("======================================================================="); } else { Serial.println("WiFi Disconnected"); } lastTime = millis(); } }        

  • 2024-05-13
  • 发表了主题帖: 【Beetle ESP32 C6迷你开发板】+基于arduino读取温湿度传感器SHTC3数据

    SHTC3简单说明         SHTC3是一个检测温度和湿度的传感器,可以检测-40℃~125℃的温度范围和0%~100%的湿度范围,典型精度为±2 %RH和±0.2°C。         SHTC3的工作电压范围为:1.62V~3.6V。         SHTC3使用的通讯方式是I2C,通讯速率可以达到400KHz。         SHTC3只有4个引脚,电源和地、2个I2C通讯引脚。         SHTC3的I2C设备地址为0x70。     下面就是SHTC3的驱动程序。要注意SHTC3的寄存器是16位的2个字节。 #ifndef __DRV_SHTC3_H #define __DRV_SHTC3_H /*========================================================================= I2C ADDRESS/BITS -----------------------------------------------------------------------*/ #define SHTC3_ADDRESS (0x70) #define SHTC3_CRC_POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001 /*=========================================================================*/ /*========================================================================= REGISTERS -----------------------------------------------------------------------*/ //ID16BIT:B15 to 12 & 10 to 6: unspecified info.bits 11 & 5 to 0: SHTC3 identifier #define SHTC3_REG_ID (0xEFC8) //xxxx 1xxx xx00 0111 #define SHTC3_REG_SLEEP (0xB098) // #define SHTC3_REG_WAKEUP (0x3517) // #define SHTC3_REG_RESET (0x805D) // //Mode1 #define SHTC3_REG_CENM_TEMP_RH (0x7CA2) //��ͨģʽ����ʱ�䳤��>10ms #define SHTC3_REG_CENM_RH_TEMP (0x5C24) // #define SHTC3_REG_CELPM_TEMP_RH (0x6458) //�͹���ģʽ����ʱ���: <1ms #define SHTC3_REG_CELPM_RH_TEMP (0x44DE) // //Mode2 #define SHTC3_REG_CDNM_TEMP_RH (0x7866) // #define SHTC3_REG_CDNM_RH_TEMP (0x58E0) // #define SHTC3_REG_CDLPM_TEMP_RH (0x609C) // #define SHTC3_REG_CDLPM_RH_TEMP (0x401A) // //============================================================================== class SHTC3 { public: SHTC3(void); int Init(void) ; byte GetMode1_TempRH(int *temp, int *humi); byte write(unsigned int memory_address, unsigned char *data, int size); byte read (unsigned int memory_address, unsigned char *data, int size); private: uint16_t shtc3_id; }; #endif 下面是操作SHTC3的寄存器接口。要注意SHTC3的寄存器是16位的2个字节。 #include <Arduino.h> #include <Wire.h> #include "shtc3.h" byte SHTC3::write(unsigned int memory_address, unsigned char *data, int size) { byte rc; Wire.beginTransmission(SHTC3_ADDRESS); Wire.write((memory_address>>8) & 0xFF); Wire.write(memory_address & 0xFF); if((data != NULL) && (size != 0)) Wire.write(data, size); rc = Wire.endTransmission(); return (rc); } byte SHTC3::read(unsigned int memory_address, unsigned char *data, int size) { byte rc; unsigned int cnt; Wire.beginTransmission(SHTC3_ADDRESS); Wire.write((memory_address>>8) & 0xFF); Wire.write(memory_address & 0xFF); rc = Wire.endTransmission(false); if (rc != 0) { return (rc); } Wire.requestFrom(SHTC3_ADDRESS, size, true); if((data != NULL) && (size != 0)) { cnt = 0; while(Wire.available()) { data[cnt] = Wire.read(); cnt++; } } return (0); } 将驱动程序添加到Arduino的库文件夹下。下面是测试读取代码。 #include <Wire.h> #include <RPR-0521RS.h> #include <shtc3.h> RPR0521RS rpr0521rs; SHTC3 d_shtc3; #define myLED 15 //设置引脚15为LED引脚 void setup() { byte rc; pinMode(myLED, OUTPUT); digitalWrite(myLED, HIGH); Serial.begin(115200); Serial.println("******************************** senser test *******************************************"); Wire.begin(); rc = rpr0521rs.init(); Serial.print(F("RPR-0521RS Init = ")); Serial.println(rc); rc = d_shtc3.Init(); Serial.print(F("SHTC3 Init = ")); Serial.println(rc); } void loop() { byte rc; byte near_far; unsigned short ps_val; float als_val; int temp; int rh; digitalWrite(myLED, HIGH); delay(100); rc = rpr0521rs.get_psalsval(&ps_val, &als_val); if (rc == 0) { Serial.print(F("RPR-0521RS (Proximity) = ")); Serial.print(ps_val); near_far = rpr0521rs.check_near_far(ps_val); if (near_far == RPR0521RS_NEAR_VAL) { Serial.print(F(" Near,")); } else { Serial.print(F(" Far,")); } if (als_val != RPR0521RS_ERROR) { Serial.print(F("\t (Ambient Light) = ")); Serial.print(als_val); Serial.println(F("[lx].")); } } delay(100); rc = d_shtc3.GetMode1_TempRH(&temp, &rh); if (rc == 0) { Serial.print(F("SHTC3 Temp = ")); Serial.print(temp); Serial.print("^C,"); Serial.print(F(" \t RH = ")); Serial.print(rh); Serial.println("%"); Serial.println(); } digitalWrite(myLED, LOW); delay(800); } 通过串口输出信息,可以看到温湿度读取成功。       资料:

  • 2024-05-08
  • 回复了主题帖: 【Beetle ESP32 C6迷你开发板】+扩展传感器底板分享

    wangerxian 发表于 2024-5-7 18:40 两个屏幕嘛?有两个接口。 就一个,一边正接线序,一边反接线序

  • 2024-05-07
  • 发表了主题帖: 【Beetle ESP32 C6迷你开发板】+基于arduino读取接近光照传感器RPR-0521RS数据

    RPR-0521RS是将光学式接近传感器和红外LED(IrLED)、数字照度传感器整合在一起的传感器。 接近传感器 (PS)通过对IrLED发射光线的接近物产生的反射光,检测出人及物体的接近。另外,照度传感器(ALS)可测量从昏暗光线到直射日光的广泛照度。根据照度数据调整LCD显示器及按键的亮度,从而提高组件的节电性能和画面的可视性。 RPR-0521RS系列光学传感器特点: · 兼容I2C BUS接口(支持f/s模式); · 兼容1.8V逻辑接口; ·掉电模式下,电流损耗低; ·有两种ALS输出值:可见光(Data0)对应光谱响应峰值;红外线光(Data1)对应光照度计算。 ·能检测到从黑暗环境乃至直接太阳光照的环境范围,具有广泛的照度测量; ·具有抑制(工频)50Hz/60Hz光噪声(ALS功能下); ·光学接近传感探测范围在1~100mm(可通过I2C接口调整); ·内置电流配置的IrLED驱动器;   在网上找到rpr-0521rs的arduino库,现在来测试一下,读取传感器数值。   传感器接如下I2C引脚。   代码如下: /***************************************************************************** RPR-0521RS.ino Copyright (c) 2016 ROHM Co.,Ltd. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ #include <Wire.h> #include <RPR-0521RS.h> RPR0521RS rpr0521rs; #define myLED 15 //设置引脚15为LED引脚 void setup() { byte rc; pinMode(myLED, OUTPUT); digitalWrite(myLED, HIGH); Serial.begin(115200); Serial.println("******************************** senser test *******************************************"); Wire.begin(); rc = rpr0521rs.init(); } void loop() { byte rc; unsigned short ps_val; float als_val; byte near_far; digitalWrite(myLED, HIGH); delay(100); rc = rpr0521rs.get_psalsval(&ps_val, &als_val); if (rc == 0) { Serial.print(F("RPR-0521RS (Proximity) = ")); Serial.print(ps_val); Serial.print(F(" [count]")); near_far = rpr0521rs.check_near_far(ps_val); if (near_far == RPR0521RS_NEAR_VAL) { Serial.println(F(" Near")); } else { Serial.println(F(" Far")); } if (als_val != RPR0521RS_ERROR) { Serial.print(F("RPR-0521RS (Ambient Light) = ")); Serial.print(als_val); Serial.println(F(" [lx]")); Serial.println(); } } digitalWrite(myLED, LOW); delay(1000); } 编译烧写   然后复位,可以看到串口输出数据如下:   硬件如下:    

最近访客

< 1/2 >

统计信息

已有21人来访过

  • 芯积分:1372
  • 好友:--
  • 主题:13
  • 回复:16

留言

你需要登录后才可以留言 登录 | 注册


现在还没有留言