Brain-dead Bluetooth on the P1
Let me start by saying two things:
- My customer wants me to incorporate Bluetooth into a Propeller device I make for him, so his customers can see sensor data on their cellphones.
- I don't know anything about Bluetooth.
How even to get started? Well, I lucked out. I ordered one of these from DigiKey, hoping for the best:
I liked it because, theoretically, I could just plug it into a Propeller Activity Board and use it with a Spin program to talk to my phone.
But I knew that was too easy to be true.
I was wrong.
By just powering it up, my phone was able to pair with it. Okay, how about sending and receiving data?
I installed this app on my Android phone:
It connected to the device plugged into the Activity Board. So I connected TX and RX to see if I got an echo. I did.
Next I wrote a little program in Spin:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ ser : "Parallax Serial Terminal" PUB start | x ser.startrxtx(1, 0, 0, 115200) ser.str(string("Enter numbers to square:", 13, 10)) repeat x := ser.decin ser.dec(x) ser.str(string(" squared = ")) ser.dec(x * x) ser.str(string(13, 10))
Here's a photo of the transaction:
What could be easier?
Well, okay. I need an app for the phone to do nice graphs, etc. I'm sure they're out there. I just need to find one and deal with the communication protocol.
I used Android App Inventor 2 for a couple simple apps where I used serial over standard Bluetooth -- one was a hacked DEF CON badge, the other was a group of WS2811 Christmas lamps used to create a miniature version of the "Stranger Things" wall. I wrote a simple parser for the P1 that had a few commands. Anything that was not understood as a command was spelled out on the lights. It was a big hit at a Halloween show. I've switch to iPhone, so I have to find tools for developing simple apps.
Thanks for the tip, Jon! I've started playing with ai2, and I'm impressed!
'Looks like ai2 works for iPhones, too:
Thanks for pointing that out, Phil. I has been a while since I worked with AI2. When I was doing those projects the only target was Android.
I often use "Bluetooth Electronics" app
It is easy to use for making a quick remote control or debug terminal with graphs and indicators etc.
Maybe not suitable for customers, as there is some setup to make it work.. setup should be possible from the propeller by sending text file over UART, but I never tried that possibility
Do you have a link for that?
All my products have an Android front end.
For quick and easy projects I recommend
BASIC! (include the exclamation), aka: RFO BASIC. It's an interpreter.
My first ever P1 project involved BT and this is what I used.
For other stuff I use B4X from anywhere software. B4A for Android, B4i for iPhone and B4R for Arduino, ESP stuff, etc. These are compilers but using the civilised BASIC syntax.
A question about Bluetooth, if I may. Is it possible for one server device (e.g. a Propeller) to be paired with multiple clients (e.g. cellphones) at once? If it is, the server would be reduced to just sending a continuous stream of data, and the client would have the onus of graphing it, scaling the graph, etc. -- rather cumbersome for ai2 with its Blockly-like programming environment.
OTOH, if only one client can be paired at a time, the Propeller program can take more control over how the data are displayed on the client, leaving the ai2 program responsible just for responding to commands regarding formatting, etc. For example, the Prop could query a phone about its screen size, then tailor its command and data stream accordingly with known coordinate limits to work with.
You probably need to look at PAN (personal area network).
Probably need to make the Prop BT the "master". I prefer this mode because it's the only way I found to have my mobile device log-on automatically (no menu selection).
Note: Some BT modules are slave only.
On the trot right now or I'd provide links, etc.
I have harped-on about the fact that; most of us are carrying the most powerful HMI ever...Why bother with a dedicated screen.
Most breakdowns I get involved with are dead due to the HMI which is subject to constant abuse/misuse.
Tomorrow, I visit a customer to fit his new user interface which cost several thousands but nothing compared to the lost production. Crazy!!!
One of my Android devices that replaced a Siemens system:
@"Phil Pilgrim (PhiPi)"
Just checked my new modules and I have the HC-5 which is able to be master OR slave.
Never used this low-cost device before so I'll start working with it tomorrow (away from the shop today) and will see what I can get it to do.
Attached is a derivative of BASIC!
It has been enhanced to support BLE.
I renamed it to a zip file to be able to upload it so it needs restoring to apk and then it will load onto an Android device.
There is a sample or two, showing how BLE devices are addressed/accessed.
It's possible to edit and run, right on the device but there are other utilities that allow editing on a PC and transferring wirelessly to the device.
I have no clue where or how to make a link to android play store.
But I have attached a screenshot from info menu in the app
I searched for it in the Play Store, found it, and installed it.
Late to the thread, Keyboard shut, eyes open. So much to learn... So much fun...
There is Bluetooth PAN (personal area network) which I have yet to try.
There is Bluetooth LE (BT 5?) where devices are addressed. I already uploaded "GrauBASIC" which does this.
Another possibility with Android is "intents" where you can create multiple separate apps that the main app can exchange data with. These apps run in the background and can have their own BT links.
Android is pretty darned cool.
Simblee was an awesome concept but it died.
Thx for the reminder of PAN. Would love to have my earbuds accessible from both phones and computers at same time, but not seen that yet. Maybe misread a doc. @phipi, my apologies for missing some of mickster's notes, so back to the books.
I am not going to read this entire thread, but I will tell you what is working well for me. A while back, jonnyMac suggested the B4X platform to me, and that is what I have been using. More specifically, I am currently using the B4A (Android) platform, but will soon be using the B4I (Apple) platform also.
If you are interested, I can throw together a skeleton project for you, with all the nuts and bolts, and all you would have to do is code a web page or two.
I like the idea of using HTML, etc., since the UI already exists on phones. Investigating further ...
One more hint, just in case you are unaware, but I am sure you are, however I will say it anyway.... Don't forget this meta tag in your html
<meta name="viewport" content="width=device-width, initial-scale=1.0">
P.S..... CSS is great stuff for putting together a nice looking interface
Sorry to post so much, but I realized I already have an example for you on the forum However this example uses html internally with the app, but I prefer to now add the html files externally. This example should allow you to connect and communicate withyour RN42 device
Alright Phil, you are being awfully quiet, and of course, I am very curious Are you making any progress with a web interface app or have you decided to build an app by customary methods?
My day job is interfering. -P.
I appreciate your efforts Bruce. The elderly tend to be rude and terse. Don't take it personally
I hope you are doing well.
After making the B4A suggestion to Phil, I realized that I forgot to mention you in helping me go in that direction. Thanks to your urging and JonnyMac's urging, I now have a user interface that looks and works great, for that ultra-secret project that I told you about And yes, I am still working on that I had some major setbacks due to illness, but slow and steady wins the race Hopefully, I will soon have a very polished product ready for that obscure marketplace
And LOL, I did not take any offense to Phil's reply, he was just telling it like it is. However, I truly hope he goes my suggested route, because I think he will be very happy he did, and after the first one, I think we will see RN42 interface apps coming from Phil left and right He won't be able to type them out fast enough
Hopefully your email is still the same, because I am going to send you a link to the new web based interface, which looks equivalent to the new app. At this point, it is best viewed in a Chrome based browser. If you view this web page on an Android phone, it should look pretty decent.
Sorry for the partial hi-jack Phil
Doing great, thanks and crazy busy. Yeah that whole B4X suite is very cool. At some point, I want to try B4R on the ESP32, not interested in the Arduino thing.
I have been shipping my B4A-created product for 10 years now and customers really like the fact that it's a ubiquitous HMI solution.
Just a few weeks ago, I was called-out to an emergency machine breakdown.....Incredible They first sent me a video, showing how the machine would get part-way through a sequence and then hang-up. They assured me that they had checked the obvious, such as proximity sensors, etc.
By the time I arrived, things had become much worse because they had continued to mess with the machine and just like someone might stab at a failing pushbutton, they stabbed harder and harder on the touchscreen and shattered it
This was some obscure control unit and it took 10 days (and big bucks) to find a replacement.....almost crippled the company. Had this been an Android device, they would have been up and running in minutes
Just yesterday, I received a call, out-of-the-blue, from a big-name manufacturer of coach seating. They want to incorporate heating in the seats but without having to add a control panel to the dash and so would I consider designing a system that could be controlled by a mobile device.
Endless opportunity out there.
P.S. The BASIC! interpreter that I posted in this thread, is really useful for quick and dirty Android experiments. I even used it for a finished product.
Well pesky paying customers prevented me from playing with BT but I finally got around to testing the HC-05 over the past few days. Such child's play
All I did with the AT commands is change the BAUD and that was it.
Android programming? I have to say that for me BASIC! is my new standard...after 10 years of B4A.
Then simply read/write bytes.
Can it get any easier than this?
After reading @Mickster comment, I realized that I had to go play with Bluetooth, because if anyone can screw something up with a Propeller, it is yours truly. 🤣 So I spent today playing with an HC-06 module. And I learned a few things that I’ll put here for those who come along later.
It really is drop-dead simple to implement a bluetooth connection. Its just like the old Hayes SmartModem days with AT commands. From a Propeller standpoint (a P2 EVAL in my case) its basically just open a serial port and bang away with AT commands and the module handles the rest. But then I learned that the HC-06 module is a stripped, brainless, slave-only bass-turd that cant walk and chew gum at the same time, compared to an HC-05.
I also found that all of the HC-04/05/06 BT2.x modules will not talk to an iPhone. For this to happen, you need a BT4.2/5.0 module like the HC-18 or HC-19. Iphone does not support a 2.x connection. Period. Android has no problem however. The good news for us Apple people is an iPhone-compatible HC-18 or HC-19 module costs about $10, so its still very cheap entertainment, and these modules are fast-fast with really improved range. Or so the illiminati tell me.
Will update this when my HC-18s arrive on Tuesday.