PARTFOUR
Parts 1-3 of the tutorial were designed to take you step-by-stepthroughdesigning the app. If you are wondering what you missed, here is asummary:
This is whatyou'll find in partone:
This is what you will find in part two:
This is what you will find in part three:
Make sure that you have selected the Bluetooth permissions as perthe following:
Make sure that BLUETOOTH and BLUETOOTH_ADMIN are selected (as perthe picture below). Then press the OK button.
Then copy and paste the following sketch into the processing/androidIDE:
Android/ProcessingSketch 9: Bluetooth App2
Here is a picture of the components used in this sketch:
ArduinoSketch 3: Bluetooth RGB Colour Changer (with OFF option)
Please note that this Arduino code/project will work with SeeedStudio's Bluetooth Shield. You may need to modify the Arduino Code (lines 95-107) to coincide withyour own bluetooth shield. I got the code snippet within the mysetupBlueToothConnection() method from some example code from Steve Chang which was found on SeeedStudio's Bluetooth Shield Wiki page. Here issome other useful information in relation to setting up this BluetoothShield that could be of help in your project (here).
Much of the code used within the Android/Processing sketch was madepossible through constant reference to these sites:
The Arduino and Processing Forums are always a great place to get helpin a short amount of time.
Connecting to Arduino using Processing and bluetooth (HC-05, HC06) I extended the Dimmer Processing code with a red, green and blue gradient strip. In the example was already the gradient from black to white. The idea was to dim a LED and also to control a RGB led from the GUI.
TheVideo
This is part 4 of my tutorial ondesigning an Android PhoneBluetooth App using the Android/Processing language. The App sendsinformation to an Arduino via Bluetooth after pressing a button on thephone. The RGB LED attached to the Arduino Uno (or compatible board)will change colour depending on the button being pressed on the phone.TheArduino gains Bluetooth capabilities through the Seeedstudio Bluetoothshield (which can be found here).
This is part 4 of my tutorial ondesigning an Android PhoneBluetooth App using the Android/Processing language. The App sendsinformation to an Arduino via Bluetooth after pressing a button on thephone. The RGB LED attached to the Arduino Uno (or compatible board)will change colour depending on the button being pressed on the phone.TheArduino gains Bluetooth capabilities through the Seeedstudio Bluetoothshield (which can be found here).
Parts 1-3 of the tutorial were designed to take you step-by-stepthroughdesigning the app. If you are wondering what you missed, here is asummary:
This is whatyou'll find in partone:
- Downloading and setting up the Android SDK
- Downloading the Processing IDE
- Setting up and preparing the Android device
- Running through a couple of Processing/Android sketches on anAndoid phone.
This is what you will find in part two:
- Introducing Toasts (display messages)
- Looking out for BluetoothDevices using BroadcastReceivers
- Getting useful information from a discovered Bluetooth device
- Connecting to a Bluetooth Device
- An Arduino Bluetooth Sketch that can be used in this tutorial
This is what you will find in part three:
- InputStreams and OutputStreams
- Error Logs using logcat
- Testing the InputStreams and OutputStreams
- Using the APWidgets library to create buttons
- Adding Buttons to the BlueTooth Project
In Part 4, we simplify and strip downthe App so that it will onlysendsa specific String to the Arduino via Bluetooth. The String sentto the Arduino depends on the Buttonbeing pressed. The code has been cleaned up and has many comments tohelp you understand what is going on. You should be able to run thissketch without having to go back through parts one, two or three of thetutorial. This fourth part of the tutorial was designed for thosepeople whowant the final end product, and are happy to work it out forthemselves. Ihope this serves you well.
I will therefore assume that you have already setup your phone and havedownloaded all the neccesary drivers, libraries, SDKs and IDEs. If not,then here are a few quick links:
I will therefore assume that you have already setup your phone and havedownloaded all the neccesary drivers, libraries, SDKs and IDEs. If not,then here are a few quick links:
- APWidgets library
Make sure that you have selected the Bluetooth permissions as perthe following:
- Android > Sketchpermissions (as per the picturebelow)
Make sure that BLUETOOTH and BLUETOOTH_ADMIN are selected (as perthe picture below). Then press the OK button.
Then copy and paste the following sketch into the processing/androidIDE:
Android/ProcessingSketch 9: Bluetooth App2
Here is a picture of the components used in this sketch:
- Arduino (Freetronics ELEVEN) with the
- Bluetooth Shield in place, and a
- Grove RGB chainable LED
- attached using Grove Universal 4pin cable.
Please take notice of the Jumper pinplacement on the Bluetooth Shield. This ensures communication betweenthe Arduino and Bluetooth Shield, and is reflected in the Arduino codefurther down this page. The Arduino transmits information to theBluetooth Shield on Digital pin 7, and therefore the Bluetooth Shield receivesinformation from the Arduino on Digital pin 7. On the other hand, theBluetooth shield transmits and the Arduino receives information onDigital pin 6 (see picture below). This serial communicationbetween the Arduino and the Bluetooth Shield occurs through the SoftwareSeriallibrary. This is different from the Serial libraryused in some of my other tutorials (often to display information in theSerial Monitor). The Arduino UNO's Serial pins are 0 (RX) and 1 (TX).It is worth looking at the Arduino Serialpage if you happen to have an Arduino Leonardo, because there are somedifferences that you should take into consideration when running thissketch.
Make sure that your Arduino has the following code installed andrunning BEFORE you launch the Android/Processing Sketch on your AndroidDevice. If you don't do it in this order, yourAndroid phone will not discover the Bluetooth Device attached to theArduino, and you will waste a lot of time. Make sure that the Bluetoothshield is flashing it's red/green LEDs. Once you see this alternatingred/green LED display, launch theAndroid/Processing sketch on the Android device. When you see thechainable RGB LED turnfrom white to green, you know you have a successful connection. Youmay then press the GUI buttons on the Android phone to change thecolour of the LED to either Red, Green, Blue or Off.
ArduinoSketch 3: Bluetooth RGB Colour Changer (with OFF option)
Please note that this Arduino code/project will work with SeeedStudio's Bluetooth Shield. You may need to modify the Arduino Code (lines 95-107) to coincide withyour own bluetooth shield. I got the code snippet within the mysetupBlueToothConnection() method from some example code from Steve Chang which was found on SeeedStudio's Bluetooth Shield Wiki page. Here issome other useful information in relation to setting up this BluetoothShield that could be of help in your project (here).
Much of the code used within the Android/Processing sketch was madepossible through constant reference to these sites:
- Mobile App Development
The Arduino and Processing Forums are always a great place to get helpin a short amount of time.