The Project board is for sharing projects based on Silicon Labs' component with other community members. View Projects Guidelines ›

Projects

    Publish
     
      • Thunderboard Sense kit Sound Alarm and notification in Telegram

        Namo_Aton | 11/334/2016 | 07:01 PM

        Hello everyone.

        Few days ago I received the new Thunderboard Sense kit and I decide to make sound alarm which will notify me on telegram. 

        Firstly I create bot and get token. How to do this you can read here https://core.telegram.org/bots 

        Then I install on my raspberypi bluepy and telepot modules for python

         

        sudo pip install telepot
        sudo pip install bluepy

         

         

        Ok! Now we are ready for experiments.

        Firstly we need to know which characteristics are responsible for onboard LED and microphone sensor.

        Let`s create simple python script  and discover all present characteristics on Thunderboard Sense kit.

         

        from bluepy.btle import *
        import struct
        
        
        def ble_micro_handle():
            scanner = Scanner(0)
            devices = scanner.scan(3)
            for dev in devices:
                 print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
               
                 for (adtype, desc, value) in dev.getScanData():
                     print "  %s = %s" % (desc, value)
            num_ble = len(devices)
            print num_ble
            if num_ble==0:
                return None
            ble_mic = []
            char_sensor = 0
            non_sensor = 0
            led_char = Characteristic
            mic_char = Characteristic
            led_handle =0
            
            for i in range(num_ble):
                try:
                    devices[i].getScanData()
                    ble_mic.append(Peripheral())
                    ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
                    char_sensor = char_sensor + 1
                    print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
                except:
                    non_sensor = non_sensor + 1
            try:
                for i in range(char_sensor):
                    services = ble_mic[i].getServices()
                    characteristics = ble_mic[i].getCharacteristics()
                    for k in characteristics:
                        print k
                        if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
                            print "LED CONTROL FOUND"
                            led_char = k
                            led_handle = k.getHandle()
                        if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
                            print "MIC SENSOR FOUND"
                            mic_char = k            
            except:
                return None

         

        This is our result

         

        Characteristic <Device Name>
        Characteristic <Appearance>
        Characteristic <Service Changed>
        Characteristic <Manufacturer Name String>
        Characteristic <Model Number String>
        Characteristic <Serial Number String>
        Characteristic <Hardware Revision String>
        Characteristic <Firmware Revision String>
        Characteristic <System ID>
        Characteristic <Battery Level>
        Characteristic <UV Index>
        Characteristic <Pressure>
        Characteristic <Temperature>
        Characteristic <Humidity>
        Characteristic <c8546913-bfd9-45eb-8dde-9f8754f4a32e>
        Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e>
        MIC SENSOR FOUND
        Characteristic <c8546913-bf03-45eb-8dde-9f8754f4a32e>
        Characteristic <ec61a454-ed01-a5e8-b8f9-de9ec026ec51>
        Characteristic <efd658ae-c401-ef33-76e7-91b00019103b>
        Characteristic <efd658ae-c402-ef33-76e7-91b00019103b>
        Characteristic <efd658ae-c403-ef33-76e7-91b00019103b>
        Characteristic <fcb89c40-c601-59f3-7dc3-5ece444a401b>
        Characteristic <fcb89c40-c602-59f3-7dc3-5ece444a401b>
        Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b>
        LED CONTROL FOUND
        Characteristic <fcb89c40-c604-59f3-7dc3-5ece444a401b>
        Characteristic <2a56>
        Characteristic <2a56>
        Characteristic <c4c1f6e2-4be5-11e5-885d-feff819cdc9f>
        Characteristic <b7c4b694-bee3-45dd-ba9f-f3b5e994f49a>
        Characteristic <71e30b8c-4131-4703-b0a0-b0bbba75856b>

        Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic  in this project to get current value from microphone.

         

        LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.

        First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.

        So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.

         

        As I mentioned above we will poll the microphone and constrain it value to  the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values. 

        And  finally ALARM. When  obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.

        Here is a code:

        from bluepy.btle import *
        import struct
        import thread
        import telepot
        from datetime import datetime
        print   datetime.now().time()
        bot = telepot.Bot('HERE MUST BE YOUR TOKEN')
        bot_data = bot.getMe()
        print bot_data
        response = bot.getUpdates()
        print response
        bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"HELLO MAX")
        def map(x, in_min, in_max, out_min, out_max):
            return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
        
        
        def SENSE_handle():
            scanner = Scanner(0)
            devices = scanner.scan(3)
            for dev in devices:
                 print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
              
                 for (adtype, desc, value) in dev.getScanData():
                     print "  %s = %s" % (desc, value)
            num_ble = len(devices)
            print num_ble
            if num_ble==0:
                return None
            ble_mic = []
            char_sensor = 0
            non_sensor = 0
            led_char = Characteristic
            mic_char = Characteristic
            led_handle =0
            
            for i in range(num_ble):
                try:
                    devices[i].getScanData()
                    ble_mic.append(Peripheral())
                    ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
                    char_sensor = char_sensor + 1
                    print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
                except:
                    non_sensor = non_sensor + 1
            try:
                for i in range(char_sensor):
                    
                    services = ble_mic[i].getServices()
                    characteristics = ble_mic[i].getCharacteristics()
                    for k in characteristics:
                        print k
                        if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
                            print "LED CONTROL FOUND"
                            led_char = k
                            led_handle = k.getHandle()
                        if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
                            print "MIC SENSOR FOUND"
                            mic_char = k
                    
            except:
                return None
            
            led_bytes =[0xFF,0x00,0x00,0x00]
            last_value = 0x00
            while True:
                mic_data = mic_char.read()
                mic_data_value =(ord(mic_data[1])<<8)+ord(mic_data[0])
                led =map(mic_data_value, 4100, 9999, 0, 0xff)
                print "LED     :",led
                print "LAST VAL:",last_value
                if led >150:
                    bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"SOUND ALERT"+str(datetime.now().time()))
                if last_value < led:
                    while last_value<=led:
                        print "LAST VALUE LOWER"
                        led_bytes[1]=last_value
                        # led_bytes[2]=led
                        led_bytes[3]=last_value
                        s =""
                        for i in led_bytes:
                            s+=chr(i)
                       
                        ble_mic[0].writeCharacteristic(led_handle,s,True)
                        last_value=last_value+10
                if last_value > led:
                    print "LAST VALUE HIGHER"
                    while last_value>led:              
                        led_bytes[1]=last_value
                        # led_bytes[2]=led
                        led_bytes[3]=last_value
                        s =""
                        for i in led_bytes:
                            s+=chr(i)                
                        ble_mic[0].writeCharacteristic(led_handle,s,True)
                        last_value=last_value-10
                last_value = led       
            
              
        while True:
            SENSE_handle()

        And now video how it works

         

      • Thunderboard Sense kit Sound Alarm and notification in Telegram

        Namo_Aton | 11/334/2016 | 07:01 PM

        Hello everyone.

        Few days ago I received the new Thunderboard Sense kit and I decide to make sound alarm which will notify me on telegram. 

        Firstly I create bot and get token. How to do this you can read here https://core.telegram.org/bots 

        Then I install on my raspberypi bluepy and telepot modules for python

         

        sudo pip install telepot
        sudo pip install bluepy

         

         

        Ok! Now we are ready for experiments.

        Firstly we need to know which characteristics are responsible for onboard LED and microphone sensor.

        Let`s create simple python script  and discover all present characteristics on Thunderboard Sense kit.

         

        from bluepy.btle import *
        import struct
        
        
        def ble_micro_handle():
            scanner = Scanner(0)
            devices = scanner.scan(3)
            for dev in devices:
                 print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
               
                 for (adtype, desc, value) in dev.getScanData():
                     print "  %s = %s" % (desc, value)
            num_ble = len(devices)
            print num_ble
            if num_ble==0:
                return None
            ble_mic = []
            char_sensor = 0
            non_sensor = 0
            led_char = Characteristic
            mic_char = Characteristic
            led_handle =0
            
            for i in range(num_ble):
                try:
                    devices[i].getScanData()
                    ble_mic.append(Peripheral())
                    ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
                    char_sensor = char_sensor + 1
                    print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
                except:
                    non_sensor = non_sensor + 1
            try:
                for i in range(char_sensor):
                    services = ble_mic[i].getServices()
                    characteristics = ble_mic[i].getCharacteristics()
                    for k in characteristics:
                        print k
                        if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
                            print "LED CONTROL FOUND"
                            led_char = k
                            led_handle = k.getHandle()
                        if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
                            print "MIC SENSOR FOUND"
                            mic_char = k            
            except:
                return None

         

        This is our result

         

        Characteristic <Device Name>
        Characteristic <Appearance>
        Characteristic <Service Changed>
        Characteristic <Manufacturer Name String>
        Characteristic <Model Number String>
        Characteristic <Serial Number String>
        Characteristic <Hardware Revision String>
        Characteristic <Firmware Revision String>
        Characteristic <System ID>
        Characteristic <Battery Level>
        Characteristic <UV Index>
        Characteristic <Pressure>
        Characteristic <Temperature>
        Characteristic <Humidity>
        Characteristic <c8546913-bfd9-45eb-8dde-9f8754f4a32e>
        Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e>
        MIC SENSOR FOUND
        Characteristic <c8546913-bf03-45eb-8dde-9f8754f4a32e>
        Characteristic <ec61a454-ed01-a5e8-b8f9-de9ec026ec51>
        Characteristic <efd658ae-c401-ef33-76e7-91b00019103b>
        Characteristic <efd658ae-c402-ef33-76e7-91b00019103b>
        Characteristic <efd658ae-c403-ef33-76e7-91b00019103b>
        Characteristic <fcb89c40-c601-59f3-7dc3-5ece444a401b>
        Characteristic <fcb89c40-c602-59f3-7dc3-5ece444a401b>
        Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b>
        LED CONTROL FOUND
        Characteristic <fcb89c40-c604-59f3-7dc3-5ece444a401b>
        Characteristic <2a56>
        Characteristic <2a56>
        Characteristic <c4c1f6e2-4be5-11e5-885d-feff819cdc9f>
        Characteristic <b7c4b694-bee3-45dd-ba9f-f3b5e994f49a>
        Characteristic <71e30b8c-4131-4703-b0a0-b0bbba75856b>

        Microphone Characteristic <c8546913-bf02-45eb-8dde-9f8754f4a32e> we can only READ, there is no notification or indication.We will periodically poll this characteristic  in this project to get current value from microphone.

         

        LED Control Characteristic <fcb89c40-c603-59f3-7dc3-5ece444a401b> we can READ, WRITE and INDICATE. In this project we will use only WRITE possibility. To control LEDs we must write 4 bytes into this characteristic: 0xff,0x00,0x00,0x00.

        First byte 0xff are used to ON all 4 led. Other 3 bytes are RED,GREEN,BLUE colors. Any value from 0x00 to 0xff can be written for specified color. Combination of them create many pretty colors.

        So if we write 0xff,0x00,0x00,0ff then we get the bright BLUE color for all four onboard LEDs.

         

        As I mentioned above we will poll the microphone and constrain it value to  the range from 0x00 to 0xff, and then write bytes array to the LED CONTROL Characteristic. But It would be bored and simple,so I add some smooth transition for our LED between values. 

        And  finally ALARM. When  obtained value from microphone will be higher than established treshold, our bot must send a message to Telegram account.

        Here is a code:

        from bluepy.btle import *
        import struct
        import thread
        import telepot
        from datetime import datetime
        print   datetime.now().time()
        bot = telepot.Bot('HERE MUST BE YOUR TOKEN')
        bot_data = bot.getMe()
        print bot_data
        response = bot.getUpdates()
        print response
        bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"HELLO MAX")
        def map(x, in_min, in_max, out_min, out_max):
            return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
        
        
        def SENSE_handle():
            scanner = Scanner(0)
            devices = scanner.scan(3)
            for dev in devices:
                 print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
              
                 for (adtype, desc, value) in dev.getScanData():
                     print "  %s = %s" % (desc, value)
            num_ble = len(devices)
            print num_ble
            if num_ble==0:
                return None
            ble_mic = []
            char_sensor = 0
            non_sensor = 0
            led_char = Characteristic
            mic_char = Characteristic
            led_handle =0
            
            for i in range(num_ble):
                try:
                    devices[i].getScanData()
                    ble_mic.append(Peripheral())
                    ble_mic[char_sensor].connect(devices[i].addr,devices[i].addrType)
                    char_sensor = char_sensor + 1
                    print "Connected %s device with addr %s " % (char_sensor, devices[i].addr)
                except:
                    non_sensor = non_sensor + 1
            try:
                for i in range(char_sensor):
                    
                    services = ble_mic[i].getServices()
                    characteristics = ble_mic[i].getCharacteristics()
                    for k in characteristics:
                        print k
                        if k.uuid=="fcb89c40-c603-59f3-7dc3-5ece444a401b":
                            print "LED CONTROL FOUND"
                            led_char = k
                            led_handle = k.getHandle()
                        if k.uuid == "c8546913-bf02-45eb-8dde-9f8754f4a32e":
                            print "MIC SENSOR FOUND"
                            mic_char = k
                    
            except:
                return None
            
            led_bytes =[0xFF,0x00,0x00,0x00]
            last_value = 0x00
            while True:
                mic_data = mic_char.read()
                mic_data_value =(ord(mic_data[1])<<8)+ord(mic_data[0])
                led =map(mic_data_value, 4100, 9999, 0, 0xff)
                print "LED     :",led
                print "LAST VAL:",last_value
                if led >150:
                    bot.sendMessage(HERE_ID_WHERE_YOU_WANT_TO_SEND_MESSAGE,"SOUND ALERT"+str(datetime.now().time()))
                if last_value < led:
                    while last_value<=led:
                        print "LAST VALUE LOWER"
                        led_bytes[1]=last_value
                        # led_bytes[2]=led
                        led_bytes[3]=last_value
                        s =""
                        for i in led_bytes:
                            s+=chr(i)
                       
                        ble_mic[0].writeCharacteristic(led_handle,s,True)
                        last_value=last_value+10
                if last_value > led:
                    print "LAST VALUE HIGHER"
                    while last_value>led:              
                        led_bytes[1]=last_value
                        # led_bytes[2]=led
                        led_bytes[3]=last_value
                        s =""
                        for i in led_bytes:
                            s+=chr(i)                
                        ble_mic[0].writeCharacteristic(led_handle,s,True)
                        last_value=last_value-10
                last_value = led       
            
              
        while True:
            SENSE_handle()

        And now video how it works

         

      • EZR32 WDS script donwload firmware (Easy config)

        atomamp | 11/328/2016 | 03:18 PM

        Description:

        This program can use in a EFM32,EZR32, EFR32 MCU. The WDS generated script files and patch file can download with a simple terminal to the MCU and the program convert the data to Pro2 API code and send to the SPI bus to PRO2 chip. Complete API Command, Property  and Register read/write support.

         

        The API command are here: http://www.silabs.com/Support%20Documents/TechnicalDocs/EZRadioPRO_REVC2_API.zip

        Features:

        • patch file download
        • WDS batch file download
        • Read Rx buffer
        • Read CMD buffer
        • Set IO ports
        • Read IO ports
        • Reset radio command
        • USB communication if hardware support it
        • Routed radio GPIO0/1 to PA0/1 (connector P30/31)

        The Firmware

        The program communicate with the Pro2 chip over SPI bus and the PC over Uart or USB. The pc side needs a terminal program like Robot tongueUTTY The serial protocol supports the ANSI/ VT100 Terminal ESC sequences. The terminal settings are the following:

        • Flow control: RTS/CTS
        • Baud rate: 57600
        • 8 data, no parity, 1 stop bits
        • Terminal type ANSI or VT100

        The command line can edit with ‘Backspace/Home/End’ or ‘Left/Right’ cursor keys. The command line must be closed by ‘Enter’. The program trims all special character except the underscore“_” The excepted character list: “0-9”, “a-z”, “A-Z”, “space” and “_”.

         

        I attached the detailed documentacion and the Bin file.

        Just donwload the program into the Radio board flash.

        It is an first version if you found a bug please report to me!