Shop OBEX P1 Docs P2 Docs Learn Events
RN-42 Control Demo from Android Phone — Parallax Forums

RN-42 Control Demo from Android Phone

JonnyMacJonnyMac Posts: 9,105
edited 2015-01-29 14:06 in Propeller 1
The RN-42 comes with a bit of a demo for the BASIC Stamp, but I haven't seen anything targeting the Propeller. As I have several projects that could benefit from control from my phone, I decided to dig in.

My test platform is an RN-42 (early release) and a Propeller Activity Board. The module is set for 3.3V operation and RTS and CTS are tied together.

I created a little configuration program that uses two copies of FullDuplexSerial (my variant) -- one copy for PST, the other for the RN-42 (yes, I know there are multii-port serial objects; for the moment I'm keeping sticking to objects I use every day). The purpose of this program is to configure the RN-42 to your liking. I set the baud rate to 9600 baud. One can also change the device name, pairing password and other parameters. Again, I stuck to simple an just changed the baud rate as in the BS2 example code.

The control program -- for testing at the moment -- receives a string from my phone and parses it into individual tokens (up to 10). Once the tokens are extracted they can be acted upon. I decided to go this route so that I could test a control mechanism with a terminal by typing things in. The current program parses the command string and gives a detailed report. It does have a bit of control code for the LEDs on P26 and P27. For example, if the command string is "P26 ON" (without the quotes), the LED will come on. The second token can also be "1" or "HIGH" to turn on the LED. To go the other way uses "OFF", "0" (zero), or "LOW".

My phone app (created in MIT App Inventor 2) is minimal: just a means to connect to the RN-42, a text box for a command string, and a SEND button. Future apps will have control strings built into UI widget event handlers -- for the moment, this lets me test strings on-the-fly. I've included the source code for my phone controller in case you want to play with it. Creating a nice layout is not easy in AI2 -- it's not like VB or other screen builders when you can do precise positioning. You'll see that I use the layout controllers as spacers to make an attractive layout.

This is alpha code, but I wanted to share it in the event anyone has feedback that may be useful. I saw a note from Chris Savage that the RN-42 requires an update -- I hope that Parallax will consider a 3.3V only variation of the RN-42 that will plug into the XBee socket -- that would save valuable space on the PAB's small breadboard. Sparkfun has such a beast and I've ordered it to try.

Comments

  • RS_JimRS_Jim Posts: 1,765
    edited 2015-01-27 05:24
    Cool, I will be following this with interest!
    Jim
  • twm47099twm47099 Posts: 867
    edited 2015-01-27 07:18
    Jon,
    I have written a couple of programs using the Sparkfun RN42 (XBee form factor which defaults to 115200 baud) for controlling my Activity Bot using an Android tablets (Samsung Tab 2 and Tab 3) with bluetooth. In post 3 of the link below I have a couple of links to the threads where I document my adventures (it was my first learning experience in developing a large multi-cog program for the propeller.)

    http://forums.parallax.com/showthread.php/158938-rn-42-bluetooth-to-propeller-code-example?highlight=twm47099

    I believe that your Prop language of choice is Spin. My program is in C since it was a follow-up to the Paralax C-learning tutorials, and I haven't gotten that far with Spin yet.

    The C code is highly commented, I just hope it is clear.

    The Android controller is a free app in Google Play (link in the post mentioned above), it is a "joystick" with 6 on-off buttons, and has limited 2 way communication. (I have no experience programming for Android).

    I have followed a number of your projects and look forward to learning more about programming the Prop and an android device from your efforts (I appreciate the way you use small "standard" methods to build your programs; I still tend to large functions which end up being useful in one project, but then need a lot of modification to use in a different project.)

    Tom
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-27 09:29
    I installed the latest version of that robot controller and will knock up a bit of Spin code to test with.

    My goal is to be able to develop custom solutions on both ends. I also decided to use a text-based protocol (which is slower and requires more data, I know) so that I can test the client end using a simple terminal. I think it would be fun if several of us started developing smart phone apps that target the Propeller.

    I really wish there was an MIT App Inventor for iOS because I want to have solutions for both platforms. There is a tool called PhoneGap that I'm looking into.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-01-27 09:53
    Nice concept. I will be following with interest, especially the IOS version.
    Agreed that a text based system is the most flexible. It doesnt matter with a simple system being text based sending a bit more data.
  • rosco_pcrosco_pc Posts: 464
    edited 2015-01-27 22:45
    Open Sound Cntrol sounds like it would fit your purpose. There are apps on both ios an android that allow you to design your interface ancomicate with OCS on a server device. Relatively simple protocol
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-27 22:56
    Open Sound Cntrol sounds like it would fit your purpose.

    Really? How would I control a stadium-sized scoreboard (in a test environment) via Bluetooth using OSC? Can you point to specific examples that would demonstrate your assertion?
  • rosco_pcrosco_pc Posts: 464
    edited 2015-01-28 01:19
    http://www.lightjams.com/

    I know this is done over WIFI, but bluetooth should be possible.

    Edit: OSC is just the protocol and is pretty open ended.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-01-28 16:00
    The protocol part is easy -- have done that many times. What I'm after is a tool that allows me to develop smart phone apps. At the moment, I'm using MIT App Inventor but will probably switch to something like Phonegap later so I can deploy on Android and iOS.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-01-28 18:47
    Jon,
    I am particularly interested in your experiences with Android and iOS apps.
    I will need to do this for a remote product that reports status every few hours via the mobile internet. Interrogation will be via an Android/iOS/Windows app. At this stage I am unsure if I could use a browser for this, or have to write an app for it.
  • rosco_pcrosco_pc Posts: 464
    edited 2015-01-28 19:11
  • max72max72 Posts: 1,155
    edited 2015-01-29 14:06
    Some OSC apps offer the possibility to create custom controls.
    The main connection is wifi/UDP, very fast.
    I tested the appinventor and is nice and easy to use. On the other hand the controls are limited (for instance sliders only in a direction). The advantage is you can send any message while with openosc there are more limits on the messages, but more flexibility on the controls.
    Massimo
Sign In or Register to comment.