Shop OBEX P1 Docs P2 Docs Learn Events
SPIN: RN-42 Bluetooth Module And Android App... Working Example — Parallax Forums

SPIN: RN-42 Bluetooth Module And Android App... Working Example

idbruceidbruce Posts: 6,197
edited 2020-08-16 14:45 in Propeller 1
Hello Everyone

I realize that there are members who prefer Spin over C/C++, so I took one of my C/C++ projects/discussions and am providing it for Spin also, because I think it is useful :) And Parallax, please forgive me for similar posts, but I think you can relate to the situation. For a more in depth discussion, but in a SimpleIDE context, please refer to this thread: forums.parallax.com/discussion/171419/success-simpleide-the-rn-42-bluetooth-module-and-b4a-android-app#latest

Anyhow, I purchased an RN-42 Bluetooth module, which I intended for machine control, but I definitely needed a custom app for Android. There are several choices when it comes to creating an Android app, but after a nudge from JonnyMac and Mickster, I looked into B4A, which is a programming environment for Android.

To sum it, I created an app which I believe will be useful to many people here that work and play with robots, machines, and home automation. To be able to use this example app, you will have to dabble in B4A just a little bit, to load and build the application, as well as altering some HTML and JavaScript code.

To make it easier on me, I will simply quote a post I made at B4X.com.

The title of the post was:
42Nurses - WebView HTML Form For Machine/Robot Control & Home Automation
Hello Everyone

I believe this is only my second post and I have come here to contribute :)

Before I contribute, please allow me to say thank you to Erel for his [B4XPages] Bluetooth Chat Example, because without it, my contribution would not be possible. His example can be found here: https://www.b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/

Now for the details... Ahhhh.... I will just summarize it :) Basically I took his chat example and added a WebView, along with WebViewExtras. In the WebView, I have an HTML form, supported and validated with JavaScript. Within the JavaScript, I utilize the member CallSub from the WebViewExtras library, to pass data back to the B4A app.

By altering the HTML, the HTML form, and the JavaScript, as well as perhaps adding additional CallSub calls, many things can be achieved and controlled with this example, very easily. It is intended for Bluetooth communication. I am using something very similar to this example application, to send commands to an RN-42 Bluetooth module, which passes those commands onto a Parallax Propeller uC, for machine control, and it does the job perfectly (so far :) ).

Anyhow, check it out, because it may help you find a solution. 42Nurses = RN-42 :)

Here is a link to the B4X.com forum thread, where I posted the application: https://b4x.com/android/forum/threads/42nurses-webview-html-form-for-machine-robot-control-home-automation.121258/

To run and edit the Android example, you must be running Version: 10.0 (the latest updated version) of B4A.

Please note the constants BT_RST, BT_RTS, and BT_CTS, defined in "Command.spin" are really not needed to communicate with the "42Nurses" Android app.

42Nurses was written and compiled with B4A Ver. 10.0 and Command.spin was created and written with the Propeller Tool Ver. 1.3.2

EDIT: And for those of you who are not to keen on making the necessary alterations, I will make the alterations for you, in exchange for payment. :)

Comments

  • While I have a moment, I just wanted to notify interested parties that an updated version has been uploaded to the B4X.com forum, but it is currently waiting for moderator approval. It should be visible in a couple to several hours.

    The updated version makes it much easier to edit the HTML source code :)
  • No comments, no nothing, you guys are a tuff crowd. This is really GOOD stuff. Just alter or create an HTML form, and you could have a robot with 1000 sensors that you could read, when you tell your robot to head due North for five miles and then turn left :) All from the comfort of your Android phone or tablet

    WOW I certainly expected more feedback
  • idbruce wrote: »
    No comments, no nothing, you guys are a tuff crowd. This is really GOOD stuff. Just alter or create an HTML form, and you could have a robot with 1000 sensors that you could read, when you tell your robot to head due North for five miles and then turn left :) All from the comfort of your Android phone or tablet

    WOW I certainly expected more feedback

    I guess everybody is focused on other things.
    Your efforts/experiences are very valuable, thank you for posting them. Keep up the good work.
    While I don't have a specific need/use for these developments at the moment, I'm sure they will come in handy in the future...
  • Yea, a feedback :)

    Thanks Francis :)
  • Cluso99Cluso99 Posts: 18,066
    I saw this late last night so I started reading about B4X which went well into the wee small hours.
    Just had time to get back onto the forum.

    Thanks for posting this. I am interested in how an iphone or ipad can be used with a graphical display connected to the P2 (as Peter has said on the P2 forum). Because of iphone/iPad software costs, I think I should try this on an Android device first ;)

    Not sure when/if I will get time to try this but I've saved the link for when that time comes.

    Thanks for posting, and keep us informed :)
  • idbruceidbruce Posts: 6,197
    edited 2020-08-17 04:13
    Hey Ray, I hope all is well

    Yea, with $99 per year (cost of developer account for B4I), you could have a new Android phone each year, instead of paying that fee :) I would definitely go the Android route.

    The hardest part for anyone interested, is downloading the software and installing it. After that, running my app is a walk in the park, and altering HTML and JavaScript is not all that difficult.

    It has been quite a while since I dived into any serious web programming, but I am fairly certain that technology has come a long way since I was serious. So I imagine a person could create some very nice interfaces with HTML, JavaScript, and CSS. And my example app can help them all to talk with a Propeller :) and even a Basic Stamp :wink:
  • Cluso99Cluso99 Posts: 18,066
    Yes, the entry cost for using iOS is high for a one-off. Pity as I have old iPhones as well as iPads.
  • Maybe someone here will give you an old Android phone or tablet :)
  • UPDATE:

    It is still awaiting moderator approval at B4X.com.....
    Once again, thank you Erel, but this time I thank you for your "Voice Recognition Example", which can be found here: https://www.b4x.com/android/forum/threads/voice-recognition-example.7317/

    I have now added voice recognition to the 42Nurses example application, which entailed adding another CallSub from the WebViewExtras library, in the JavaScript and adding another HTML source file, as well as some other miscellaneous stuff. Of course the voice recognition part of this example is contingent upon your device being able to support it.

    In operation, your voice is transformed into a text string, and then this text string is transmitted via Bluetooth :)

    I hope you like the possibilities :)
  • I quit making my own tablet enclosures because there are plenty of rugged Android devices out there now.

    https://teguar.com/10-inch-android-rugged-tablet-trt-a5380.html
Sign In or Register to comment.