Feedback!

Wearable Wayfinder Bluetooth

Views: 1512 Difficulty: 2 Status: Development
3screens_weird

Wireless communication on the wearable wayfinder.

Talk to the Wearable Wayfinder without wires! The Wearable Wayfinder comes equipped with RN-42 Bluetooth module, which allows for wireless communication with any bluetooth enabled device like smart phones and PCs. In this tutorial we share code for sending simple messages back and forth between a Wearable Wayfinder and the Arduino program's Serial terminal.

Step-by-Step Instructions

Step 0 Pair 'em up

Open up your bluetooth preferences on your computer or mobile device. Make sure the Wearable Wayfinder is turned on. You should see it listed with the other bluetooth devices in the neighborhood. The RN-42 Chips we use show up as FireFly-xxxx. Click the pair button to establish the bluetooth connection.

Step 1 If it Fails

Often we find the initial pairing attempt fails and you get a message like 'unable to connect to bluetooth device'. Don't lose hope! Click the options button on a Mac or open up the equivalent pairing option dialog on a PC.

Step 2 Enter the Code 1234

Enter the default code for the firefly RN-42 bluetooth chips of 1234. Then press the Pair button.

Step 3 Connected

Now you should be connected! You're ready to start communicating wirelessly.

Step 4 Select the Port

Now open up Arduino and navigate to Tools > Port. Select the bluetooth device you just paired with. On OS X the port is called /dev/cu/FireFly-xxxx-SPP. On Windows it will probably be some COM port with FireFly in the name. The check mark lets you know this Port is selected. Now when you press the Serial Monitor button (the one in the upper right of the Arduino window with the magnifying glass you will be connecting to the Bluetooth device. Upload the code below onto you Wearable Wayfinder and feel the wireless magic!

Bluetooth Transceiver

Here is Arduino code to talk to a Wearable Wayfinder over bluetooth. The loop function just 3 lines long. We read the Serial Port to see if any messages have been sent, we check the inputs on the Wayfinder to see if the buttons are being pushed or the potentiometer has been spun, then if we have received a message we scroll it across the Wayfinder's screen. Note that we use the Serial1 port for bluetooth communication as in:
  if (ww.btn_1_pressed()){
    ww.clear_screen();
    Serial1.println("Btn 1 pressed");
    ww.draw_string(5, 96, "Btn 1 pressed", ww.stroke.color_16(), 1);
  }
This is because the Wayfinder is based on the Arduino Leonardo and the Serial port refers to the built-in Serial line for communication over USB. When you spin the wayfinder's potentiometer or press its buttons we send messages over bluetooth to the Serial Monitor. You can send messages to the Wayfinder by typing them into the Serial Monitor and pressing return/enter.
/* LucidTronix Wearable Wayfinder 
 * Blue Tooth Transeiver
 * written by samwell freeman for LucidTronix
 * For instructions, and documentation See:
 * http://www.lucidtronix.com/tutorials/64
 */

#include <WearableWayfinder.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <Wire.h>
#include <SPI.h>
#include <Color.h>
#include <HMC5883L.h>
#include <MCP79410.h>
#include <I2C.h>
#include <MMA8453Q.h>

// for leo:
Adafruit_ST7735  tft = Adafruit_ST7735(SS, 9, 8);
WearableWayfinder ww = WearableWayfinder(&tft);

int old_pot = 0;
const int buffer_size = 18;
char buffer_in[buffer_size];
int char_index = 0;

void setup() {
  Serial1.begin(115200);    	//initialize Serial1
  Serial.begin(115200);    	//initialize Serial1

  for(int i = 0; i < buffer_size; i++) buffer_in[i] = 0;

  ww.initialize();
  ww.draw_string(5, 6, "BLUE", Color(30, 35, 255).color_16(), 3);
  ww.draw_string(15, 36, "TOOTH", Color(30, 35, 255).color_16(), 3);
  ww.draw_string(2, 76, "transiever", Color(30, 135, 235).color_16(), 2);
  
  delay(2500);
  ww.clear_screen();

}

void loop() {   
  if (Serial1.available() > 0){
    char cur_char;
    while((cur_char = Serial1.read()) != -1){
      buffer_in[char_index] = cur_char;
      char_index = ++char_index % buffer_size;
    }
    Serial1.print("received string:");
    Serial1.println(buffer_in);
    tft.fillRect(1, 145, 127, 10, ww.background.color_16());
    ww.draw_string(2, 145, buffer_in, ww.stroke.color_16(), 1);
  }
  
  if (ww.btn_1_pressed()){
    ww.clear_screen();
    Serial1.println("Btn 1 pressed");
    ww.draw_string(5, 106, "Btn 1 pressed", ww.stroke.color_16(), 1);
  }
  
  if (ww.btn_2_pressed()){
    ww.clear_screen();
    Serial1.println("Btn 2 pressed");
    ww.draw_string(5, 106, "Btn 2 pressed", ww.stroke.color_16(), 1);
  }

  int pot =  analogRead(0);
  if(abs(pot-old_pot) > 5) {
    old_pot = pot;
    tft.fillRect(10, 45, 50, 10, ww.background.color_16()); 
    ww.draw_string(5, 36, "Potentiometer", ww.stroke.color_16(), 1);
    ww.print_integer(10, 45, pot, 1);
    Serial1.print("Wheel Reeds:");
    Serial1.println(pot);
  }
}

Parts

Title Description # Cost Link Picture
Wearable Wayfinder An Arduino on steroids! Full color LCD screen, accelerometer, compass, and real time clock loaded onto a wearable gadget! 1 $69.95 Link 3screens2
Permalink: http://lucidtronix.com/tutorials/64
Control the Heart Matrix LED display wirelessly, using XBEE radio modules....
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Use the Wearable Wayfinder and the MCP79410 Real time clock chip to make an Arduino alarm clock....
From simple rules emerge mysterious and intricate patterns....
Coupling the HMC5883L Compass with our color library turns the Wearable Wayfinder into a handy naviga...
A wearable real-time clock with vibrant color display....
This circuit lets you talk to an XBEE serial port with 5V power and just two signal lines: RX and TX....
The MCP79410 breakout board gives easy access to this cute little timekeeper....