Friday, November 21, 2014

Continous rotation servos

Back after a small hiatus with a somewhat short post.  So today we talk about continuous rotation servos. What are they exactly?
Well continuous rotation servos look exactly like normal servos. Figure 1 shows you one continuous rotation servo.



Figure 1: Never judge a servo by its looks

Ok, nothing special here. Let's draw the line between a servo and a continuous rotation servo.

SERVO - Feed it some value and it will move to some position/angle. Speed is preset.
CONTINUOUS ROTATION SERVO - Feed it some value and it will rotate at some speed. You can vary both speed of rotation and direction of rotation. Is to servos what the evo is to mitsubishis. A completely different monster.

Right. You can vary both its speed and direction of rotation. That is particularly useful if you are building a differential drive robot. A differential drive robot is based on two motors that are independent of each other. The video below gives you a demo of one differential drive project I have been working on, during calibration phase. 





Calibration is extremely important here. I need to know the pulses that must be fed to each motor so as to obtain a specific motion. After a long phase of testing, you'll have gathered all that data, thereby getting what I call the engine map.
Let's get things clear here. Yes, I can vary the speed and direction of rotation of the continuous rotation servo and the manufacturer will often provide timing pulses for that.
If you are on arduino, commands(manufacturer) would be like:

myservo.writeMicroseconds(1500) =>Full stop
myservo.writeMicroseconds(2000) =>Full speed right
myservo.writeMicroseconds(1000) =>Full speed left

Now, the world would be beautiful if everything followed such brilliant precision. However, it's not. You are gonna have to obtain more accurate values for these data. If you are on a differential drive, double the precision. For making turns, you need for two wheels to be perfectly synced. Now, as you saw, it's not the case. Working with those perpendicular lines was a way of calibrating turns. After a really long and incredibly frustrating testing period, I came up with the engine map. 
Usually, if you vary between the extremes, you can vary the speed. The video below demos the capacity of a continuous rotation servo. I'm just crudely mapping the readings from my potentiometer to my servo.



Now, why do I think they are a good bet for differential drives? After all, dc motors coupled to H bridges and encoders would do the trick. Here's your answer. It's plug and play. No need to cram your design with additional components(like H bridges and encoders).
That's it. Thanks for reading. More next week.




Friday, November 7, 2014

Controlling your Arduino from your phone via bluetooth

Controlling your Arduino from your phone via bluetooth is simple business. I would  have liked having been told that a few years ago. It's just that to get it done, you need resources that are spread throughout the web. In this post, we'll build a simple controller. Our aim is to switch an LED on/off . All that, wirelessly.
So, where do we start? We could ramble on and on about the various theories on Bluetooth but chances are you need a quick fix solution. That is what we'll be doing here.
Ok, so parts we'll be needing:
1. An arduino
Well, any arduino would do but I'm using an arduino uno
2. An LED
Classic 5mm LED
3. A bluetooth module
The bluetooth module is essentially the component which takes care of the transmission and reception of the data. I'm using a bluetooth mate silver which is shown in Figure 1.



Figure 1: The BT mate silver



4. A phone with some serial communication software
I'm using a Lumia 625 and despite the limited limited LIMITED(did I say LIMITED? It's that bad) number of apps available on their store, I grabbed a small serial communication software called BT Terminal, shown in Figure 2. Many many thanks to the creator of this app.


Figure 2: The App
5. An RGB
An RGB is essentially 3 LEDs in one package. They are insanely cool.


Figure 3: The RGB

6. Some wires
First things first. You need to power your project. Be it the 5V regulator, usb power, anything that works will do. So in my case, I'm just plugging the UNO to my computer's usb port.
Then, you need to connect the components together. So connections are

A) Bluetooth mate silver module
Now this is advanced stuff. So, the module will communicate at some speed and we need to know that speed. I think the BT mate silver's default speed is 115000 bauds. You can change that to values that suit you by configuring the module. If you don't want to do that, you'll be using 115000 in the program. I've set mine at 9600. The module comes without header pins, so if yours is out of the box, you have some soldering job on the line(be careful to not leave your iron on these pins for too long)
There are some marking on the board, so:
1. VCC to 5V power
2. GND to Ground
3. TX-0 to Arduino Pin 2
4. RX-1 to Arduino Pin 3

B) LED
Simple job
1. Ground it
2. Connect the +ve lead to pin 5 via a resistor(anything between 1k and 2k is OK)

C) RGB
The RGB is cool once you know it. So longest lead is grounded and the remaining three pins are connected to Arduino Pins 6, 7 and 8 via resistors. You should have something like this.



Figure 4: Setup


Now, for the code:
/* 
Simple Bluetooth controller project
Sordagen Bryan Arnasala
7 November 2014
*/
#include <SoftwareSerial.h>
//Setting up trans and recept pins
int BTtx = 2; //Arduino Pin 2 is connected to TX-0
int BTrx = 3; //Arduino Pin 3 is connected to RX-1
SoftwareSerial BT(BTtx, BTrx); // Serial comm config, I'm using BT,anything'll do
//Setting up led and RGB pins
int LED = 5;
int RGB1 = 6;
int RGB2 = 7;
int RGB3 = 8;
char TOKEN; 

void setup()
{
  BT.begin(9600); // Careful here. Make sure you have the proper value
  pinMode(LED, OUTPUT);
  pinMode(RGB1, OUTPUT);
  pinMode(RGB2, OUTPUT);
  pinMode(RGB3, OUTPUT);
}

void loop()
{
  while (!BT.available()); 
  TOKEN = BT.read();
  if( TOKEN == '1' )
  {
    digitalWrite(LED, HIGH);
    digitalWrite(RGB1, LOW);
    digitalWrite(RGB2, LOW);
    digitalWrite(RGB3, LOW);
  }
  else if( TOKEN == '2' )
  {
    digitalWrite(LED, LOW);
    digitalWrite(RGB1, HIGH);
    digitalWrite(RGB2, LOW);
    digitalWrite(RGB3, LOW);
  }
  else if( TOKEN == '3' )
  {
    digitalWrite(LED, LOW);
    digitalWrite(RGB1, LOW);
    digitalWrite(RGB2, HIGH);
    digitalWrite(RGB3, LOW);
  }
  else if( TOKEN =='4')
  {
    digitalWrite(LED, LOW);
    digitalWrite(RGB1, LOW);
    digitalWrite(RGB2, LOW);
    digitalWrite(RGB3, HIGH);
  }
  else if( TOKEN =='5') //Turn off all LEDs
  {
    digitalWrite(LED, LOW);
    digitalWrite(RGB1, LOW);
    digitalWrite(RGB2, LOW);
    digitalWrite(RGB3, LOW);
  }
}

Ok, now just upload this. Load your serial comm app. You might have to do some straight forward bluetooth pairing and you are off. Commands "1" to "4" switch one colour on. Command "5" turns off all of them. Here's the project at work.




That's it! If you can switch LEDs on and off, you could do the same for motors, sirens, fans...anything! You might want to read data from sensors. This is easy to do. The BT.println() command does that. You might also be cognizant in App development - you could then build an app that is custom for your project. 
Thanks for reading!