SimpleTerm on the Arduino step-by-step essential for dev

I love my Arduino :x

SimpleTerm on the Arduino step-by-step essential for dev

Postby Ian » Mon Sep 02, 2013 10:19 am

To catapult your career as a fantastic doohickey designer it is essential that you get a good system going where you can type commands into the Arduino Serial Monitor that will be sent to BTInterface and also where you can read anything sent by BTInterface on the Arduino Serial Monitor.

To begin you need to connect up your Bluetooth module and I use the cheap Linvor 4-pin module with the Transmit pin (TX) connected to pin 10 and the Receive pin (RX) connected to pin 11.

The Arduino Serial Monitor is opened either by clicking Tools > Serial Monitor, by doing the keyboard combination of Ctrl+Shift+M (M for Monitor) or by clicking on the little spyglass graphic at the top-right of the Arduino IDE.

When you have the Serial Monitor displayed you should make sure that the two drop-downs on the bottom-right are set to No line ending and 9600 baud.

Load up this sketch: SimpleTerm into your Arduino:
Code: Select all
#include <SoftwareSerial.h>
// using the SoftwareSerial library allows the developer to choose
// which pins to put the bluetooth module on. Unfortunately some
// bluetooth 'shields' are hardwired to use Pins 0 and 1 which makes
// two-way communication with the Serial Monitor impossible :(
// use a cheap 'Linvor' 4 pin bluetooth module instead
// please see the Arduino section in the forum at www.BTInterface.com
// Set the Arduino Serial Monitor to 9600 Baud and no line ending.

// Receive pin (RX), Transmit pin (TX) of the Bluetooth module
SoftwareSerial softSerial(10, 11); 
String command = ""; // Stores response of bluetooth device
int baudrate = 9600;

void setup() 
{
  Serial.begin(baudrate);
  softSerial.begin(baudrate);
  Serial.println("SimpleTerm Ready!");
}

void loop()
{
  // SoftSerial is to and from the Bluetooth device 
  // Serial is to and from the PC (Arduino Serial Monitor).
 
   if (Serial.available()) softSerial.write(Serial.read()); // send from Arduino to Bluetooth
   while(softSerial.available() > 0) { // While there is more to be read, keep reading.
     command += (char)softSerial.read();
     delay(1); // gives it a chance to get all the characters
   }
   
// Your code can go here   
   
  // copy what's in command to the serial monitor.
   if(command != "") Serial.println(command); // send from Bluetooth to Serial Monitor
     
   command = ""; //empty the command string ready for the next use.
}// END loop()


With this code running on the Arduino when you open the Serial Monitor the first thing you see is the text SimpleTerm Ready!
And now you can connect to the Arduino with BTInterface, when BTInterface connects you see the word btinterface in the Serial Monitor, that's because this is the first thing that happens upon a new connection and you can use that in your Arduino code to detect that BTInterface has connected.

As it stands right now you can type in commands in the top line of the Serial Monitor and hit the send button or the return key on your keyboard to send them to BTInterface and you can see anything that BTInterface sends in the main area.

Try pressing on a few buttons, changing a slider etc. to see what BTInterface sends to the Arduino.

Now for the fun part, try sending commands to BTInterface such as:
sfx10
say hello there how are you?
1
b1 Press Me
stats
term
1
b2h
ph
sb90
sb10
sbh
l1 < This is button one
l1c
l1r
l1l

Having fun yet? < don't type that in, it was a question :)
Image
BTInterface

Its a thing that allows you to do things with things.

Please Donate to support further development of BTInterface, thank you
https://www.paypal.com/cgi-bin/webscr?c ... aNonHosted
User avatar
Ian
Site Admin
 
Posts: 269
Joined: Sun Jan 13, 2013 3:24 pm

Return to Arduino

Who is online

Users browsing this forum: No registered users and 1 guest

cron