你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

基于STM32做一个万圣节智能南瓜灯!

[复制链接]
点点&木木 发布时间:2019-4-2 17:56
本帖最后由 点点&木木 于 2019-4-12 09:16 编辑

本次介绍的是一款基于STM32的3D打印的万圣节南瓜灯,并且当它听到周围的噪音时,会改变颜色并哼唱万圣节歌曲。


1.jpg



硬件组件
Zerynth Shield    ×      1      
Arduino       ×       1      
STM32 Nucleo ST Nucleo    ×     1      
粒子光子   ×       1      
Adafruit NeoPixel   ×  1      
3D打印的南瓜灯   × 1

万圣节即将到来,可能你需要一些东西来打动你的朋友。那么你可以试试这个项目:3D打印的万圣节南瓜灯,当它听到周围的噪音时会改变颜色并哼唱万圣节歌曲。设计非常简单,因为Zerynth (编程工具)和ZerynthShield (与Arduino和Particle板兼容的多传感器屏蔽)完成了大部分的工作。



第1步:所需材料

2.1.jpg



2.2.jpg



2.3.jpg



2.4.jpg



2.5.jpg



该项目需要的内容很少:

无论你使用哪种操作系统,Zerynth都会运行!只需下载包并安装它:http ://www.zerynth.com/zerynth-studio/
Arduino DUE 或ST NucleoF401RE 或Particle Photon 或Mikroe Flip&Click 。无论您使用哪种主板,Zerynth都是多板兼容的!您可以在Zerynth文档的专用部分中找到所有支持的板详细信息。
Zerynth,它是一个多板屏蔽,提供一组传感器和执行器,包括用于触摸检测的传感器,红外LED,麦克风,光传感器和温度传感器。
来自Adafruit的NeoPixel LED条(或环)(可在此处获取http://www.adafruit.com/products/1426
这个可爱的3D打印的杰克南瓜(http://www.thingiverse.com/thing:500762


第2步:组装


3.1.jpg


3.2.jpg


我相信没有比这更容易的了

Zerynth Shield配备了一套传感器,可以插入所有最常用的通信端口,使制造商,设计人员和物联网专业人员能够轻松开发智能物体,而无需担心布线和焊接。那么你的工作只需将Zerynth Shield搭载到您的Arduino上,并充分利用麦克风和蜂鸣器。

在Zerynth Shield中还有一个专门用于连接AdafruitNeopixel LED灯条的端口。端口引脚为:GND; VIN;LED控制引脚。

最后,将所有电路板和LED放入3D打印的南瓜灯中,您就完成了!



第3步:编程

4.jpg


连接并“虚拟化”您的电路板(已经解释过 http://bit.ly/Hackster-VIPER-Theremin
在Zerynth创建一个新项目(已在此处解释  http://bit.ly/Hackster-IoT-Notes-Printer
复制您在此hackster中可以找到的代码
将代码上传到您的主板上即可完成!
代码非常简单,有很多注释。



最后一步:享受它!

5.jpg

也许你想远程控制你的南瓜灯?使用Zerynth,您也可以轻松完成此操作!

请看上面的图片:通过移动设备控制的IoT环境光灯。相关教程已经准备就绪......请继续关注!




原理图
盾牌设置
只需将Zerynth Shield搭载到您的Arduino上,并充分利用麦克风和蜂鸣器。

将所有电路板和LED放入3D打印的南瓜灯中,您就完成了!


代码

################################################################################
# Smart Halloween Pumpkin Lamp
#
# Created by Zerynth Team 2015 CC
# Author: L. Rizzello
################################################################################
import streams
from community.floyd.rtttl import rtttl
import threading
# import toishield module
from toishield import toishield
# import neopixel module
from neopixel import ledstrips as neo
streams.serial()
# set detection enabled and pumpkininactive by default
toishield.microphone.detectionEnabled = True
toishield.microphone.activePumpkin = False
# set some variable for sound detection
toishield.microphone.staticMin = 4096
toishield.microphone.staticMax = -4096
toishield.microphone.resetMinMaxCounter = 0
# declare leds to blink!
leds = neo.ledstrip(toishield.led_pin, 16)
leds.setall(0,0,0)
leds.on()
# semaphore initialized to 0 -> red: ifa thread tries to acquire the semaphore
# it blocks if the semaphore has not beenturned 'green' (released)
semaphore = threading.Semaphore(0)
# define a RTTTL Halloween melody to beplayed by passing it the RTTTL string.
# find more songs athttp://ez4mobile.com/nokiatone/rtttf.htm and many other websites
hsong = rtttl.tune('Halloween:d=4,o=5,b=180:8d6,8g,8g,8d6,8g,8g,8d6,8g,8d#6,8g,8d6,8g,8g,8d6,8g,8g,8d6,8g,8d#6,8g,8c#6,8f#,8f#,8c#6,8f#,8f#,8c#6,8f#,8d6,8f#,8c#6,8f#,8f#,8c#6,8f#,8f#,8c#6,8f#,8d6,8f#')
# If you use Particle Photon uncomment thefollowing line and short-circuit the Buzzer and Aux2 pins
# toishield.buzzer_pin=D9.PWM
def blink():
    # blink while the pumpkin is active
    whiletoishield.microphone.activePumpkin:
       leds.setall(255,0,0)
       leds.on()
       sleep(500)
       leds.setall(255,140,0)
       leds.on()
       sleep(500)
   leds.setall(0,0,0)
   leds.on()
   semaphore.release()
def playHalloween():
    # plays halloween song two times, then disables pumpkin,but also waits
    # at the semaphore to synchronize with blinking thread
    for i in range(2):
       hsong.play(toishield.buzzer_pin)
   toishield.microphone.activePumpkin = False
   semaphore.acquire()
   sleep(1000)
    print("enabled again")
   toishield.microphone.detectionEnabled = True
def scare():
    # this is called when the sound exceeds the threshold,waits one second
    # and starts scaring!
    sleep(1000)
   thread(playHalloween)
   thread(blink)
# define a function that takes a sensorobject as parameter and checks the
# maximum peak to peak extension of thesignal in a preset window
# look at this
# example for details on how the sound detectorworks
def detectSound(obj):
    if(obj.resetMinMaxCounter == obj._observationWindowN):
       extension = obj.staticMax - obj.staticMin
       if (extension> 1000):
           ifobj.detectionEnabled:
                obj.detectionEnabled = False
                obj.activePumpkin = True
                thread(scare)
       obj.staticMax, obj.staticMin = -4096, 4096
       obj.resetMinMaxCounter = 0
    else:
       c = obj.currentSample()
       if (c >obj.staticMax):
           obj.staticMax = c
       elif (c < obj.staticMin):
           obj.staticMin = c
       obj.resetMinMaxCounter += 1
# set 'detectSound' as the function to beapplied to the object at every sampling step   
toishield.microphone.doEverySample(detectSound)
# start sampling at 1 millisecond (1 kHZ)with a window length of 50 so that
# the lowest detectable frequency is 20 Hz
toishield.microphone.startSampling(1,50,"raw")



收藏 评论2 发布时间:2019-4-2 17:56

举报

2个回答
Kevin201707 回答时间:2019-4-3 10:19:54
点赞
corrys 回答时间:2019-5-30 21:10:12
1有点意思

所属标签

STM32团队

意法半导体微控制器和微处理器拥有广泛的产品线,包含低成本的8位单片机和基于ARM® Cortex®-M0、M0+、M3、M4、M33、M7及A7内核并具备丰富外设选择的32位微控制器及微处理器


最新内容

相似分享

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版