Data Transfer to smart device
oldhippy
Posts: 36
in BASIC Stamp
Any one know how to send ASCII data from a BS2 to a smart device (iPhone,android phone,Tablet, etc.)
Comments
I posted some thoughts about using App Inventor 2 here:
http://letsmakerobots.com/blog/duane-degn/creating-simple-android-apps-with-mit-app-inventor-2
Edit (4 October, 2015): The new owners of LMR deleted all my previous posts. Sorry about dead link.
There are a variety of inexpensive Bluetooth modules which should work great with the BS2.
Here are a couple of Bluetooth modules I've used and I like.
The HC-05 is a popular one.
http://www.icstation.com/wireless-bluetooth-transceiver-module-rs232-p-1434.html
It has a "KEY" pin which can be set high to place the module in programming mode. The HC-05 can be used either as a master device or a slave device. Its default setting should work fine with a BS2 and Android phone.
Another module I like is from ElectroDragon.
http://www.electrodragon.com/product/edpa-bluetooth-module/
This one is also easy to use. This module has an interrupt pin which I believe indicates there is data in the UART. I think this interrupt pin makes this module very useful.
I've used both these modules with an Android phone and Propeller boards.
You likely need some sort of level shifter to protect the Bluetooth module from the 5V logic of the BS2. I think you could get away with using a couple resistors as a voltage divider. The BS2 should be able to read the 3.3V signal from the module just fine.
But I am not entirely happy with the Android Bluetooth Terminal Apps that I have tried so far. Each one has a different oddity that seems to get in the way. Currently I use Bluetooth on a LInux Netbook with a real keyboard and that is more pleasant.
It is limited to 115200baud (way beyond the BS2) and 8N1 format.
Yes it is 3.3VDC powered and preferred logic level.
Arduinos claim the voltage divider solution is good...
"For the HC-05 RX pin (data in) we need to convert the Arduinos 5V to 3.3v. A simple way to do this is by using a voltage divider made from a couple of resistors. In my case I use a 1K ohm resistor and a 2K ohm resistor.
As a quick guide to the voltage divider; 1K + 2K = 3K. 1K is a third of 3K so it reduces the voltage by a third.
One third of 5V is 1.66 and 5-1.66 = 3.33 which is what we want. Putting the resistors the other way would reduce the voltage by 2 thirds."
On the HC-05 Tx pin (data out), the 3.3VDC High is high enough for the BS2.
++++
My own use is on a Propeller programmed with Forth and everything has been up and running 24/7 for several weeks now.
++++
Both the HC-05 and HC-06 boot and power up in an configuration mode and wait for AT prefaced instructions. Any use with the BS2 will have to either provide the expected AT instructions or wait for that phase to cease. I do believe that once you set the Baud rate (needed for the slower BS2) it will remember after being turned off and restarted.
The HC-05 is different than the HC-06 in this regard. There are two ways to enter command mode with the HC-05. The first way is to hold the KEY pin high as the module is powered on. When the command mode is entered this way, the baud will be always be 38400.
The other way to enter command mode with the HC-05 is to pull the KEY pin high after the module has been powered on. In this case, the baud setting of the device will be used. If the "AT+RESET" command is given while in command mode, the baud may switch to 38400 but it doesn't always do this. I think it depends if the device is communicating with another Bluetooth device or not.
I've notice transmissions from another device can knock the HC-05 out of command mode.
Baud changes to the HC-05 don't take effect until the module has been restarted.
The various AT commands are different depending on the module used. Some modules have a single digit code to indicate which baud to use. The HC-05 uses the full baud number to change the baud. You'll need to make sure you find instructions for your specific module in order to change the modules settings.
A lot of users have the HC06 and are confused about what they have...so they call it and HC05. Sellers on Ebay are also confused.
I'd recommend the HC-05. I have both but I rarely use the HC-06.
The pdf linked below compares the HC-05 and HC-06.
tec.reutlingen-university.de/uploads/media/DatenblattHC-05_BT-Modul.pdf
IMO (and the opinion of the author of the above paper) the HC-05 is the better choice for most (IMO all) applications.
I've used the HC-06 with Propeller projects, and it's not bad once you get the hang of it. The problem I've found is that its AT interface does not wait for a terminating character (e.g., CR), it is time based. What one really needs to do is setup macros in a advanced terminal to send the entire string at once. As I'm using it with the Propeller, I wrote a Spin program that parses my commands into PST and then sends them to the HC-06; responses from the HC-06 are echoed to PST. Using my parser object I can issue a command like BAUD 57600 and the Spin code will translate that and send the correct AT command. It was only about an hour's worth of work, but well worth the effort as it greatly simplifies configuring the HC-06.
I have read the factory default is 9600baud 8n1, but then I see other people saying other things. (IIRC, my own purchase defaulted to 9600 baud.)
My use is a Propeller 1 that is on 24/7 and loaded with Forth. The Propeller is powered from a wallwart that is also trickle charging a 12VDC gel cell that assures perpetual operation. And it all sits in a plastic breadbox next to the wall outlet.
++++++++++++++++
When the HC-05 or HC-06 first arrives, it may be configured with a baud rate that is too fast for BasicStamp use. So you have set up an RS232 port (directly for via USB adapter, from your computer and have your first session via a Terminal program).
Set aside your BasicStamp and first explore the device with your computer hardwired to the serial port. If you desire to look for the BT activity at the same time, use a cell phone. laptop, or notebook computer separate from the one that is doing the configuration.
At the same time, you can observe how the AT commands interact and the rather annoying fact that they don't wait for a CR, LF, or CRLF. Yes, macros in your terminal software work much better than pure keyboard input, but you can use 'cut and paste' instead of macros.
The keyboard may just frustrate you.
Power down your BT device and check again to see that the baud rate holds and you will again see the what you get for a Prompt in terminal.
From the Prompt, you have to wait for AT mode to time out or you begin to get into a garbled exchange of attempts to receive AT commands.
Sending a simple AT should reply with OK, confirm operation. Typing really fast might actually work. Then you can start your wait for change to normal communications mode.
For the slave that remains perpetually on, I don't have to change identity or PIN. It just sits there waiting for the Master BT to connect. I haven't messed with AT for many months.
This is one of many ways in which the HC-05 and HC-06 modules are different. The HC-05 waits for the end of line characters.
A lot of your other concerns are also not present in the HC-05 since the KEY pin has to be set high in order to enter AT mode.
The password (default 1234) can be changed and so can the name of the module. I'm pretty sure the module's address can't be changed (I tried).
BTW, MIT's App Inventor 2 makes it relatively easy to write one's own BT interface for an Android device. AI2 has its drawbacks but its easy of use makes putting up with these drawbacks worthwhile IMO.
I shared some thoughts about App Inventor 2 on the Let's Make Robots site.
letsmakerobots.com/blog/duane-degn/creating-simple-android-apps-with-mit-app-inventor-2
Sorry all my posts at LMR were deleted by the new owners.