Shop OBEX P1 Docs P2 Docs Learn Events
SUCCESS!!! SimpleIDE, the RN-42 Bluetooth Module, and B4A Android App — Parallax Forums

SUCCESS!!! SimpleIDE, the RN-42 Bluetooth Module, and B4A Android App

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

I am currently waiting on a delivery of the ChronoDot V2.1 to complete the timestamp aspect of my current project. In the meantime, I would like to explore the possibilities of the RN-42 Bluetooth Module that I recently purchased, and of course, I suppose like most people, I want to be able to control my project with an Android device :)

With this in mind, I started exploring my options, and stumbled across the MIT App Inventor (appinventor.org/appInventor2). I am truly amazed that I have not seen any discussion about this in the forum. MIT App Inventor provides you with the capability of creating Android apps and allows you to test them as you build your app. All I can say is "WOW". I don't know how this will all work out, but I certainly intend to explore the possibilties, over the next several days or weeks. I am hoping that I can use this in my current project, in addition to another huge project which has been placed on hold :)

Anyhow, I will most likely start my adventure sometime later today. If you think I am barking up the wrong tree, then please let me know the drawbacks.

Bruce
«1

Comments

  • My first report is.... It all looks very interesting :)
  • Thanks Jim I missed that. That thread may come in handy during my exploration :)

    I like what I have seen so far from App Inventor.
  • Well.... Exploration and this thread will have to be put on hold for a bit.

    Santa came early, delivering new toys today :)
  • Hey Brue,

    I posted the apk for the BASIC! interpreter in a recent thread.

    This is their bluetooth sample code. I was talking to the Prop in minutes with this.
    I ended up stripping a lot out and it boiled down to nothing.
    
    !!
    This program demonstrates using
    Bluetooth as both an application
    that listens for a connection
    or makes a connection to a listener.
    
    Before running this program use
    the Android "Settings" application
    to enable Bluetooth and to pair
    with the device(s) that you will
    talk to.
    
    This program will send and receive
    data bytes to and from a connected
    device.
    
    You can use this program to 
    (among many other things) set
    up a chat between two Android
    devices.
    
    Note: The UUID used by default is
    the standard serial port UUID. This
    can be changed. Read the manual.
    
    !!
    
    ! Begin by opening Bluetooth
    ! If Bluetooth is not enabled
    ! the program will stop here.
    
    BT.OPEN
    
    ! When BT is opened, the program
    ! will start listening for another
    ! device to connect. At this time
    ! the user can continue to wait
    ! for a connection are can attempt
    ! to connect to another device
    ! that is waiting for a connection
    
    ! Ask user what to do
    
    ARRAY.LOAD type$[], "Connect to listener", "Continue to listen for connection", "Quit"
    title$ = "Select operation mode"
    
    ! Create the menu that will be loaded
    ! when the screen is touched.
    
    ARRAY.LOAD menu$[], "Send", "Disconnect","Quit"
    
    new_connection:
    xdomenu =0
    
    SELECT type, type$[], title$
    
    ! If the user pressed the back
    ! key or selected quit then quit
    ! otherwise try to connect to
    ! a listener
    
    IF (type = 0) | (type =3)
     PRINT "Thanks for playing"
     BT.CLOSE
     END
    ELSEIF type = 1
     BT.CONNECT
    ENDIF
    
    ! Read status until
    ! a connection is made
    
    ln = 0
    DO
     BT.STATUS s
     IF s = 1
      ln = ln + 1
      PRINT "Listening", ln
     ELSEIF s =2
      PRINT "Connecting"
     ELSEIF s = 3
      PRINT "Connected"
      PRINT "Touch any text line to send, disconnect or quit."
     ENDIF
     PAUSE 1000
    
    UNTIL s = 3
    
    ! When a connection is made
    ! get the name of the connected
    ! device
    
    BT.DEVICE.NAME device$
    
    ! *** Read/Write Loop ****
    
    RW_Loop:
    
    DO
    
     ! If the screen is touched, the interrupt
     ! code will change xdoMemu to 1 (true)
     ! In that case, show the menu
    
     IF xdoMenu
      xdoMenu =0
      SELECT menu,  menu$[], "Do what?"
      IF menu = 1 THEN GOSUB xdoSend
      IF menu = 2 THEN BT.DISCONNECT
      IF menu = 3
       PRINT "Thanks for playing"
       BT.CLOSE
       END
      ENDIF
    
     ENDIF
    
    
     ! Read status to insure
     ! that we remain connected.
     ! If disconnected, program
     ! reverts to listen mode.
     ! In that case, ask user
     ! what to do.
    
     BT.STATUS s
     IF s<> 3
      PRINT "Connection lost"
      GOTO new_connection
     ENDIF
    
     ! Read messages until
     ! the message queue is
     ! empty
    
     DO
      BT.READ.READY rr
      IF rr
       BT.READ.BYTES rmsg$
       PRINT device$;": ";rmsg$
      ENDIF
     UNTIL rr = 0
    
    UNTIL 0
    
    ! Get and send message
    ! to the connected device
    
    xdoSend:
    
    INPUT "Text to send", wmsg$
    BT.WRITE wmsg$
    PRINT "Me: "; wmsg$
    
    RETURN
    
    ! When Console is touched
    ! set xdoMenu to true
    
    onConsoleTouch:
    xdoMenu = 1
    ConsoleTouch.Resume
    
    onError:
    END
    
    
  • Mickster

    I could be wrong :) , but I don't see talking with the Propeller as a major problem. My problem is the user interface, but isn't it always :) .

    I have not totaled it all up, but I would imagine there are at least 1000 possible combinations of user settings, if not more. It will be a very in depth user interface for the App that I will be creating, all of which boils down to sending a short command sequence. At the moment, I am currently using a fairly complex html form, which is processed by a Perl script to create the short command sequence, however this intended for control from a remote location, over the internet. The bluetooth app will of course be intended for local control.

    Just to give you an idea of the complexity of my undertaking, here is a snapshot of the user interface, with certain text being removed for proprietary purposes. This form is used for very specific motor control operations.

    I may have to realign my thinking, just to make a bluetooth app possible, because MIT App Inventor, as far as I can tell so far, does not offer radio buttons, but I may have missed it at first glance.
    218 x 580 - 21K
  • but I don't see talking with the Propeller as a major problem
    It's quite easy if you're just passing strings back and forth. Another up-side of using strings is that you can do your device-to-prop testing through PST.
  • Hey JonnyMac, good to hear from you
    It's quite easy if you're just passing strings back and forth. Another up-side of using strings is that you can do your device-to-prop testing through PST.

    Actually, with the exception of possible ACK and NACK, it will all be one way communication, with a string of (I think) 7 characters. It doesn't sound like a major issue at all, or at least from some of the stuff I have read so far. As I said, the problem will be the user interface.

    Anyway, I hope you are doing well. It is good to see you participating more in the forum again. Even my participation has increased a bit lately. It is good to know that many of the members have just been lingering in the background. Mike Green's participation has picked up as well :)

  • Install BASIC!

    Go to the link at the bottom

    Look for the GW-lib

    Load/run the demo

    By the end of today, you will be making apps with radio buttons, menus, scrolling lists, sliders, pop-ups, etc.

    However, I do understand what it's like when new toys arrive :lol:

    http://mougino.free.fr/rfo-basic/
  • idbruceidbruce Posts: 6,197
    edited 2020-04-03 20:20
    Let me see how it goes.... I may end up taking your advice :)

    Do I have to write BASIC code? Or is it block oriented like App Inventor?

    What I really want is the most powerful and option full app software for free, which does not require a memory hungry executable to be installed on my PC.

    I will check it out :) But I must admit, BASIC was never really my programming language of choice and my skills in that language are certainly deficient :)
  • It's a language with a syntax similar to BASIC but it's just like any other language, you get familiar as you go.

    You can edit/run directly on the device or you can edit on the PC, hit a function key and the code jumps to the device and executes. No compiling.

    You have the option of always running the script or if you want to distribute it, you simply convert it to an apk.

    The apk doesn't compile the code, it bundles your code with the interpreter, along with any assets. It looks like any old Android app to others.

    Just today, I pulled out a WiFi-485/422 device that I've had for ages but never played with. Connected the terminals for a loopback and used the "sockets" demo in BASIC!, voila, instant success.
  • JonnyMacJonnyMac Posts: 8,912
    edited 2020-04-03 21:14
    What I really want is the most powerful and option full app software for free, which does not require a memory hungry executable to be installed on my PC.
    Checkout B4A (Basic For Android) -- it's now free (used to be $50). Warning: There is a big install requirement because it is creating native Android apps.

    https://www.b4x.com/
  • Yeah B4A is cool, I have been using it since 2012.

    Bit more of a learning curve though.

    B4R (BASIC for Arduino) uses the same syntax but now one can produce native code for the ESP devices.

    B4J, same syntax to produce Java apps.

    B4i, same syntax for iOS but it's the only one that isn't free...yet.
  • Yea Jon that looks pretty extensive and powerful. However I cannot find the system requirements for an install. I am still running old computers around here. I would hate to bring them to a grinding halt :)
  • idbruce wrote: »
    Yea Jon that looks pretty extensive and powerful. However I cannot find the system requirements for an install. I am still running old computers around here. I would hate to bring them to a grinding halt :)

    Shouldn't be a problem. I use it on my shop-floor Toughbook which has one of the low (dog) power Pentium chips and B4A works fine.
  • Alright Jon and Mickster

    I will now be attempting to delve into the world of creating apps, by downloading B4A :neutral:

    Hopefully it won't turn my PC into a boat anchor :)
  • Checkout B4A (Basic For Android) -- it's now free (used to be $50). Warning: There is a big install requirement because it is creating native Android apps.

    Yep.... That was a pretty extensive install, but the IDE is now ready.

    As for me, it looks like I have a lot of studying to do. :neutral:
  • It all makes sense after a day or two. They have a great forum and there is lots of sample code around.

    Did you download B4A-Bridge to your device (Google Play)? It will also prompt you to download the Designer which is a great way to build your UI.

  • I am back to working with BASIC! after 8 years of B4A. I don't do any heavy processing so not having to compile is a benefit to me and my end-users. I want to be open source without requiring a PC-based compiler.
  • Mickster
    Did you download B4A-Bridge to your device (Google Play)?

    Yea, I also have B4A-Bridge installed, however it did not prompt me to download Designer. Designer appears to be part of the B4A IDE.
  • I can see that it will take a little while to get the hang of B4X software, but I like it and interests me greatly. In the past, I have done a lot of GUI programming in MFC, so this ought to be a perfect fit for me, moving forward into the future.

    I just wish I had a good grasp on it already :smile:

    Thanks Jon. Thanks Mickster.

    Propeller controlled machinery run from custom made GUI apps :smiley:
  • Hi idbruce

    This (B4X) interests me a lot- please keep us informed of your progress and any hints for the newbe for pitfalls to avoid etc.

    Dave
  • idbruceidbruce Posts: 6,197
    edited 2020-04-09 01:57
    tritonium

    I wasn't really sure how I was going to respond to your post and request, but after a lot of thought, this is what I have to say.

    Whenever I try to learn something new, I almost always have a particular goal that I am trying to achieve or some type of problem that I am trying to solve. In this particular case, I want to learn how to control the Propeller microcontroller with mobile devices, and of course, the B4X platforms will allow me to do this, but there must also be a means and method of communication between the microcontroller and the mobile device. For my purposes, Bluetooth will provide the method of communication. I already have an Android phone, a RN-42 Bluetooth Module, and several Propeller boards to experiment with. Additionally, I have the B4A platform and all accessories installed and ready to go on my PC and mobile device. At this point, I am ready begin my journey into the unknown :smile:

    As mentioned, I like to start with a goal or have a problem to solve. In this particular case, at this specific moment, I have a machine that I would like to be able to control with my phone, through a Graphical User Interface (GUI) hosted on the phone. I already know what I want and need on the GUI, and this will greatly assist me in my endeavor to learn the B4X platform. To begin my journey of learning the B4X platform, I will start by designing my GUI and make sure that it has everything that I want and need for controling my machine. After I have the GUI designed, then I will research and write the code necessary to make the GUI fully functional. This is just my method of learning at my pace, while achieving a goal or solving a problem. Everyone learns differently. By attacking several different projects, in the same manner, I will eventually become a fairly versatile programmer of the B4X platforms.

    That being said, not every mobile app needs a GUI, a Propeller, Bluetooth communication, or a problem to solve :wink: Only you can determine what you want to learn, how you want to learn it, and how well you want to know the subject. You may become the person telling me the pitfalls during your journey of learning :smile:
  • It's worth mentioning that B4A has libraries for USB-to-serial and also for the "Yoyo"

    Not everyone is comfortable with wireless communications.



  • Mickster
    It's worth mentioning that B4A has libraries for USB-to-serial and also for the "Yoyo"

    Not everyone is comfortable with wireless communications.

    :smile: That is quite an understatement. :smile:

    There are a lot of libraries available, for many different things. You can do a lot of different things with the B4X platforms and mobile devices. I really started digging around this morning and was amazed at some of the stuff I had found.

    You may already know this or perhaps maybe not, but I am seeking an answer, and perhaps you may know that as well. This morning, I downloaded and installed the "B4A Object Browser", which is a stand alone application, and can be found here: https://b4x.com/android/forum/threads/b4x-b4a-b4i-b4j-and-b4r-api-documentation-b4x-object-browser.25682/

    After providing the path to the libraries folder in the "Options", the B4A Object Browser loaded itself with a lot of wonderful information contained within that libraries folder. However, after a quick glance, I did not notice any information pertaining to the libraries listed on this web page: https://b4x.com/android/documentation.html

    So my question is, are those libraries buried deep within the B4A Object Browser, and if not, how do I get access to those libraries?
  • I may be totally off with my reply here but IIRC, the additional libraries don't go in the same location as B4A's libraries.

    I will investigate and re-read your question in a few hours. Been a long day here and I'm nodding off.
  • I may be totally off with my reply here but IIRC, the additional libraries don't go in the same location as B4A's libraries.

    You are correct, additional libraries should go to a different location and folder. The B4A software as well as the B4A Object Browser, both allow you to specify paths to additional libraries.

    I suppose the real questions are:

    Are the libraries listed at https://b4x.com/android/documentation.html installed with the B4A software, but located in a different library folder, or do they have to be downloaded seperately and individually, or can they be downloaded as a massive library upgrade :)

    If you don't know the answer, that is okay, I can do the research. I just thought you might know.
  • Oh I downloaded as required. I think that the very first one was "astreams" (?) as I wanted to get the BT working.
  • Mickster

    Yea, it looks as though you have to download the libraries after searching for them.
    Oh I downloaded as required. I think that the very first one was "astreams" (?) as I wanted to get the BT working.

    Okay... Curiousity risen :smile: What is BT?
  • Bluetooth.

    I think that you already stated that you have selected a BT module but if you ever consider the ESP32 as an alternative, you can program it using B4R (same syntax as B4A).
Sign In or Register to comment.