* The preview only display some random pages of manuals. You can download
full content via the form below.
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
ANNIKKEN ANDEE USER GUIDE
Piasim Corporation Pte Ltd Revision F5
1/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Table of Contents 1 What is Annikken Andee?......................................................................................... 5 2 Getting Started...........................................................................................................7 2.1 Hardware Setup........................................................................................................... 7 2.1.1 Connecting Arduino with Computer.................................................................... 7 2.1.2 Annikken Andee Setup......................................................................................... 7 2.2 Bluetooth Pairing........................................................................................................ 8 2.2.1 Annikken Andee and Android Device.................................................................. 8 2.3 Software Setup............................................................................................................ 8
3 Hardware Overview.................................................................................................10 3.1 Power Connections.................................................................................................... 10 3.2 SPI Connections........................................................................................................ 10 3.3 SD Card..................................................................................................................... 10 3.4 LEDs......................................................................................................................... 11
4 Andee Library For Arduino..................................................................................... 13 4.1 Installing Andee Library............................................................................................ 13 4.2 Running the Example - “Hello World”...................................................................... 15 4.3 Basic Program Loop.................................................................................................. 17 4.4 Output Data on Android from Arduino...................................................................... 17 4.5 Beyond Basic Program Loop.....................................................................................24 4.6 Input Data from Android to Arduino......................................................................... 29 4.6.1 BUTTON_IN Displays...................................................................................... 29 4.6.2 KEYBOARD_IN Displays................................................................................ 31 4.7 Removing Displays................................................................................................... 36 4.8 Getting For Annikken Andee Status.......................................................................... 41 4.9 Disconnect and Connection Status............................................................................ 43 4.10 Read and Write SD Card........................................................................................ 44 Piasim Corporation Pte Ltd Revision F5
2/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
4.10.1 Reading A Line From SD................................................................................. 46 4.10.2 Read A Number Of Bytes From SD................................................................. 48 4.10.3 Writing Data to SD........................................................................................... 50 4.11 Sending SMS and Creating Notifications................................................................ 51
5 String Limits............................................................................................................ 53 6 Connector SV2 Functionality.................................................................................. 54 7 Upgrading Firmware................................................................................................54 8 Annikken Andee Specifications...............................................................................57 8.1 Data Rate................................................................................................................... 57 8.2 Dimensions................................................................................................................ 58
Piasim Corporation Pte Ltd Revision F5
3/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Version Changes F2
Separated API reference to another document.
F3
-added function description of SV2 of Annikken Andee
F4
Major change of memory management.
Piasim Corporation Pte Ltd Revision F5
4/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
1 What is Annikken Andee?
Illustration 1: Annikken Andee
Illustration 2: Function calls in Arduino to create displays on Android
Annikken Andee is a Bluetooth add-on shield for the popular Arduino platform. With Annikken Andee's library and its Android app, you can easily create touch interfaces, display data and use phone functions, like SMS on Android platforms – without writing any Android code. From your Arduino code, just call a simple function and watch your data simply appearing on your android device! Annikken Andee is your handy mailman in sending and receiving data to and from a mobile
Illustration 3: Screenshot of created
device.
display
Piasim Corporation Pte Ltd Revision F5
5/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Annikken Andee is also capable creating displays with touch capabilities, capturing user touch events and sending it to Arduino, where you can code a function to handle the Android touch event in Arduino code. Annikken Andee is also capable of creating displays which allows Android users to key in passwords, text, numbers using the Android keyboard. This information will, likewise, be sent to your Arduino, where you can handle the input. Furthermore, Annikken Andee is designed to take up minimal amount of memory on Arduino. Using the Andee library will take up about (330 + 2n) bytes of memory, where n is the number of displays you wish to create on Annikken Andee. Annikken Andee stores information about what to display in its own memory, and not your Arduino's memory, so as to free up precious Arduino memory for your design. Annikken Andee holds in its memory the data to display on the connected Android device. Your work only involves configuring these memory, i.e. helper.setData(“Hello World”), or giving Annikken Andee instructions, i.e. helper.update(), in your Arduino
code. Annikken Andee takes care of the complicated bluetooth wireless management stuff for you. The Andee Library for Arduino abstracts complicated SPI communications between Arduino and Annikken Andee. You only worry about your Arduino design. If you have an existing application with Arduino and wish create an interface on Android, Annikken Andee clearly is THE choice!
Piasim Corporation Pte Ltd Revision F5
6/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
2 Getting Started 2.1 Hardware Setup 2.1.1
Connecting Arduino with Computer
You should make sure your Arduino board is functioning properly first. Connect Arduino to your computer using USB, note the COM number being assigned by your computer. For mac users, you will be assigned a /dev/tty* instead. Next, launch the Arduino IDE and connect to it using the assigned com port number. You should now load some Arduino examples. For detailed instructions on setting up your Arduino, visit www.arduino.cc to look for setup instructions of your Arduino board.
2.1.2
Annikken Andee Setup
NOTE! Remove power to Arduino first before plugging in Annikken Andee. Plug Annikken Andee on top of Arduino as shown. Connection is made between the two via the ICSP connector (Arduino) and pin 8. Annikken Andee is powered via the 5V pin of Arduino's ICSP connector.
Illustration 4: Annikken Andee with Arduino Uno
Piasim Corporation Pte Ltd Revision F5
7/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 5: Blinking LD2 Power up Arduino either by USB (recommended) or power adapter. Led LD2 of Annikken Andee should be blinking, indicating its ready for connection. USB is recommended because it can debug and program Arduino.
2.2 Bluetooth Pairing 2.2.1
Annikken Andee and Android Device
Annikken Andee pairs with Android devices without requiring any pin code. From your Android device: Settings -> Bluetooth -> Scan
Click on the Annikken Andee device that shows up after scanning to pair with it. Should your device request for a pin code, key in 0000.
2.3 Software Setup •
Download the Annikken Andee App from Google Play Store and install it onto your Android device.
•
Enable Bluetooth on your Android device. Make sure Annikken Andee is plugged onto Arduino and powered on. Pair Annikken Andee with you Android using the android's system settings.
•
Launch Annikken Andee App. You should be prompted with a bluetooth connection screen. If not, press the “Connect” icon from the app's activity bar.
Piasim Corporation Pte Ltd Revision F5
8/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Connect Button
Illustration 6: Connect icon from
Illustration 7: Bluetooth list of
app's activity bar
devices to connect
•
Select the Annikken Andee device you with to connect with.
•
Annikken Andee's LD2 should be blinking red, indicating an active connection.
•
Install Annikken Andee Library and run the examples. The library can be downloaded from www.annikken.com/annikkenandee/AndeeLibrary.zip. Detailed instructions are in section 4.1 Installing Andee Library. You should see data appearing in the app by running the example sketches provided under Examples -> Andee of Arduino IDE (Arduino code are called sketches).
Piasim Corporation Pte Ltd Revision F5
9/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
3 Hardware Overview 3.1 Power Connections
Illustration 8: ICSP and Pin8
Annikken Andee draws a 5V supply from Arduino. Internal circuitry onboard then steps down this to 3.3V to power all of Annikken Andee. Power connection is made via the ICSP connector of Arduino.
3.2 SPI Connections Pin 8 of Arduino is connected to Annikken Andee. ICSP of Arduino is also connected to Annikken Andee. These pins provide SPI connections for transferring of data. Arduino is configured as a master and Annikken Andee a slave. Pin 8 acts as a slave select pin from Arduino to Annikken Andee. You should avoid using pin 8 or Arduino to make any external connections.
3.3 SD Card The SD Card slots accepts standard sd cards. It allows users to have an extra memory storage should they need it. The read write functions are provided in the Andee library Piasim Corporation Pte Ltd Revision F5
10/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino
•
By Annikken
for Arduino.
3.4 LEDs There are 3 leds. •
ON: Indicates that power is being supplied to Annikken Andee
•
LD1:
◦ Blinking Green – Indication presence of write activity to Annikken Andee. •
LD2: ◦ Blinking Green – No bluetooth connection with Android
◦ Blinking Red – Active Connection with Android
•
LD1 and LD2: ◦ Both blinking red – SDCard not present or image.hex file not found. (Bootload mode)
Piasim Corporation Pte Ltd Revision F5
11/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
◦ Alternate Green (LD1) and Red (LD2) – Firmware programming in progress. (Bootload mode)
◦ Alternate Green/Green and Red/Red – Downloaded firmware is corrupted. (Bootload mode)
Piasim Corporation Pte Ltd Revision F5
12/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
4 Andee Library For Arduino Arduino programmers can use the Andee Library for Arduino to send and fetch data from Annikken Andee. Annikken Andee will, likewise, send and fetch your data between itself and Annikken Andee App on Android. There's no need not meddle with Android programming for the mobile phone, initiating and maintaining wireless connections, or setting up SPI connections. It simply works. You create Android interfaces (with Annikken Andee App) using function calls, provided by the library, in Arduino.
4.1 Installing Andee Library Here are the instruction to install the Andee library. Once installed, you can easily use the functions to create new Arduino sketches or integrate them with existing ones. (Arduino programs are known as sketches). Firstly make sure you have already installed the Arduino IDE. Get the correct version of Arduino IDE from www.arduino.cc. The following instructions will guide you through on how to install Andee library so your Arduino IDE can use it. Note: For a detailed instruction on creating and installing an external library, you can look up this link: http://arduino.cc/en/Hacking/LibraryTutorial 1. First, download the zip file from www.annikken.com/annikkenandee/AndeeLibrary.zip. 2. Locate the libraries sub-directory of your Arduino sketchbook directory. For windows, its normally found at: C:\Users\
\Documents\Arduino Mac users, ~\Documents\Arduino
Piasim Corporation Pte Ltd Revision F5
13/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Illustration 9: Libraries folder created by Arduino 3. Here create a directory named “Libraries” if it does not exists. Normally this library will be create when you install Arduino and ran it. 4. Unzipped the downloaded file AndeeLibrary.zip, and copy the entire “Andee” folder into the “Libraries” folder. Note that your “Libraries” folder may contain other libraries contributed by other Arduino users.
Illustration 10: Copy Andee Folder into Libraries 5. Launch the Arduino IDE. Go to Sketch -> Import Library. You should see the Andee library listed. Note: You may need to restart Arduino IDE to see the library listed. You can now use the Annikken Andee library for your Arduino projects.
Piasim Corporation Pte Ltd Revision F5
14/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 11: Import library into sketches
4.2 Running the Example - “Hello World” In this section, we will be guiding print a text “Hello World” to an Android screen. •
Plug Annikken Andee on top of your Arduino board.
•
Connect Arduino with your computer using USB and launch Arduino IDE. This will also power up Annikken Andee and you should see a blinking green led (LD2).
Piasim Corporation Pte Ltd Revision F5
15/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
• •
From Arduino, open up the example “Demo1_HelloWorld”. From Arduino, select File->Examples ->Andee -> Demo1_HelloWorld
•
On Android, turn on bluetooth, pair your Android with your Annikken Andee. Annikken Andee should have a name like “Andee XXXX”, where XXXX are numbers.
•
On Android, launch Annikken Andee App (available from Google Play store).
•
Click on “Bluetooth List” if its available to you.
•
Choose the appropriate Annikken Andee by checking its box and click the 'Connect' button at the bottom of Illustration 12: Bluetooth the list. Once connected, you should notice that LD2 List of devices of Annikken Andee is blinking red.
•
Upload your program by clicking the 'Upload' button from your Arduino IDE. Your program should compile and once loaded you should see a screen like this on your Android device. If data is not showing, please reset Arduino.
Illustration 13: Demo1_HelloWorld Screenshot •
Congratulations! Your Android is now communicating with Annikken Andee.
Piasim Corporation Pte Ltd Revision F5
16/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
4.3 Basic Program Loop This a basic loop to get your data to be displayed on an Android.
Illustration 14: Basic Program Flow We will use Demo1_HelloWorld demo program included with the Andee library to show you where to perform these tasks in an Arduino sketch.
4.4 Output Data on Android from Arduino To output data from Arduino to Android, you use a DATA_OUT display. Here is a screenshot of a DATA_OUT display that spans the full width of Android. Displays can occupy 1/4, 1/3, 1/2, 2/3, 3/4 or the FULL width of Android screen. Let's use the Demo1_HelloWorld example to illustrate this. Here is the code you need to write in Arduino to display a DATA_OUT display on Android. Piasim Corporation Pte Ltd Revision F5
17/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
//Program outputs Hello World to a display #include #include #include //to use delay function //Declare an instance of AndeeHelper to help manage our display. AndeeHelper andeeHelper; void setup(){ //Setup communications between Annikken Andee and Arduino Andee.begin(); andeeHelper.setId(14); //Give this helper a unique ID andeeHelper.setType(DATA_OUT); //Set Type to DATA_OUT andeeHelper.setLocation(0, 0, FULL); //Row, Order, Span //Set the title, data and units fields of our display. AndeeHelper.setTitle("Hello Title"); AndeeHelper.setData("This is Data Field"); andeeHelper.setUnit("Units Field"); }
Andee.clear();//Clear the screen of any previous displays
void loop(){ // Tell Andee to display our DATA_OUT andeeHelper.update(); //Delay for 1 second, here we send update every second. delay(1000); }
To use Andee in Arduino sketches, we need to include the necessary libraries. Since our Andee.h library uses the SPI.h library, be sure to include it in your sketch.
#include #include
Create Helpers Tasks – refer to flowchart of previous section. We need to use AndeeHelper class to help manage our display on Android. You should have a AndeeHelper instance for each display on Android. This this example, we only want one DATA_OUT display. So we declare just one andeeHelper object. Next we will declare a AndeeHelper variable.
Piasim Corporation Pte Ltd Revision F5
18/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
#include #include AndeeHelper andeeHelper;
We use this instance to “save” data, like title and location or the text to display on Android, in Annikken Andee's memory via various function calls. Every Arduino sketch/program needs to have: •
void setup(){ }
•
void loop() {}
The Arduino's setup() function is only called once during the execution of the Arduino program. Normally, we do some setup here. It is here we do things that needs to be done first, or things that need to be done only once. #include #include AndeeHelper andeeHelper; void setup(){ Andee.begin(); andeeHelper.setId(14); andeeHelper.setType(DATA_OUT); andeeHelper.setLocation(0,0,FULL);
Andee.begin() We call Andee.begin() to setup communications between Annikken Andee and the Arduino board.
void setId(int id) When you call setId(id), you are associating this andeeHelper with a MemBlock inside Annikken Andee. Annikken Andee will initialize MemBlock[id] with defaults upon receiving this command.
Piasim Corporation Pte Ltd Revision F5
19/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 15: Memory Management in Annikken Andee After you have associated the andeeHelper with a MemBlock in Annikken Andee, any functions you call with andeeHelper will be directed at the MemBlock[id]. In our example we are using MemBlock[14], setId(14). void setType(char type) Use the pre-defined macros, DATA_OUT: data display, BUTTON_IN: button display, KEYBOARD_IN: display which allow user to send characters typed by Android keyboard to Arduino. This our example, we set to DATA_OUT as we want to simply display something. void setLocation(int row, int order, int span) This function, we give our helper location information for our display. For row, give it an integer from 0 to 3, corresponding to row 1 to row 4 of android display. For order, we set it to zero first. Order dictates the order (left-to-right) in which displays on the same row appears. A bigger order will be place on the right hand side of a smaller order. Order 1
Piasim Corporation Pte Ltd Revision F5
Order 2
Order 3
20/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
By setting it to zero, we are leaving it for the program to decide. Displays that are called to be output first will appear on the leftmost. For span, we want this display to fill the width of Android screen, so we use the macro FULL. Other macros you can use are: ONE_THIRD
Fills one third of width
TWO_THIRD
Fills two third of width
ONE_QUART
Fills one quarter of width
THREE_QUART
Fills three quarters of width
HALF
Fills half the width
Next, we give information to our helper that tells it what to populate our display with. Data displays have three fields we can use: title, data and unit. They can be used with the following functions.
setTitle(char*)
setData(char*) setUnit(char*)
Illustration 16: Fields you can populate data with #include #include AndeeHelper andeeHelper; void setup(){ Andee.begin(); andeeHelper.setId(0); andeeHelper.setType(DATA_OUT); andeeHelper.setLocation(0,0,FULL);
}
andeeHelper.setTitle("Hello Title"); andeeHelper.setData("This is Data Field"); AndeeHelper.setUnit("Units Field"); Andee.clear();//Clear the screen of any previous displays
Piasim Corporation Pte Ltd Revision F5
21/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
void setTitle(char* title) void setData(char* data) void setUnit(char* unit) Use the the above function to provide title, data and unit information to our DATA_OUT display. You can also use override functions to set title, data or unit. Character strings are limited to a maximum of 64 bytes. •
void setTitle(char*)
•
void setTitle(int value)
•
void setTitle(float value, int numberOfDecimalPlaces)
•
void setTitle(double value, int numberOfDecimalPlaces)
•
void setData(char*)
•
void setData(int value)
•
void setData(float value, int numberOfDecimalPlaces)
•
void setData(double value, int numberOfDecimalPlaces)
•
void setUnit(char*)
•
void setUnit(int value)
•
void setUnit(float value, int numberOfDecimalPlaces)
•
void setUnit(double value, int numberOfDecimalPlaces)
void clear() We call this to clear the Android screen of all previous displays. Note that by calling this, Annikken Andee's MemBlocks are not erased. The previous fields you saved in Annikken Andee's MemBlocks are intact. Update Helper With Data Task We move on to create the Arduino's loop() function. This Arduino program will keep calling its loop() function when its running. Normally, we perform data acquisitions or updates in the loop() function. You can think of this as the program's main loop. For this example, we do not have any data to update. Let's move on to the next task. Piasim Corporation Pte Ltd Revision F5
22/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
#include #include AndeeHelper andeeHelper; void setup(){ ... } void loop(){ }
Up till now, if you compile and upload the Arduino sketch, you will not see anything appear on your Android screen. This is because all we have done up till this point was only to give information to our Annikken Andee. You have not instructed Annikken Andee to create any display yet. Update Android Screen Task void update() Let's tell our helper to inform Android about our display. #include #include AndeeHelper andeeHelper; void setup(){ ... } void loop(){ andeeHelper.update(); Delay(1000); //Delay 1 second before the next update. }
When this function is called, Annikken Andee will inform Android where and what to display based on the information we gave it in our setup loop. Now we can upload this program to our Arduino board. You should see the display appearing on your Android screen.
Piasim Corporation Pte Ltd Revision F5
23/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
4.5 Acquiring Analog Data and Output to Android
Illustration 17: Snapshot of Demo2_SendAnalogReadings Notice that we create a function called setInitialData() helper functions to “configure” the MemBlocks of Annikken Andee. Let's bring the attention to the loop() of Arduino. Instead of using setData(...) and update() in sequence, we tell Annikken Andee to display data using updateData(...) function. Calling this will instruct Annikken Andee to update Android using the data we pass in. It has the effect of setData(...) and update() together, but it is less “heavy” in Piasim Corporation Pte Ltd Revision F5
24/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
the sense that only a single instruction is sent from Arduino to Annikken Andee. void updateData(char*) void updateData(int value) void updateData(float value, int numberOfDecimalPlaces) void updateData(double value, int numberOfDecimalPlaces)
Illustration 18: Demo2_SendAnalogReadings Screenshot
You should see the above screen after you upload the sketch to Arduino. Everything in blue can be confusing, you may want to bring attention to a certain analog pin, let's say A1 of Arduino, to show red. You can do so using the setColor(char* argb) and setTitleColor(char* argb) function. Let's add this function call inside
our setInitialData() helper function.
Illustration 19: Snapshot of setInitialData() code changes
Compile and upload the program and you should see the following screen. Piasim Corporation Pte Ltd Revision F5
25/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 20: Snapshot of color change for DATA_OUT Let's change some more colors, say for Analog A2. Let's change it to a light gray box with a white title bar.
Illustration 21: Changing more colors Compile and upload to see the change.
Illustration 22: Light colors Seems like we cannot see out text with light backgrounds. In Annikken Andee, you have a choice of white text or black text, i.e. TEXT_LIGHT, TEXT_DARK. Use the Piasim Corporation Pte Ltd Revision F5
26/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
following function to set them.
Illustration 24: DATA_OUT white background with black text Illustration 23: Setting the text colors to white or black Here is a list of settable color macros, you can pass in your own 8 character string as well: Macros
ARGB String
Macros
ARGB String
BLACK
"FF000000"
LTGRAY
"FFCCCCCC"
LIGHT_BLUE
"FF33B5E5"
GREEN
"FF00FF00"
BLUE
"FF0099CC"
MAGENTA
"FFFF00FF"
CYAN
"FF00FFFF"
RED
"FFFF0000"
DKGRAY
"FF444444"
WHITE
"FFFFFFFF"
GRAY
"FF888888"
YELLOW
"FFFFFF00"
TRANSPARENT
"00FFFFFF"
•
TEXT_LIGHT – '0'
•
TEXT_DARK – '1'
Piasim Corporation Pte Ltd Revision F5
27/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
4.6 Input Data from Android to Arduino
Illustration 25: BUTTON_IN and KEYBOARD_IN displays There are two ways to send messages from Android to Arduino through Annikkken Andee. BUTTON_IN displays send touch events to Arduino and KEYBOARD_IN sends a text entered by Android's soft keyboard to Arduino. Demo3_ ButtonAndKeyboard from examples shows you these two inputs.
4.6.1
BUTTON_IN Displays
BUTTON_IN displays sends a message to Annikken Andee when a user touches it. Your Arduino sketch can catch this using the isPressed() function. Below is a code of how to create a button on Android and catch the response.
Piasim Corporation Pte Ltd Revision F5
28/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
If you touch the BUTTON_IN display on Android, you will notice it will be overlay with a spinner when you touch it, and sometime later it goes away and a tick is shown at the bottom right corner of the BUTTON_IN display. In Annikken Andee App, all buttons and keyboards will show a “waiting for ack” spinner when user touches them. In the case for KEYBOARD_IN, “waiting for ack” spinner shows after users sends a text input out. The “waiting for ack” will disappear and a tick will be shown once the app receives an ack from Annikken Andee. Arduino users must instruct Annikken Andee to send ack using the ack() function. This will allow user to know if Arduino has handled the touch event already or not.
Illustration 27: Waiting for ack
Illustration 26: After App receives ack
Illustration 28: Feedback box updated after BUTTON is pressed Piasim Corporation Pte Ltd Revision F5
29/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Illustration 29: Code section generating the above interface
Piasim Corporation Pte Ltd Revision F5
30/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 30: Options shown after long press on "waiting for ack" button In the event when and ack is not received after sometime, the Android user can choose to resend the touch event (Resend), cancel it (Cancel Click) or continue waiting (Do Nothing). These options are made available via a long press on the BUTTON_IN display.
4.6.2
KEYBOARD_IN Displays
KEYBOARD_IN displays allows an Android user to send a character string (not more than 64 characters) from Android to Arduino. When an Android user touches a KEYBOARD_IN button, the Android app will provide a keyboard for user to key in a message to be sent to Annikken Andee. The way Arduino gets notified is similar to the way BUTTON_IN displays notify, via isPressed() function. Note the similarity of the code. Note that button and keyboard are AndeeHelpers instances, i.e. AndeeHelper Piasim Corporation Pte Ltd Revision F5
31/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
button, keyboard;
Illustration 31: Comparing BUTTON_IN and KEYBOARD_IN code Arduino code need to call getKeyboardMessage(char* buffer) to retrieve the user message from Annikken Andee. Note that userKeyboardInput is a char buffer you have to define in Arduino, i.e. userKeyboardInput[32]. Piasim Corporation Pte Ltd Revision F5
32/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 33: Soft keyboard shown when user presses button
Illustration 32: Feedback updated with user keyboard input
You can control the keyboard type using Arduino code. i.e. obscuring text or not obscuring text. This is normally used where user is to enter a password but do not wish the entered characters to be shown. Keyboard type is set using setKeyboardType(char) function. In the example below, we used setKeyboardType(ALPHA_NUMERIC_PW).
Piasim Corporation Pte Ltd Revision F5
33/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 34: Obscured text input There is a total of 8 types of keyboard input you can set. The first four as described are using Android's system soft keyboard, or any other third-party keyboard the user has installed. A “_PW” appended behind each macros would mean that the entered text will be obscured.
Piasim Corporation Pte Ltd Revision F5
34/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Keyboard Type MACRO
Piasim Corporation Pte Ltd Revision F5
Description
Screenshot
35/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
ALPHA_NUMERIC
The full set of Android
ALPHA_NUMERIC_PW
keyboard with numbers and characters.
ANDROID_NUMERIC
Android's numbers only
ANDROID_NUMERIC_PW
keyboard.
ANDEE_NUMERIC_A
Andee's numeric only
ANDEE_NUMERIC_A_PW
keyboard. Differs from
Piasim Corporation Pte Ltd Revision F5
(Landscape)
36/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Android numeric keyboard in the sense that it shows the button while in landscape mode. For Android numeric keyboard,
(Portrait)
only the keyboard and text entry field is shown.
ANDEE_NUMERIC_B
Similar to
ANDEE_NUMERIC_B_PW
ANDEE_NUMERIC_A but
(Landscape)
allows entry of decimals and negative numbers.
Piasim Corporation Pte Ltd Revision F5
37/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
(Portrait)
4.7 Removing Displays For some applications, you may wish to show or hide certain buttons or displays at certain times. For example, you may wish to hide a “open door” button until the user positively authenticated himself/herself. We will be using Demo4_RemoveAndDestroy. Demo4 is an extension of Demo3_ButtonAndKeyboard, the difference is that we will be adding handling functions to demonstrate the removal and destroying of displays on Android screen. Also there will be 2 additional DATA_OUT displays for the demonstration of remove() function. Upload Demo4_RemoveAndDestroy to your Arduino and you should see the following screen. Please take a look at the flowchart of the program to help you understand the program flow.
Piasim Corporation Pte Ltd Revision F5
38/68 July 2, 2013
Annikken Andee •
Piasim Corporation Pte Ltd Revision F5
Bluetooth Shield For Arduino By Annikken
39/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 35: Screenshot Demo4_RemoveDisplays
Let's see the setInitialData() function. Here you should notice that the two displays are updated here instead of inside the Arduino's loop function. This is so not to “recreate” the displays once remove() has been called. If we call update() on the two displays in the loop(), the displays will reappear after remove() has been called.
Piasim Corporation Pte Ltd Revision F5
40/68 July 2, 2013
Annikken Andee •
Piasim Corporation Pte Ltd Revision F5
Bluetooth Shield For Arduino By Annikken
41/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 36: Code snippet of setInitialData for Demo4_RemoveAndDestroy
Now for the handleKeyboardMessage() function. First we get the message from Annikken Andee using getKeyboardMessage(char*) function.
Illustration 37: handleKeyboardMessage() Then we call remove() on display[0] or display[1], depending on which what the user entered. The handleKeyboardMessage() is called in Arduino's loop function. Piasim Corporation Pte Ltd Revision F5
42/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Illustration 38: Arduino's loop function
Piasim Corporation Pte Ltd Revision F5
43/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 40: User enters '2'
Illustration 39: User enters '1'
You should notice that display number 2 is automatically flushed to the left of Android screen. This is the default behavior even when you have set the order of display to 1. Because in the first row, there is no displays before display 2, therefore it appears at the leftmost. If you wish for the display 2 to occupy the same position even after removing display 1, try modifiying display[0] to have transparent title and field color instead of calling remove(). This is demonstrated using the “Set Transparent” button.
Illustration 41: Creating a transparent display Here is the code for createTransparentUnit(). When pressing the button “Set Transparent”, you should see the following screen.
Piasim Corporation Pte Ltd Revision F5
44/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Illustration 43: Code for create transparent unit
Illustration 42: Demo4 with a transparent display
4.8 Getting Annikken Andee Status At times, you may be interested to know Annikken Andee's information. E.g. Annikken Andee's bluetooth name. To get such status information, your Arduino code needs to use the following functions: •
bool AndeeClass::sendCommand(char* command, char* reply);
To illustrate the use of these functions, check out DEMO5_GetConnectedMACID. Annikken Andee keeps track of the unique bluetooth mac id a connected Android device. This mac id can be obtained with the request command “GET CONNECTED MAC_ID”. You need to open up Arduino's serial port monitor to see the error message when no Android is connected.
Piasim Corporation Pte Ltd Revision F5
45/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 44: Icon to click to open Arduino's serial port monitor
Illustration 45: Snippet of sendCommand function Here is a table of commands you can use: Command String
Description
Reply
“GET CONNECTED MAC_ID”
Get the unique bluetooth
E.g. 00:00:11:11:ed:da -54
mac id of connected Android append with RSSI data. “GET BTADDR”
Get the unique bluetooth
E.g. “00:00:11:11:ed:da”
mac id of Annikken Andee “GET BT NAME”
Get Annikken Andee's
E.g. “Andee 1001”
Bluetooth name “SET BT NAME ” Set Annikken Andee's
No reply to this request.
Bluetooth name to
Note that you still need to
name>
supply a rcvdBuffer for the function.
The replies, often text messages, will be saved into the buffer you supplied. In this case example, cmdReply[64]. If successful, sendCommand() function returns a true, else it returns a false, with the error message copied inside cmdReply, or the buffer you supply into the function. Piasim Corporation Pte Ltd Revision F5
46/68 July 2, 2013
Annikken Andee •
Piasim Corporation Pte Ltd Revision F5
Bluetooth Shield For Arduino By Annikken
47/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 47: If no Android is connected, Illustration 46: Screenshot of
serial port shows this
Demo5_GetConnectedMACID
4.9 Disconnect and Connection Status You can use disconnect() and isConnected() functions provided by the AndeeClass to better manage connection. The disconnect() function allows Arduino to instruct Annikken Andee to disconnect its existing bluetooth connection with Android. Demo6_DisconnectConnect will show you this. The program is simple as shown below.
Piasim Corporation Pte Ltd Revision F5
48/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Illustration 48: Demo6 Source Code Arduino program will instruct Annikken Andee to display a “DISCONNECT” button if Andee.isConnected() returns true. And if the button is being touched by a user, Arduino instructs Annikken Andee to disconnect from the Android device by calling Andee.disconnect(). Once disconnected, you should see the screen as shown below.
Piasim Corporation Pte Ltd Revision F5
49/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 49: Screen observed after calling Andee.disconnect()
4.10
Read and Write SD Card Annikken Andee provides an SD card slot to provide a non-volatile storage option
for Arduino users. For Arduino coder, you need to complicated yourself with setting up of SPI for the sdcard. Data to be written and sent is also being done via the following API calls from Andee library: •
int readLineFromSD(char* filename, int offset, char* replyBuffer, int maxLen, char* delimitString)
•
int readBytesFromSD(char* filename, int offset, char* replyBuffer, int numOfBytesToRead)
•
int appendSD(char* filename, char* contents, char* errorMsgBuffer)
Piasim Corporation Pte Ltd Revision F5
50/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
•
int writeSD(char* filename, char* contents, int offset, char* errorMsgBuffer)
Note that filenames should not contain the character ';' and ','. All these functions returns an integer specifying the current file location. If a '-1' is returned, it means an exception has occurred while performing the functions. The detailed error message will be saved in errorMsgBuffer[] - which is a character buffer you have to defined it in Arduino. Demo7_SDFunctions demonstrate the above functions. To run the above demo, you need to have a sdcard. Create a text file, name it as “demo7.txt” and load it with the contents as shown.
Illustration 50: Contents of demo7.txt
Next upload Demo7_SDFunctions to an Arduino can run it. Connect with an Android device and you should see the following screen.
Piasim Corporation Pte Ltd Revision F5
51/68 July 2, 2013
Annikken Andee •
Piasim Corporation Pte Ltd Revision F5
Bluetooth Shield For Arduino By Annikken
52/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
To show more controls
Illustration 51: Screenshot of
Illustration 52: Revealing more buttons
Demo7_SDFunctions
hidden on right
Notice for 2nd and 3rd line of display, there are small white right-pointing arrows on the right side of display. This means that there are more displays on the right and can be accessed by dragging your finger across the row from right to left.
4.10.1
Reading A Line From SD
Reading a line from SD card is accomplished by the function: •
int readLineFromSD(char* filename, int offset, char* replyBuffer, int maxLen, char* delimitString)
In Demo7_SDFunctions, this function is implemented via a button press with title “Read Line”. Here is the code.
Piasim Corporation Pte Ltd Revision F5
53/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Illustration 53: Variables defined globally for use in Demo7
Piasim Corporation Pte Ltd Revision F5
Illustration 54: Initialization of button
54/68 July 2, 2013
Annikken Andee •
Piasim Corporation Pte Ltd Revision F5
Bluetooth Shield For Arduino By Annikken
55/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 55: Code segment from loop() The readLineFromSD(...) functions returns an int indicating the current file position. For example if 5 bytes were to be read, the value returned would be 5. Therefore, in this example, if you were to read the next line beginning from where you left off, you would pass in a value of 5 as the offset value. Try pressing the “Read Line” button once.
Illustration 56: DATA_OUT display showing the read contents and returned file pointer position
Current file pointer position
as variable offset
File pointer
0
1
2
3
4
Contents
L
i
n
e
1
5
6
7
8
9
10
11
12
13
14
15
t
e
s
t
i
n
g
\n
L
i
Delimiter not included in returned sd contents Continue pressing the “Read Line” button will show you the contents of demo7.txt line-by-line delimited by “\n”. Once end of file is reached, you should see this.
Piasim Corporation Pte Ltd Revision F5
56/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 57: Display showing end of file Remember that a returned value of -1 indicated an exception, and the exception description is placed in your received contents buffer, in this case cmdReply[64].
4.10.2
Read A Number Of Bytes From SD
Here is the function prototype: •
int readBytesFromSD(char* filename, int offset, char* replyBuffer, int numOfBytesToRead)
In Demo7_SDFunctions, there are two buttons to to be used with this function. “Set Offset” and “Set Number Bytes”.
Illustration 58: Set Offset and Set Number Bytes Variable offset will shift the file position pointer File pointer
0
1
2
3
4
Contents
L
i
n
e
1
5
6
7
8
9
10
11
12
13
14
15
t
e
s
t
i
n
g
\n
L
i
NumOfBytesToRead specifies number of bytes to read from file position Here is the code segment for Set Offset button and Set Number Bytes button.
Piasim Corporation Pte Ltd Revision F5
57/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
Illustration 59: Code segment for Set Offset and Set Number Bytes button
Illustration 60: What the Read Bytes button do For example, set offset to 1 and numBytesToRead to 5 will show you the following result.
4.10.3
Illustration 61: readContents
Illustration 62: readContents
display after setting offset and
display after pressing Read Bytes
numBytesToRead
button
Writing Data to SD
You have two functions to use to write data to sdcard. Piasim Corporation Pte Ltd Revision F5
58/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
•
int appendSD(char* filename, char* contents, char* errorMsgBuffer)
•
int writeSD(char* filename, char* contents, int offset, char* errorMsgBuffer)
The appendSD(...) function write contents starting from the end of file specified by filename. The writeSD(...) writes contents starting from file position specified by offset.
Illustration 63: Code segment of appendSD and writeSD For writeSD, the offset is set using the “Set Offset” button also. The “WRITE SD” button is hidden on the right side of “APPEND SD” function. Here is the list of possible errors you may received during any SD read/write functions: Error Message
Description
NO SDCARD
SD card not insert or not properly inserted.
FILE NOT FOUND
Cannot find the specified file.
OPENING FILE ERROR
There was an error opening the file.
READ FILE ERROR
Error reading file, most probably corrupted.
EOF REACHED
End of file.
UNABLE TO CLOSE FILE
An error occurred while trying to close the file after reading
Piasim Corporation Pte Ltd Revision F5
59/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
or writing.
4.11
Sending SMS and Creating Notifications This section shows you how to instruct Annikken Andee to use the connected
Android device, to send sms to a recipient or to create a notification. You need to create AndeeHelper instances and set the proper messages as shown.
Piasim Corporation Pte Ltd Revision F5
60/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Illustration 64: Variables to declare
Piasim Corporation Pte Ltd Revision F5
61/68 July 2, 2013
Annikken Andee •
Bluetooth Shield For Arduino By Annikken
Illustration 65: Setup function
Piasim Corporation Pte Ltd Revision F5
62/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
Illustration 66: loop function
Illustration 67: Screenshot of Demo10_SMSandNotification
The Arduino's loop function basically handles the displaying of buttons on Android screen using the update() function and performing the sms.send() and notice.notify() function.
Piasim Corporation Pte Ltd Revision F5
63/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
5 String Limits There is a maximum limit you the fields in Annikken Andee can take. Display Type
Settable Fields
Max Characters (Bytes)
DATA_OUT
Title
64
Data
64
Unit
64
BUTTON_IN
Title
64
KEYBOARD_IN
Title
64
User Input
64
HintText
64
SD ReadWrite
Read and write contents
64 in one function call
SMS_SENDER
Recipient
64
Message
64
Title
64
Message
64
Ticker
64
NOTIFICATION
Piasim Corporation Pte Ltd Revision F5
64/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
6 Connector SV2 Functionality Annikken Andee has a 8-pin through-hole port labelled SV2 as shown.
SV2 Pin Number
Function
1
Reserved.
2
Reserved.
3
Digital HIGH when LD2 = RED.
4
Digital HIGH when LD2 = GREEN.
5
Reserved.
6
Reserved.
7
Reserved.
8
Reserved.
Users can wire these pins to their external systems for detection purposes. For example, you may need to put Annikken Andee into an enclosure. However, doing that will obscure the LD2 from view. Users may still want to be notified of connection status via the LD2 led. Instead of soldering your own wire to the surface mounted LD2, you can instead use pin 3 and pin 4 of SV2 to connect it to your external LED.
7 Upgrading Firmware Annikken Andee's firmware can be upgraded using a sdcard. Firmware releases can Piasim Corporation Pte Ltd Revision F5
65/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
be obtained from Annikken Andee's website, www.annikken.com/annikkenandee/AndeeLibrary.zip. The correct firmware to use with a library build is included in the zip file. •
Copy the .hex file to a SDCARD and rename it to image.hex.
Rename file to image.hex
•
Insert the SDCARD (with firmware file) into Annikken Andee's SDCARD slot.
•
Apply power to Annikken Andee. Annikken Andee's LD2 should be showing a blinking green light. This shows that it is in normal mode.
•
Put Annikken Andee into bootloading mode with the following steps: •
Press and hold BTN2
•
While still holding BTN2, press and release the RESET button.
2
1
Piasim Corporation Pte Ltd Revision F5
(2) Press and RELEASE reset button.
(1) Press and HOLD reset button.
66/68 July 2, 2013
Annikken Andee
Bluetooth Shield For Arduino By Annikken
•
•
LD1 will flash RED and LD2 will flash GREEN alternately, indicating firmware programming is in progress. You can release BTN2 once you observed this.
•
Annikken Andee will put itself back to normal mode once firmware programming is done – indicated by LD2 blinking green light.
•
Note that SV2 will not be working under bootloading mode.
Piasim Corporation Pte Ltd Revision F5
67/68 July 2, 2013
Bluetooth Shield For Arduino
Annikken Andee
By Annikken
•
8 Annikken Andee Specifications 8.1 Dimensions TOP VIEW
SIDE VIEW – Dimensions in mm
Enquiries:
[email protected]
Tech Support: [email protected] Website: www.annikken.com
Piasim Corporation Pte Ltd Revision F5
68/68 July 2, 2013