tag:blogger.com,1999:blog-50852437809039031712024-03-27T16:52:59.943-07:00Arduinofy - Arduino Projectsarduino projects with bluetooth connections. flying machines such as the quadcopter. ground based projects and many many more to come!Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-5085243780903903171.post-85462101135683207162013-10-25T19:10:00.001-07:002014-11-28T18:56:14.979-08:00Tutorial: Programming the HC-05 - AT mode - with ArduinoTutorial: Programming the HC-05 AT commands - done easily with Arduino<br />
<br />
<br />
<h3>
What This Tutorial Covers</h3>
<div>
In this tutorial I will show you how to wire the HC-05 to Arduino UNO and get into the AT mode all done with CODE. This way there is no need for pulling pins high and low by hand and it is quick and convenient and easy. Also, I will go through the process of changing the bound rate, the name and demonstrate a few other useful AT commands. </div>
<div>
<br /></div>
<div>
*Please note that this tutorial is for the HC-05.</div>
<div>
<br /></div>
<div>
<a name='more'></a><br /></div>
<div>
<h3>
What You Need</h3>
</div>
<div>
For this tutorial you will need a few things, here is the list:</div>
<div>
<br /></div>
<div>
- Arduino UNO, but any equivalent should do just fine</div>
<div>
- HC-05 with a breakout board, unless you know what your doing. </div>
<div>
- a breadboard and some wires</div>
<div>
<br /></div>
<div>
<h3>
Set Up</h3>
</div>
<div>
Here are some pictures of the Set Up. Included is also a diagram of the connections made with Fritzing. (Thanks Fritzing!)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIm8YqqOm07JjhSSyh2p6twQN7Iqg0DxbJXvVbEq50-INv_HKB_wWCE3bPvIl6nFPXEJ3a78D7fUkoRhWFBtaC3fRPghntzfl1dxMtm5Mp6ZlkGWIeOqLvbtOOVztM2kG0hHHdmCPQpBM/s1600/photo+1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIm8YqqOm07JjhSSyh2p6twQN7Iqg0DxbJXvVbEq50-INv_HKB_wWCE3bPvIl6nFPXEJ3a78D7fUkoRhWFBtaC3fRPghntzfl1dxMtm5Mp6ZlkGWIeOqLvbtOOVztM2kG0hHHdmCPQpBM/s320/photo+1.JPG" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicONw7mPalTu8k6XtNX4N1LC-IMcISlaS8gQpXBnyvFAeXUGhXVCZube4MGYsrJl8nVEzn67TUKwzhtBM8cgkfPrjlepZPbztP9VjTpTiQ6bWnqVoIN03aEmx5ZY0PBiZvoxdX-iFyst0/s1600/photo+3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicONw7mPalTu8k6XtNX4N1LC-IMcISlaS8gQpXBnyvFAeXUGhXVCZube4MGYsrJl8nVEzn67TUKwzhtBM8cgkfPrjlepZPbztP9VjTpTiQ6bWnqVoIN03aEmx5ZY0PBiZvoxdX-iFyst0/s320/photo+3.JPG" width="240" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWRE8bKkb5dBhKjQfzpdPGD96pCTVeRGw7R5LuMMYDGtT9T5e6e5cvtZWBn7ioTBW8ymtzfpu4O8zGGCEr3u8rvbHwFAQ8tyKHqrfBk8c-XHiHd9RTd1bgg8up9kcitK1lgNzqs_tzdqk/s1600/sketch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWRE8bKkb5dBhKjQfzpdPGD96pCTVeRGw7R5LuMMYDGtT9T5e6e5cvtZWBn7ioTBW8ymtzfpu4O8zGGCEr3u8rvbHwFAQ8tyKHqrfBk8c-XHiHd9RTd1bgg8up9kcitK1lgNzqs_tzdqk/s320/sketch.png" width="294" /></a></div>
<br />
<br /></div>
<div>
<br /></div>
<div>
<u>A quick run through the connections verbally as they are very simple and easy.</u></div>
<div>
<br /></div>
<div>
- Arduino pin A1 is connected to the TX pin of the BT.</div>
<div>
- Arduino pin A0 is connected to the RX pin of the BT</div>
<div>
- Arduino pin GND is connected to GND pin of the BT.</div>
<div>
- *** Arduino pin 7 is connected to 5V pin of the BT. ***</div>
<div>
- Arduino pin 8 is connected to the KEY pin of the BT. </div>
<div>
<br /></div>
<div>
Simple, no? A few wires and we are set to upload the code! </div>
<div>
<br /></div>
<div>
Now, before I slap the code here I want to take the time to explain why we are connecting the 5V of the Bluetooth to pin 7 of the Arduino. This is very simple, in order to get into the AT mode we have to follow a few simple steps and connecting the 5V pin to a variable pin of the Arduino allows us to bring it High and Low as we please. In order to get into the AT mode we have to first pull the 5V and the KEY pins to Low. This is important and often skipped by all the other tutorials and thus it introduces problems for the people trying to follow in the long run. Once they are Low we have to pull the KEY pin High, after a small delay and only then, we pull the 5V pin to HIGH. This results in the BT going into the AT mode and this can be confirmed by sending a serial command "AT" via serial and/or by looking at the HC-05 indication LED; it should be blinking at one second intervals.</div>
<div>
<h3>
The Code</h3>
</div>
<div>
Now finally for the code. I commented it thoroughly and thus I will not explain much of it here in text. I want people to find it easy to program the HC-05 this I'm posting the code as a whole. </div>
<div>
<br />
Simply copy this code and upload it to the Arduino. </div>
<div>
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;">/*
This code is in the public domain.
written by Damian Glinojecki
*/
#include <softwareserial .h="">
#define bt_power 7
#define bt_key_power 8
#define indication_led 13
SoftwareSerial BT(A0, A1); // RX | TX
void setup()
{
// set the pins to OUTPUT
pinMode(bt_power, OUTPUT);
pinMode(bt_key_power, OUTPUT);
pinMode(indication_led, OUTPUT);
// set the pins to LOW
digitalWrite(bt_power, LOW);
digitalWrite(bt_key_power, LOW);
digitalWrite(indication_led, LOW);
/************************************************
Setting the pins to low is important because
in order for us to get into AT mode the key pin
has to be set to Ground FIRST. Many tutorials out
there fail to mention this important fact and
therefore many people have problems with getting
into the AT mode of the HC-05
************************************************/
// make sure the key has been LOW for a bit
delay(100);
// set the key pin to High
digitalWrite(bt_key_power, HIGH);
// small delay
delay(100);
// now power on the BT
digitalWrite(bt_power, HIGH);
// start our serial so we can send and recieve
// information from the BT module
Serial.begin(9600);
// initiate the BT serial at 38400 which is the default
// speed at which the BT AT mode operates at
BT.begin(38400);
// self explanatory
Serial.write("For a list of commands, visit: \n");
Serial.write("Type AT commands \n\n");
// process complete turn on led 13
digitalWrite(indication_led, HIGH);
// Send an "AT" command to the AT (without quotes)
// if response is OK, then we are connected
// and ready to program the BT module
}
void loop()
{
// listen for a response from the HC-05 and write it to the serial monitor
if (BT.available())
Serial.write(BT.read());
// listen for user input and send it to the HC-05
if (Serial.available())
BT.write(Serial.read());
}
</softwareserial></code></pre>
</div>
<br />
<br />
<h3>
Now to the Programming of the HC-05</h3>
<div>
In your Arduino sketch you have a very useful tool called the Serial Monitor. Click Tools -> Serial Monitor.</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgILYhUqSr2pt9dNc0wYy2NoqxYdpgelaEdpkulSFCua3hiVYNB1mrVIqPRJTM7dB1C9BgfZkyF0pX-eeDPot4TmHd6S2lDIzj_u3kKY4CVciHrcN__G_wwiHmGibtjhw1A00f9YReb_nI/s1600/tools-serial.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgILYhUqSr2pt9dNc0wYy2NoqxYdpgelaEdpkulSFCua3hiVYNB1mrVIqPRJTM7dB1C9BgfZkyF0pX-eeDPot4TmHd6S2lDIzj_u3kKY4CVciHrcN__G_wwiHmGibtjhw1A00f9YReb_nI/s320/tools-serial.png" width="320" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
Before we do anything, lets make sure our Serial Monitor settings are correctly set. This is IMPORTANT! </div>
<div>
<br /></div>
<div>
First off make sure that the boxes outlined in red match yours. </div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjQma7X-CHko8HG3OXxTUfCpcujthRHo2WhxmG-kNL2OwwtThhQmdNkA60N5xiSP6_1NiNKmNQe-8dC2PANXpZg0daZVq5yVN8PWhuzRz3yHai-fcbI7qN-_pA45XL7-Y48Movg-148ic/s1600/matching+bound+ratge.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="164" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjQma7X-CHko8HG3OXxTUfCpcujthRHo2WhxmG-kNL2OwwtThhQmdNkA60N5xiSP6_1NiNKmNQe-8dC2PANXpZg0daZVq5yVN8PWhuzRz3yHai-fcbI7qN-_pA45XL7-Y48Movg-148ic/s320/matching+bound+ratge.png" width="320" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
***Please note that I am using version 1.0.1 of the Arduino software but it should be the same for all of them. </div>
<div>
<br /></div>
<div>
It is important that your bound rate is set at 9600 or else we wont be able to talk the same "language" as the Arduino is set to understand. Also, make sure that the line editing is set to "Both NL & CR". This is another important detail that many tutorials miss. (I was ripping out my hair not understanding why I cant communicate with the HC-05)</div>
<div>
<br /></div>
<div>
Now for a test type "AT" without the quotes and press enter. You should get a response "OK" as follows:</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS2Q1UM8dvyXNCZzrbbaY_58shN9dcKSxcZRyJIM-TNqkGliXBygO3l-UOvSX3Ono2m4VOR30lP2hEqFEOMu_khLLwP6dfEShcU8snU3LJo4KyMN2KPWQ09CJo5QmJjHTqozY48M0ZE2Y/s1600/ok+response.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="169" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS2Q1UM8dvyXNCZzrbbaY_58shN9dcKSxcZRyJIM-TNqkGliXBygO3l-UOvSX3Ono2m4VOR30lP2hEqFEOMu_khLLwP6dfEShcU8snU3LJo4KyMN2KPWQ09CJo5QmJjHTqozY48M0ZE2Y/s320/ok+response.png" width="320" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
This is GOOD! This means that we are in AT mode and we are talking with the HC-05 and it hears us! Now we can change some of the settings. You can find the complete list of commands on the bottom of this page.</div>
<div>
<br /></div>
<div>
For starters I will change the name of the Bluetooth. To do this all I need to do is type in the following command: "AT+NAME=QMBTv1" (again, without the quotes) You can substitute "QMBTv1" for anything you like. This is the name I am giving my BT though. Now to confirm that the name was changes lets send another command "AT+NAME?" The HC-05 should respond with the name that we just assigned.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRiY3grN7S5cpOLTweZ9Dc4diz_-ey65LUadMvueJhJMchfv0OO4eKN88lQ0olPWODU_zbhyphenhyphen25MG4QDc4EAsiP4hltoRFK6U-fNz13VAoxFcWWzjDSsCF50TBZjlbcDGqj4VJ1toS9OLk/s1600/name+change.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRiY3grN7S5cpOLTweZ9Dc4diz_-ey65LUadMvueJhJMchfv0OO4eKN88lQ0olPWODU_zbhyphenhyphen25MG4QDc4EAsiP4hltoRFK6U-fNz13VAoxFcWWzjDSsCF50TBZjlbcDGqj4VJ1toS9OLk/s1600/name+change.png" /></a></div>
<br /></div>
<div>
<br /></div>
<div>
Side Note: Some of you might wonder what does the QMBTv1 stand for. As I mentioned in an earlier post, I want to build a quadcopter. This BT module is going to be the main means of communication with the quad. :) </div>
<div>
<br /></div>
<div>
Now lets change the bound rate to 115200,1,0. This is just as simple. Send this command "AT+UART=115200,1,0" and then "AT+UART?" to confirm that it was changed successfully. </div>
<div>
<br /></div>
<div>
<br /></div>
<div>
If you followed all the steps and got the name and the bound rate to change, then you have done everything right. Congratulations you changed the HC-05 settings! </div>
<div>
<br /></div>
<div>
<h3>
Commands for the HC-05</h3>
</div>
<div>
You can find all of them here. Courtesy of linotux, Thanks for listing them! </div>
<div>
<a href="http://www.linotux.ch/arduino/HC-0305_serial_module_AT_commamd_set_201104_revised.pdf" target="_blank">CLICK HERE</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<br />Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com35tag:blogger.com,1999:blog-5085243780903903171.post-70800921664659538512013-05-24T19:24:00.003-07:002013-10-17T14:37:00.614-07:00Tuorial: Attiny84 / 85 and Bluetooth Tuorial: Attiny84 / 85 and Bluetooth<br />
<br />
<h3>
What This Tutorial Covers</h3>
This tutorial is an expansion / continuation of the previous <a href="http://arduinofy.blogspot.com/2012/12/arduino-bluetooth-seeeduino.html">Bluetooth tutorial</a>. In other words I will assume you are familiar with arduino and simple Bluetooth concepts. Also, I assume you know how to program an Attiny via arduino as an ISP or via a standalone programmer. I'm not going to be going over the code in detail unless it is something I didn't cover in the previous tutorial.<br />
<br />
In this tutorial we will learn how to connect a Bluetooth module to an Attiny and how to make them talk! Exciting isint it? This will allow you to control a shrinkified arduino project wirelessly via Bluetooth from another arduino bluetooth enabled device, via a computer or even via a phone. In this tutorial I will cover how to control your Bluetooth enabled Attiny via a computer, but soon I will be doing a tutorial on how to accomplish this via an iPhone.<br />
<br />
<a name='more'></a><br />
<h3>
What You Need</h3>
For this tutorial you will need a few things, here is the list:<br />
- Attiny84 or 85<br />
- Bluetooth module<br />
- a bread board and some wires<br />
<br />
<h3>
Identify your Bluetooth</h3>
The first thing you have to do is check your hardware and find out which pin means what. This is not difficult and either the manufacturer or the retailer which you have purchased the module from should provide you with a schematic. Here is the module I'm using the HC-05 Bluetooth Transceiver:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmba-_nMn-n_BGvl8xQovekeV8OldoWJaT8bsVzjShyphenhyphencTIlFhhaTM3NPq_fWBZo4YgTkrjWRSFvAHOo4xs5kbOVfk6Y4uU9btmE4grRcV6ImsBqZuBJKfsbzfqflN8cDQU5SGiG_Oqv4/s1600/module.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="" border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYmba-_nMn-n_BGvl8xQovekeV8OldoWJaT8bsVzjShyphenhyphencTIlFhhaTM3NPq_fWBZo4YgTkrjWRSFvAHOo4xs5kbOVfk6Y4uU9btmE4grRcV6ImsBqZuBJKfsbzfqflN8cDQU5SGiG_Oqv4/s200/module.JPG" title="HC-05 module" width="150" /></a></div>
<br />
You can get it from <a href="http://www.ebay.com/itm/HC-05-Bluetooth-Transceiver-Host-Slave-Master-Module-Wireless-Serial-6pin-/321120060216">here</a> from NYPLATFORM on ebay. ($11)<br />
<br />
<h3>
Set Up</h3>
Here are two pictures of the setup:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmC274VjLy2AH40dXC04uppCelBVnF-tbLTBXhqqQQetR02ts-tnCkZKstUOVOFDy8TMmi24Ymey9QtK0VRQrRS2UkfiJjW6FCw62HLF1QHMOIqiKy7aNqVC47Cjb7bhyphenhyphenrfxuozfbGPaw/s1600/setup+side.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmC274VjLy2AH40dXC04uppCelBVnF-tbLTBXhqqQQetR02ts-tnCkZKstUOVOFDy8TMmi24Ymey9QtK0VRQrRS2UkfiJjW6FCw62HLF1QHMOIqiKy7aNqVC47Cjb7bhyphenhyphenrfxuozfbGPaw/s320/setup+side.JPG" width="240" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8qB51NIsQmzZyZRW2RnYrDlmoAI2WtkGvj1Kr70spm7er23_4vD6H4IqTbtJnDs2k71VYtckP44Xf9fa7SE8lB2PjlUNixKApxt2AfbQLHh_8uTB9Pk5BlYoyeefayn1HSk8W5AmjO8I/s1600/setup+top.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8qB51NIsQmzZyZRW2RnYrDlmoAI2WtkGvj1Kr70spm7er23_4vD6H4IqTbtJnDs2k71VYtckP44Xf9fa7SE8lB2PjlUNixKApxt2AfbQLHh_8uTB9Pk5BlYoyeefayn1HSk8W5AmjO8I/s320/setup+top.JPG" width="240" /></a></div>
<br />
<br />
I know its not clear so I will run through it in more detail in text. The Bluetooth module I'am using has 6 pins. I'm using only 4 of them. The TX, RX, 5V, and GROUND. This is all you need to run the Bluetooth and make it work. Some other features are excluded due to this but I will leave it up to you to discover them.<br />
<br />
OK, first the simple stuff that you should be familiar with already. In the code notice that I initiate "int led = 4" pin 4 as "led", then I set it up for output and turn it on. We will be using this led to verify connection with our computer via Putty. In other words we will control the led via Bluetooth and make it turn on and off. As mentioned before this led is connected to Attiny pin 4, in my setup I'm using a resistor (should be 330ohm) between the Attiny and the led as I do not want to fry the led.<br />
<br />
Now for connecting the Bluetooth with the Attiny. This is simpler that you would have ever thought, all you need is two wires or jumpers that connect the RX pin with pin 1 on the Attiny and connect the TX pn with pin 2 on the Attiny. Now make sure everything has 5V connected to it, the Bluetooth module and the Attiny.<br />
<br />
NOTE: some Bluetooth modules could be using a different Voltage!!!<br />
<br />
<h3>
Programming</h3>
Hold on there! Before we start programming there is one thing you have to make sure of. In order for this to work properly as I found out you have to burn the 8mhz boot loader for the Attiny! Google is your friend on this one.<br />
<br />
Now, since I have gone through most of the code in my previous tutorial I will not be detailed on this. The only part that I will make remarks about is the new code that controls the led.<br />
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;">/*
This code will run the bluetooth as slave
pressing 1 turns on led 4
pressing 0 turns off led 4
*/
#include <softwareserial .h=""> //Software Serial Port
#define RxD 1
#define TxD 2
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
int led = 4;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void loop()
{
char recvChar;
while(1){
//check if there's any data sent from the remote bluetooth shield
if(blueToothSerial.available()){
recvChar = blueToothSerial.read();
if(recvChar == '1')
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=HC-05\r\n"); //set the bluetooth name as "HC-05"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
//blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
blueToothSerial.print("bluetooth connected!\n");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
</softwareserial></code></pre>
<br />
The only new code that you should see is the following:<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;">void loop()
{
char recvChar;
while(1){
//check if there's any data sent from the remote bluetooth shield
if(blueToothSerial.available()){
recvChar = blueToothSerial.read();
if(recvChar == '1')
digitalWrite(led,HIGH);
else
digitalWrite(led,LOW);
}
}
}
</code></pre>
<br />
This is our loop. We do this 8mhz per second. Lets take a look at it and what it does. It is not very complicated and just looking at it you should be able to figure it out. Skipping to the first if statement, we are checking if there is any data that has been transmitted from the master device. Then, if there was we write it into a char. Now the char should be holding whatever value you have passed to it. In this example I choose "1" and any. "1" will turn on the led and any other will turn it off. Now in the second if statement we are comparing the char to "1" and if they match then we turn the led on. If they don't match we turn it off. So, as long as the connection is working, you should be able to turn off the led that is turned on at initialization.<br />
<br />
<h3>
Getting it All Connected</h3>
Now, power everything on. If you are using the same module as I am, you should see a red blinking led. This is good, your Bluetooth device is ready for pairing. Open up your computers Bluetooth software, find HC-05 and connect to it. This device uses a 4 digit pairing code. The default is "1234", type it in and sync them together. Open up device manager in control panel note the COM port that the Bluetooth is using, if there is more than one you will have to try them all if your unlucky. Open up putty select COM connection type in the COM# and leave the bound rate at 9600, this is what we used in the code and this is what worked best for this device.<br />
If putty opens up a new session (black window) with the text displaying "Bluetooth Connected" you are in business. Press any key and the led should turn off, press "1" and the led should turn on. Congratulations!! You have established a bluetooth connection using an Attiny.<br />
<br />
Comments and Questions welcome!<br />
Thanks for reading.Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com21tag:blogger.com,1999:blog-5085243780903903171.post-6018449932459740812013-04-24T15:19:00.000-07:002013-04-24T15:25:56.924-07:00Time Zapper, awesome! Hi everyone! My new app has just been released and is up for FREE in the app store! Check it out<br />
<br />
Available for the iPhone and for the iPad!<br />
<br />
<br />
<ul>
<li><a href="https://itunes.apple.com/us/app/time-zapper/id630205919?ls=1&mt=8"><b><span style="background-color: #444444; color: white;">Click to Download for iPhone or iPad</span></b></a></li>
</ul>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<img alt="" border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_rpuYvY1OZyg06JQR2yEoeBBnvw6DgIniBRWSSkieK-q2bdF8nVB-y1N0PsHc-QGs1wnhhyLVkbawDrvxjBqbAv070FceCJ54mlApiZYFIeA8eE929Nw37L-qv-TWg6ddLI52PfLXElQ/s320/IMG_1492.PNG" title="time zapper" width="213" /><span id="goog_984062899"></span><span id="goog_984062900"></span><a href="http://www.blogger.com/"></a></div>
<br />
<a name='more'></a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPjP1N9Ec6UVaI-ZNsCBPgWs1839KOmuZos_RBYXRqmk6Gbex9_LSvin_M_uTq3belb560cCXsjKaC7PjViNtmzork0zIVbPod_3XEdP_9u_wxe9Cjl5-laNeYwpN32XdPhmP3mkMVUK0/s1600/IMG_1490.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPjP1N9Ec6UVaI-ZNsCBPgWs1839KOmuZos_RBYXRqmk6Gbex9_LSvin_M_uTq3belb560cCXsjKaC7PjViNtmzork0zIVbPod_3XEdP_9u_wxe9Cjl5-laNeYwpN32XdPhmP3mkMVUK0/s320/IMG_1490.PNG" width="213" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl8n_6xPh1tI0iwBFij4CbpnrRS2XzoWztgeEmP_bc1b7NW7ojQA9jC1USGtnXIzOaIp7kSselKgGCI6pcJHeZpjqghPuvml1vvwDNSA08HzeiEuKKXyQTzsD1l3kwm2xHUV6PvnMr9zk/s1600/IMG_1485.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjl8n_6xPh1tI0iwBFij4CbpnrRS2XzoWztgeEmP_bc1b7NW7ojQA9jC1USGtnXIzOaIp7kSselKgGCI6pcJHeZpjqghPuvml1vvwDNSA08HzeiEuKKXyQTzsD1l3kwm2xHUV6PvnMr9zk/s320/IMG_1485.PNG" width="213" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhntjtwHZLU2S4y-Gnxph3VC6vF0IMoWhiwmd7NochkEOTC2vHUDvpEH72FspSmtj8jSKbCROF0NDcpHWnVtgWBjk5XN0q_UgCzrqXSXYvQrOyM-7oqc42FC8Zx-5BnXoov9kygLRs0O_o/s1600/IMG_1488.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhntjtwHZLU2S4y-Gnxph3VC6vF0IMoWhiwmd7NochkEOTC2vHUDvpEH72FspSmtj8jSKbCROF0NDcpHWnVtgWBjk5XN0q_UgCzrqXSXYvQrOyM-7oqc42FC8Zx-5BnXoov9kygLRs0O_o/s320/IMG_1488.PNG" width="213" /></a></div>
<br />
<br />
<span style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;">Like fast games? Want to test and practice your reflexes or challenge your friends to see who is quicker? Then this is perfect for you! </span><br />
<br style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;" />
<span style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;">Time Zapper is a game challenge to yourself and to your friends! Can you beat your own fastest reaction time? What about their reaction time? </span><br />
<br style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;" />
<span style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;">Features Beautiful Retina graphics, several game modes, Game Center, high score, statistics and more! </span><br />
<br style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;" />
<span style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;">Why not try it? Its free. </span><br />
<span style="background-color: white; color: #898989; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Arial, Verdana, sans-serif; font-size: 12px; line-height: 18px;"><br /></span>
Thanks for looking!Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com0tag:blogger.com,1999:blog-5085243780903903171.post-43399177513402764562013-01-04T23:07:00.002-08:002013-01-04T23:10:32.095-08:00Little plans for the future work - Quadcopter! <br />
<h3>
Micro Micro QuadCopter</h3>
<div>
I have many plans in my head for the future projects and not enough time or money to make them all! But, here is one that could be very interesting for the future work... A QuadCopter! Not just any quadcopter, a micro quadcopter. </div>
<div>
<br /></div>
<h3>
Parts (detailed)</h3>
note: "~" = approximately<br />
- attiny 84 (1 gram) ($3)<br />
- IMU Analog Combo Board Razor - 6DOF Ultra-Thin IMU (estimating it to be < 6-7 grams) ($15)<br />
- plantraco 7mm motors (4) @ (3.3 grams each w/ props*) ($20 for all)<br />
- plantraco 4 channel receiver (1 gram) ($60)<br />
- plantraco LP200-FR Bahoma Cell (small lipo = short flight might use bigger) @ (5.5 grams) ($15)<br />
- frame + wireing (~10 gram) (~$20)<br />
<br />
total weight should be ~38 grams and the price would be approximately $133 + shipping. Not bad huh?<br />
All the tutorials and do it yourself for the quadcopters are about much bigger and thus more expensive models. Going micro does have a lot of drawbacks though. This will never lift a camera like I would like it to. It will never be as stable and it will be much harder to get it right! But that just adds to the fun. Also it would be the smallest and lightest quadcopter out there as far as I'm concerned.<br />
<div>
<br /></div>
Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com2tag:blogger.com,1999:blog-5085243780903903171.post-63798591470894687732012-12-27T16:32:00.001-08:002012-12-28T13:55:52.270-08:00Bluetooth + Arduino Tutorial<h2>
Bluetooth and its wonders. Set it up with Arduino and Attiny85!</h2>
<h3>
Introduction</h3>
<div>
This is my very first tutorial and it is on Bluetooth with Arduino. I feel this is necessary for the community as there are not so many of them out there. The ones that are floating around the web are highly outdated or just not to my taste. Sorry! I know I'm not the best one to do a tutorial either but I will try my best. I learned how to use the Seeeduino Bluetooth, or any Bluetooth the hard way. This is created to make it easier for you! </div>
<div>
<br /></div>
<div>
<b><i>note:</i></b> When I was learning about how to add Bluetooth to my project I was following closely the Wiki page of Seeeduino Bluetooth Shield. Find it <a href="http://www.seeedstudio.com/wiki/Bluetooth_Shield" target="_blank">here</a>. Also, I will be covering how to set up your Bluetooth as a slave. If you would like to learn how to set it up as a Master reference the link above.<br />
<br />
I hope you enjoy this tutorial / how to</div>
<div>
<br /></div>
<h3>
What you need, Arduino Bluetooth</h3>
<div>
<br />
<a name='more'></a><br /></div>
<div>
What you will need for the first part of this tutorial (Bluetooth with Arduino <u>not</u> Attiny!!) is an Arduino Uno, I'm using version 3, and the Seeeduino Bluetooth Shield. You can use a different one by modifying the<br />
tutorial slightly. In the second part of the tutorial I will introduce a different Bluetooth module and how to work it with the Attiny85. </div>
<div>
<br /></div>
<div>
<u><b>The list:</b></u></div>
<div>
<ul>
<li>Arduino Uno (I'm sure you can use others but I haven't had a chance to test)</li>
<li>Seeeduino Bluetooth Shield</li>
</ul>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNXSIbKRzpSVru0mN4EkCbHthpxD5jj6-9tEZjDsajrelsmRaPmO2MB7yy_EdYBB3k4EQEzPrGRrefHELjsf6gnlEyV6VDlNMcVQIoQLLWQO6RvKJl7W25JJJdGu5IkEo1FpWpUbpt9zk/s1600/arduino_w_shield.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNXSIbKRzpSVru0mN4EkCbHthpxD5jj6-9tEZjDsajrelsmRaPmO2MB7yy_EdYBB3k4EQEzPrGRrefHELjsf6gnlEyV6VDlNMcVQIoQLLWQO6RvKJl7W25JJJdGu5IkEo1FpWpUbpt9zk/s1600/arduino_w_shield.JPG" width="320" /></a></div>
<br /></div>
<h3>
OK! We are Ready to Set Up! </h3>
</div>
<div>
First of, lets connect everything like it should be. When you are placing your shield onto the Arduino make sure the analog side is on the analog side of the Arduino and the Digital on Digital. Make sure the pins are matching and just place it down and push it in.</div>
<div>
We are ready to upload! I'm going to assume you have the Arduino software installed and you know how to upload a sketch to your Arduino. The only problem is that we don't have the code!</div>
<div>
<br /></div>
<h3>
The Seeeduino Bluetooth Shield Code</h3>
<div>
This is my favorite part, the coding! </div>
<div>
Start off by opening up a new Arduino sketch. Fill in the usual aka Bare Minimum:</div>
<div>
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;"> void setup(){ }
void loop(){ }
</code></pre>
</div>
<div>
<br />
Now, for us to set up a communication via a serial port we can use a library called SoftwareSerial. Go to tools -> library and choose the SoftwareSerial library. Once you have it imported we can start using it.<br />
<br />
For the first part we are going to set up the software serial port on Arduino channel 6 and 7. 6 being the receiving pin and 7 being the transmitting pin.<br />
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;"> #include <softwareserial .h=".h"> // this will include the software serial port library
int rx_pin = 6; // setting digital pin 6 to be the receiving pin
int tx_pin = 7; // setting the digital pin 7 to be the transmitting pin
SoftwareSerial Bt(rx_pin,tx_pin); // this creates a new SoftwareSerial object on
// the selected pins!
void setup(){ }
void loop(){ }
</softwareserial></code></pre>
<br />
OK, so far so good! The code is not doing much yet but we are getting somewhere. Now its time to set up the pinModes like so.<br />
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;"> void setup(){
Serial.begin(9600); // this is a connection between the arduino and
// the pc via USB
pinMode(rx_pin, INPUT); // receiving pin as INPUT
pinMode(tx_pin, OUTPUT); // transmitting pin as OUTPUT
bluetoothInitiate(); // this function will initiate our bluetooth (next section)
}
</code></pre>
<br />
And now the Bluetooth as a slave. What this means that your android phone or your PC will be able to pair with it and send information back and forth. For this I will create a separate function to keep everything neat in the setup function.<br />
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;"> void bluetoothInitiate(){
// this part is copied from the Seeeduino example*
Bt.begin(38400); // this sets the the module to run at the default bound rate
Bt.print("\r\n+STWMOD = 0\r\n"); //set the bluetooth work in slave mode
Bt.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
Bt.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
Bt.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
Bt.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
delay(2000); // This delay is required.
Bt.flush();
Bt.print("Bluetooth connection established correctly!"); // if connection is successful then print to the master device
}
</code></pre>
<br />
Congrats! You can now connect to your Bluetooth, but it wont do much at all.<br />
So... now we need to do something to receive the packets thrown at us from a PC or any other device.<br />
For this we setup the RX pin and the TX pin, so lets put it to works.<br />
<br />
<pre style="background: #222222; border: width:99%; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left;"><code style="color: white; word-wrap: normal;"> char buffer; // this is where we are going to store the received character
void loop(){
if(Bt.avaliable()){ // this will check if there is anything being
// sent to the Bluetooth from another device
buffer = Bt.read(); // this will save anything that is being sent to the Bluetooth
Serial.print(buffer); // this will print to the local serial (tools->serial monitor)
}
// this is for recieving on the device with bluetooth, now we can make it send stuff too!
if(Serial.available()){ // this will check if any data is sent
// from the local terminal
buffer = Serial.read(); // get what the terminal sent
Bt.print(buffer); // and now send it to the master device
}
}
</code></pre>
<br />
<br />
<h3>
Putty and COM</h3>
<div>
In order for us to communicate between the PC and Arduino via Bluetooth we have to establish a connection via COM. A really good and free program that we can use to establish a serial connection between the Bluetooth module and our PC is Putty. You can download it and read more about it <a href="http://www.putty.org/" target="_blank">here</a>. Now once you have installed Putty we can move on to the next step. </div>
<div>
Power on your Arduino with the shield and the code already uploaded. Remember to restart the Arduino after you have uploaded the code. </div>
<div>
You should notice two leds flashing on the shield, red and yellow. This is good, now you can search for the module using your PC's Bluetooth software. It should be named SeedBtSlave. The pairing code is "0000" Once you have it paired with your computer we can start working our magic, but first we need to check what COM port we are running the Bluetooth connection on. We can do this by clicking start then typing "device manager". Open device manager and navigate down to Ports(COM&LPT), expand it. Now you should notice that you have two new things there. It should say "Standard Serial over Bluetooth link (COM#)" If it does, then you know that you paired your device correctly and are ready to start using it. NOTE: I have more than one Bluetooth device connected therefore there are 4 ports!</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUFcPUh5YLSX7t5U1UBZf10Hgq9rDzDsrK4KNhywCCu8D6H-fSSmqgqEw28DQnsaVYvUkbkz7m4qn76_ogjDvylkfugo_tWbX2xruJ4a18eE2GGz8aE2PbHu1NarNIhItRM-u6Zsgc_j4/s1600/prots.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="229" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUFcPUh5YLSX7t5U1UBZf10Hgq9rDzDsrK4KNhywCCu8D6H-fSSmqgqEw28DQnsaVYvUkbkz7m4qn76_ogjDvylkfugo_tWbX2xruJ4a18eE2GGz8aE2PbHu1NarNIhItRM-u6Zsgc_j4/s1600/prots.png" width="320" /></a></div>
<div>
<br /></div>
<div>
Note the COM number. (usually the top one out of the two) and lets go over to Putty. </div>
<div>
Open up Putty and select the "serial" radio button. Now set the COM# and the speed as 38400. This is what we used in the code*</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRzKzNmJlNH-vqGZdB2vD4n4JgB4W1ltN8_D6QIDLXSNxbsJmzWmDWlf1xbjPmBej8YtJx5SEOVls7nDgRRbK4-emp7cPitAe_WQS0GETct1zqjJMaMAOIzyjFim05AsS37cOdIk4UfR4/s1600/putty.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="284" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRzKzNmJlNH-vqGZdB2vD4n4JgB4W1ltN8_D6QIDLXSNxbsJmzWmDWlf1xbjPmBej8YtJx5SEOVls7nDgRRbK4-emp7cPitAe_WQS0GETct1zqjJMaMAOIzyjFim05AsS37cOdIk4UfR4/s1600/putty.png" width="320" /></a></div>
<div>
<br /></div>
<div>
At this point I would recommend that you restart your Arduino before proceeding to open the connection. When the red/yellow lights are flashing on the Arduino you are ready to connect! If everything went right you should see this screen:</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdy07oq5g4BgsMufywfcrJa9GgmaCDpwNk0JYaV4UNlT_VMKvB93Yh2XNAKjAVu8IGqvHmL77XKEf0NzUs2j2P3xj-D96usuEJoQf02aX5AI__d8W7foXvhg7zTdBWRTS_y9VOzVDPRI/s1600/connection_success.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="201" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGdy07oq5g4BgsMufywfcrJa9GgmaCDpwNk0JYaV4UNlT_VMKvB93Yh2XNAKjAVu8IGqvHmL77XKEf0NzUs2j2P3xj-D96usuEJoQf02aX5AI__d8W7foXvhg7zTdBWRTS_y9VOzVDPRI/s1600/connection_success.png" width="320" /></a></div>
<div>
<br /></div>
<br />
Congratulations!!! This message has been sent over Bluetooth from your Arduino to your PC!<br />
Now open your local terminal monitor (the USB connection between your PC and Arduino) and send messages between the two. I have used this to turn on and off LEDS and move SERVOS. Its heaps of fun and the limits are your imagination.<br />
<br />
Later on this week I will post a tutorial building upon this and how to use a different Bluetooth module with the Attiny85. Stay tuned! I hope you enjoyed this tutorial, if you have any questions please comment. Also, keep in mind that this is my first tutorial and one of the first blog posts ever. If you do not understand something or if you would like to comment on anything do not hesitate to post.<br />
<br />
Thanks for reading!</div>
Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com65tag:blogger.com,1999:blog-5085243780903903171.post-55518202712223040802012-12-27T13:14:00.001-08:002012-12-28T13:56:00.356-08:00About Me<h2>
Just a Bit, About Me</h2>
<div>
My name is Damian Glinojecki, I'm a student at Hunter College based in NYC. I'm studying computer science and in my free time I work on a lot of my own projects such as iphone apps, arduino projects and many more. Enough said, time to write something about my current projects!</div>
Damian Glinojeckihttp://www.blogger.com/profile/17425285209191621622noreply@blogger.com0