Shop OBEX P1 Docs P2 Docs Learn Events
BTLE Control — Parallax Forums

BTLE Control

JonnyMacJonnyMac Posts: 9,102
edited 2017-10-19 15:19 in Learn with BlocklyProp
I'm experimenting with the Adafruit BTLE UART Friend (in Spin), but thought -- for fun -- I'd try a simple project in Blockly that corresponds to one of the demo control panels in the Adafruit Bluefruit LE phone app. This demo works with the color picker panel to set the colors on a string of WS2812 LEDs.

blockly_blte_rgb_control.jpg

Being a "standard" coder (Spin is my preferred tool), I still stumble around the Blockly environment a bit, but -- happily -- this worked the first time I tested it. The color picker sends a 6-byte packet. The first two bytes are "!C" (for color?) followed by red, green, blue, and a crc.

Protocol details for the color picker are here:
-- https://learn.adafruit.com/bluefruit-le-connect-for-ios/controller#color-picker

I've made the project public; the blocks are here:
-- http://blockly.parallax.com/blockly/projectlink?id=14218&key=3b63afce-d277-4d40-9f40-b768117e1932

Note: The mode switch on the module needs to be in UART and the CTS pin connected to ground for this to work.
766 x 631 - 430K

Comments

  • Jon, Nice!

    This is an easy way to add BLE to a project. I've done something similar with the RedBear Labs devices and Arduino as well as TI devices and it is cool to see you doing this with the Adafruit device, Blocky and a Parallax device.

    Thanks for sharing.
  • This is a super neat, productive project Jon! Nice to see how Blockly worked well the first time through. In this case it seems that it actually saved you a lot of time.

    I saw it on the Blockly for Microcontrollers Facebook group, too. I think I'm going to order the hardware and give it a try myself. As you know, I've also got a big WS2812 LED project ahead of me and this will make it a lot more fun.

    Ken Gracey
  • Truth be told, I was able to use the BTLE module with Spin -- I thought I'd try it in Blockly because I knew you'd like it and I remembered your other project.

    Make sure you order the serial (UART) version, not the SPI version. JB and I have a client project that requires BTLE hence I bought the module.

    -- https://www.amazon.com/Adafruit-Bluefruit-UART-Friend-Bluetooth/dp/B010M8UZPY

    I have also been experimenting with the HM-10 which you can for about $10. But there is not fancy phone app for it; on that score you're on you're own (I'm working on learning PhoneGap for x-platform control apps).

    -- https://www.amazon.com/DSD-TECH-HM-10-Bluetooth-iBeacon/dp/B06WGZB2N4

    I've used both devices in serial pass-through mode with my parsing engine.
  • JonnyMac,
    I had a look at the Adafruit BTLE UART Friend page and it certainly seems to be a useful and powerful device.
    I can visualize many applications, especially for short range data transfer.
    I wonder if you would mind sharing your SPIN code with us.
    Many thanks for the heads-up on this device.
  • JonnyMacJonnyMac Posts: 9,102
    edited 2017-10-20 03:00
    macrobeak wrote: »
    JonnyMac,
    I had a look at the Adafruit BTLE UART Friend page and it certainly seems to be a useful and powerful device.
    I can visualize many applications, especially for short range data transfer.
    I wonder if you would mind sharing your SPIN code with us.
    Many thanks for the heads-up on this device.

    If you start a thread in the Propeller 1 forum I will do that -- I don't want to discuss Spin code in the Blockly forum. Deal?

  • BeanBean Posts: 8,129
    Jon,
    What do you use to program on the phone side ?
    Can you share any of that code ?

    Thanks,
    Bean
  • JonnyMacJonnyMac Posts: 9,102
    edited 2017-10-20 19:12
    For the moment (as I'm still in R&D mode), I am using the Bluefruit LE app as it has several interfaces to choose from in the controller section of the app.

    -- https://learn.adafruit.com/bluefruit-le-connect-for-ios/controller

    I have also used the UART section to send simple commands to a project. With just a few commands it's easy to convert the incoming string to uppercase and then use strcomp() to test -- that's what I'm doing in Spin (I don't know if Blockly has a "no data available" value like FDS does).

    In the past I have used MIT App Inventor 2 to create simple Android apps that used standard BT serial. The reason for the move to BTLE is that my customer wants iPhone support and iOS phones only support BTLE. Luckily, most BLTE devices seen seem to have a custom service that supports serial pass-through, even if it's in small chunks (the HM-20, for example, can send up to 20 bytes; I don't yet know the limit on the Adafruit module) .

    I'm working through some online classes in PhoneGap hoping that I can do what we need for the customer without us having to hire an iOS developer. John B and I were actually contacted by a friend of our client who asked us to produce a working device THE NEXT DAY (we had less than 24 hours to solve a problem for them that their internal engineering department had failed to complete in a month). Luckily, we had good controller (our HC-8+), some Bluetooth modules from an earlier experiment, and a Bluetooth framework for AI2 that I had used in the past to control my DEF CON 22 badge. We didn't get any sleep, but pulled it off -- now we're doing a proper development cycle.

    Today is a bit busy. When I get some free time, I'll post some Spin code from my experiments in the Propeller 1 forum.
  • Jon, Nice!

    I believe someone asked about the SPIN code in another thread, but I have been working with a C version which I will post if folks are interested.

    However, if you are looking for a non APP way to collect data from the BLE/Bluetooth device, BlueZ can be run from command line and allows you to gather data from a BT device as well as send commands to it. I do this from a Raspberry Pi or a BeagleBone Black

    Ex:
    BLE Scan:
    $ sudo ~/bluez-5.43/tools/hcitool lescan
    LE Scan ...
    B4:99:4C:7A:F8:31
    B4:99:4C:7A:F8:31 (unknown)

    This is from a RedBear Labs BLE Mini

    BT Scan
    $ sudo ~/bluez-5.43/tools/hcitool scan
    Scanning ...
            C8:29:2A:05:0E:C0       LGE DTV BCM20702A1
            98:D3:32:20:C9:FC       HC-05
    

    The LGE Device if from my TV and the HC-05 is a Velleman VMA302 HC-05 device I got from Fry's

    You can connect to a BLE device and get the characteristics from it and see which is accesible or not by trial and error.
    $ sudo ~/bluez-5.43/attrib/gatttool -i hci0 -b B4:99:4C:7A:F8:31 -I
    [B4:99:4C:7A:F8:31][LE]> connect
    Attempting to connect to B4:99:4C:7A:F8:31
    Connection successful
    [B4:99:4C:7A:F8:31][LE]> primary
    attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb
    attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb
    attr handle: 0x0010, end grp handle: 0xffff uuid: 713d0000-503e-4c75-ba94-3148f18d941e
    


    you can read and write to the device as such:
    [B4:99:4C:7A:F8:31][LE]> char-read-hnd 0x0001
    Characteristic value/descriptor: 00 18 
    [B4:99:4C:7A:F8:31][LE]> char-write-req 0x0016 01
    Characteristic value was written successfully
    


    Or from command line as:
    sudo ~/bluez-5.43/attrib/gatttool -b B4:99:4C:7A:F8:31 --char-write-req -a 0x0016 -n 01
    

    I don't want to highjack your thread so I'll post the rest elsewhere, but thought it might be of interest to you or others work on the Blocky example.

Sign In or Register to comment.