iOSã§åãtechBASICãBleutooth Low Energyã«å¯¾å¿ãã¦ããã¨ãããã¨ãªã®ã§ãæ©éå®é¨ãã¦ã¿ã¾ããã
ã
å®é¨ã«ä½¿ã£ãç°å¢ã¯ãiPad3 + techBASIC + SBDBT + Bleutooth Low Energyãã¡ã¼ã ã§ãã
以ä¸ããã®æé ãç´¹ä»ãã¾ãã
âå¿
è¦ãªãã®
ã»Bleutooth Low Energyã«å¯¾å¿ãããiPad/iPhone
ãç§ã¯ãiPad3ã使ãã¾ããã
ã»techBASICãiPad/iPhoneã§åãBASIC
ã»SBDBTãPIC24FJ64GB004æè¼ã®ãã¤ã³ã³åºæ¿
ã
ã»USBæ¥ç¶ã®Bluetooth4.0ã«å¯¾å¿ããã¢ããã¿
ãç§ã¯ã”iBUFFALO BSBT4D09BK”ã使ãã¾ããã
ã»SBDBTç¨Bleutooth Low Energyãã¡ã¼ã
ãæ©è½ã®è©³ç´°ã¯ããã¡ã¼ã ã®ã¦ã¼ã¶ã¼ãºããã¥ã¢ã«ãåç
§ãã¦ãã ããã
ã»SBDBTã®éçºç°å¢
ãSBDBTã®ããã¥ã¢ã«ãåç
§ãã¦ãã ããã
âSBDBTã®æºå
SBDBTç¨Bleutooth Low Energyãã¡ã¼ã ã®ã½ã¼ã¹ããã¦ã³ãã¼ããã³ã³ãã¤ã«ããå®è¡ãã¡ã¤ã«ãSBDBTã«æ¸ãè¾¼ã¿ã¾ãã
詳細ã¯ãBleutooth Low Energyãã¡ã¼ã ã®ã¦ã¼ã¶ã¼ãºããã¥ã¢ã«ãåç
§ãã¦ãã ããã
æ¸ãè¾¼ãã ãã¡ã¼ã ãæ£å¸¸ã«åãããã¦ã¼ã¶ã¼ããã¥ã¢ã«ãåèã«LightBlueã§ç¢ºèªãã¦ããã¾ãã
ã
âiPadå´ã®æºå
ä¸ã®ãã¹ãç¨ããã°ã©ã ã®ã½ã¼ã¹ãiPadã®techBASICã«éãã¾ãã
techBASICã®ããã¥ã¢ã«ã«æ¸ãã¦ããããæ¹ã¯2ã¤ããã¾ãã
ã»iTunesã使ã
ãä¸ã®ã½ã¼ã¹ããã°ã©ã ãé©å½ãªãã¡ã¤ã«åãä»ãã¦ãã¡ã¤ã«ã«ä¿åããiTunesã§techBASICã«è»¢éãã¾ãã
ããã¡ã¤ã«ã®æ¡å¼µå㯔bas”ã§ãã
ï¼ç§ã®ç°å¢ã§ã¯ãªãããã¾ãè¡ãã¾ããã§ãããï¼
ã»ã¡ã¼ã«ã使ã
ãPCãªã©ããã¡ã¼ã«ã®æ¬æã«ããã°ã©ã ã½ã¼ã¹ãå¼µãä»ããèªåãã¦ã«éä¿¡ãã¾ãã
ãiPadã§ãã®ã¡ã¼ã«ãéããtechBASICã§ä½æãã空ã®ãã¡ã¤ã«ã«ã³ãããã¾ãã
ããã ããã¡ã¼ã«ã½ããã«ãã£ã¦ã¯é·ãè¡ã«åæã«æ¹è¡ãå
¥ã£ã¦ãã¾ãã®ã§å¾ã§æç´ããå¿
è¦ã§ãã
!-------ãããã---------------------------------------------------------------------------
! Define the various UUIDs
serviceUUID$ = "FFF0"
stringUUID$ = "FFF1"
ledUUID$ = "FFF2"
counterUUID$ = "00001234-0000-1000-8000-00805F9B34FB"
! This is the device we've connected to.
DIM sbdbtPeripheral AS BLEPeripheral
!----------------------------------------------------------------------------
BLE.startBLE
DIM uuid(0) AS STRING !Pass an empty array to get all available devices.
BLE.startScan(uuid)
!----------------------------------------------------------------------------
! Called when a peripheral is found. If it is a target device, we
! initiate a connection to is and stop scanning for peripherals.
!
! Parameters:
! time - The time when the peripheral was discovered.
! peripheral - The peripheral that was discovered.
! services - List of services offered by the device.
! advertisements - Advertisements (information provided by the
! device without the need to read a service/characteristic)
! rssi - Received Signal Strength Indicator
!----------------------------------------------------------------------------
SUB BLEDiscoveredPeripheral(time AS DOUBLE, peripheral AS BLEPeripheral,services() AS STRING, advertisements(,) AS STRING, rssi AS SINGLE)
PRINT "Found "; peripheral.bleName; "; UUID = "; peripheral.uuid
IF peripheral.bleName = "SBDBT BLE TEST" THEN
sbdbtPeripheral = peripheral
BLE.connect(sbdbtPeripheral)
END IF
PRINT "Stopping scan"
BLE.stopScan
END SUB
!----------------------------------------------------------------------------
! Called to report information about the connection status of the
! peripheral or to report that services have been discovered.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! kind - The kind of call. One of
! 1 - Connection completed
! 2 - Connection failed
! 3 - Connection lost
! 4 - Services discovered
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
!----------------------------------------------------------------------------
SUB BLEPeripheralInfo (time AS DOUBLE, peripheral AS BLEPeripheral, kind AS INTEGER, msg AS STRING, err AS LONG)
IF kind = 1 THEN
PRINT "Connected to "; peripheral.bleName
peripheral.discoverServices(uuid)
ELSE IF kind = 2 OR kind = 3 THEN
PRINT "The connection was lost."
ELSE IF kind = 4 THEN
! Services were found. If it is the main service, begin discovery
! of its characteristics.
DIM availableServices(1) AS BLEService
availableServices = peripheral.services
FOR a = 1 TO UBOUND(availableServices, 1)
PRINT "Found service "; availableServices(a).UUID
IF availableServices(a).UUID = serviceUUID$ THEN
peripheral.discoverCharacteristics(uuid, availableServices(a))
END IF
NEXT
END IF
END SUB
!----------------------------------------------------------------------------
! Called to report information about a characteristic or included
! services for a service. If it is one we are interested in, start
! handling it.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! service - The service whose characteristic or included
! service was found.
! kind - The kind of call. One of
! 1 - Characteristics found
! 2 - Included services found
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
!----------------------------------------------------------------------------
SUB BLEServiceInfo (time AS DOUBLE, peripheral AS BLEPeripheral, service AS BLEService, kind AS INTEGER, msg AS STRING, err AS LONG)
IF kind = 1 THEN
DIM characteristics(1) AS BLECharacteristic
characteristics = service.characteristics
FOR i = 1 TO UBOUND(characteristics, 1)
PRINT "Found characteristic "; i; ": "; characteristics(i).uuid
IF characteristics(i).uuid = counterUUID$ THEN
peripheral.readCharacteristic(characteristics(i))
!peripheral.setNotify(characteristics(i), 1)
END IF
IF characteristics(i).uuid = stringUUID$ THEN
DIM value(3) AS INTEGER
value = [ASC("A"),ASC("B"),ASC("C")]
peripheral.writeCharacteristic(characteristics(i), value, 1)
END IF
IF characteristics(i).uuid = ledUUID$ THEN
DIM value(1) AS INTEGER
value = [$01]
peripheral.writeCharacteristic(characteristics(i), value, 1)
END IF
NEXT
END IF
END SUB
!----------------------------------------------------------------------------
! Called to return information from a characteristic.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! characteristic - The characteristic whose information
! changed.
! kind - The kind of call. One of
! 1 - Called after a discoverDescriptors call.
! 2 - Called after a readCharacteristics call.
! 3 - Called to report status after a writeCharacteristics
! call.
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
!
!----------------------------------------------------------------------------
SUB BLECharacteristicInfo (time AS DOUBLE, peripheral AS BLEPeripheral, characteristic AS BLECharacteristic, kind AS INTEGER, msg AS STRING, err AS LONG)
IF kind = 2 THEN
! Read response recieved.
DIM value(1) AS INTEGER
PRINT "Value for characteristic "; characteristic.uuid; " = ";
value = characteristic.value
SELECT CASE characteristic.uuid
CASE counterUUID$
FOR i = 1 TO UBOUND(value, 1)
PRINT RIGHT(HEX(value(i)), 2);
NEXT
PRINT
CASE stringUUID$
FOR i = 1 TO UBOUND(value, 1)
PRINT CHR(value(i));
NEXT
PRINT
CASE ELSE
!PRINT "Unexpected UUID "; characteristic.uuid
END SELECT
ELSE IF kind = 3 THEN
! Write response recieved.
SELECT CASE characteristic.uuid
CASE stringUUID$
peripheral.readCharacteristic(characteristic)
CASE ELSE
!PRINT "Unexpected UUID "; characteristic.uuid
END SELECT
END IF
END SUB
!-------ããã¾ã§---------------------------------------------------------------------------
âå®é¨æé
ï¼ï¼SBDBTã«USB Bluetoothã¢ããã¿ãæ¿ããé»æºãå
¥ãã¾ãã
ãããã°ããããã¨ã赤LEDãæ¶ç¯ãããªã¬ã³ã¸LEDã®ã¿ç¹ç¯ã«ãªãã¾ãã
ï¼ï¼iPadã®BluetoothãONã«ããtechBASICã«è»¢éããããã°ã©ã ãå®è¡ãã¾ãã
ãããã¾ãè¡ãã°ãã®ããã«è¡¨ç¤ºããã赤LEDãç¹ç¯ããã¯ãã§ãã
ã
âiPad3 + techBASIC + mbed + Bleutooth Low Energyã®å®é¨
Ken TodotaniããããSBDBTç¨Bleutooth Low Energyãã¡ã¼ã ãmbedã«ç§»æ¤ãã¦ãã ãã£ãã®ã§è©¦ãã¦ã¿ãã
ã»ãiPhoneããmbedãBluetooth LE (BTLE)ã§å¶å¾¡ããã
techBASICããã°ã©ã ã®ãµãã«ã¼ãã³”BLEDiscoveredPeripheral”å
ã®ããã®è¡ãä¿®æ£ããã
ãä¿®æ£åï¼IF peripheral.bleName = "SBDBT BLE TEST" THEN
ãä¿®æ£å¾ï¼IF peripheral.bleName = "mbed BLE TEST" THEN
ãã¾ãè¡ãã°ãã®ããã«è¡¨ç¤ºãããã¯ãã
ã
âè£è¶³
techBASIC App Builderã使ãã°techBASICã§ä½ã£ãããã°ã©ã ããç¬ç«ããã¢ããªã±ã¼ã·ã§ã³ã«ã§ããããã§ãã
â以ä¸â
åèãªã³ã¯
ã»Creating and Using Controls
ã»BTstackLE