BTLE Control
JonnyMac
Posts: 9,102
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.
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.
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.
Comments
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.
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
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.
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?
What do you use to program on the phone side ?
Can you share any of that code ?
Thanks,
Bean
-- 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.
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
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.
you can read and write to the device as such:
Or from command line as:
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.