Thursday, November 7, 2013

Lowcost Bluetooth Roomba adaptor (rootooth)

Materials: 

- 1 x 0.1mF Capacitor
- 1 x 0.33mF Capacitor (0.1mF Capacitor works too)
- 1 x +5V Fixed-Voltage Regulator 7805
- 1 x Bluetooth - TTL Bluetooth Module (Serial UART) - 115200 8N1 capable
- 1 x UST to TTL adaptor (could be optional)
- 1 x Roomba 5xx (I believe that works with other models too but I didn't test it)
- Welder and utilities


Introduction:

I have an iRobot Roomba 530 that I found for free in craigslist (broken battery) some weeks ago, this model of Roomba has no option to schedule vacuum jobs, so you have to press START button each time that you want to vacuum the floor, it's not a big deal, but I knew that you could do that through serial port. After reading about it in the Internet, I realized that there is a Bluetooth module called rootooth to do that wireless.
Rootooth is expensive and big and I did't want to have something attached to my roomba, then I decided to do it by myself.


Bluetooth module:

To substitute the iRobot Bluetooth module (Rootooth) you need a Bluetooth to TTL module, I found it in Ebay (there are a lot) and it costs me less than $15, it has to have these features:
- 5V VCC input
- AT mode
- 115200 8N1 capable
- RX, TX, VCC and GND pins



Steps:

 First, we have to configure our Bluetooth module to work in 115200 8N1 if this isn't the default configuration. For that, use a USB to TTL adapter connected to your Bluetooth module and follow the manufacturer steps to change it.


*picture of the USB-TTL adapter

In my module, it was in 9600 8N1 by default, so I used putty with this config and "AT+BAUD8" to change it as described by manufacturer.

Once our Bluetooth module is configured in the same way as our roomba, it's time to create our power adapter. Since the roomba works with more than 5V, we need something to convert this voltage to 5V, then I used a 7805 regulator that I bought in Radioshark and two capacitors, you have to create this schema:
INPUT and GND will be connected to out roomba, OUTPUT and GND to VCC and GND to our Bluetooth module.

Now is time to open the roomba to access to the board, we could connect it directly to roomba's port, but I don't like this idea, since I prefer to have it inside of the roomba. Anyway, if you want to use the port, this is the schema:
* Remember that TX and RX have to be switched and Vpwr and GND have to be connected to the power adapter.


   But if you are a perfectionist, you can follow any how-to to open the roomba, after that,  look for the TTL port on the roomba board, and try to localize where you have to connect your Bluetooth module:



It was easy using a multimeter in "continuity" mode. This image above if for my 530, it will be safe if you test it for your roomba model, just in case.
Using a welder, we have to connect GND to GND in our power adapter, VCC to input of our power adapter, TX to RX of our bluetooth and RX to our TX of our bluetooth device, you have to be sure that you use enough cord to put your bluetooth module with the power adapter in the hole where the charger plug is (see next picture).


It's time to check that it works before close the Roomba, so now you need a computer with bluetooth. Connect your Roomba's battery and link you computer to your bluetooth module as a normal bluetooth device, then use a terminal software (as putty or minicom) to connect to the bluetooth/TTL that you just created (it depends of your OS). If you are using Linux, follow this steps:

   # rfcomm connect 0 xx:xx:xx:xx:xx:xx #your bluetooth module mac
   # minicom -b 115200 -D /dev/rfcomm0

Now if you push "STAR" button in your roomba some lines have to appear in you screen, it not, try to check that all connections are working fine, if it still doesn't work, try to swap TX and RX connections, it worked for me.

It's time to close your roomba and if you have an Android phone, try "Roomba touch drive" app (https://play.google.com/store/apps/details?id=com.fl&hl=en) and enjoy!
If you don't have an Android phone, there are a lot of different programs for windows and maybe for mac/IOS that you can try.


References:
http://hackingroomba.com/projects/build-a-roomba-bluetooth-adapter/
http://www.securitybydefault.com/2011/01/hacking-roomba.html


Acknowledgments:
- G. Giribet, without your wheel, my roomba would still limp...
- M. Leon, your help with the power adapter was essential.


Friday, March 1, 2013

Import data file to MySql Database


Introduction:

We are trying to add data from a text file (snp file, dep file, etc) to a MySql table but we want to be sure if the import process was successfully before save or discard this data.

Steps:

#From the mysql shell, we start the transaction:

mysql> BEGIN;

#We use "load data infile" to load the data, we can define in which column is going each file column.
mysql> LOAD DATA INFILE '[PATH_OF_THE_FILE]'  INTO TABLE [TABLE] (column2,column3,column5,column8);
Query OK, 69144 rows affected, 1 warning (0.71 sec)
Records: 69144  Deleted: 0  Skipped: 0  Warnings: 1
#After that, we can use show warnings to decide if we want this data or not
mysql> show warnings;
+---------+------+---------------------------------------------+
| Level   | Code | Message                                     |
+---------+------+---------------------------------------------+
| Warning | 1364 | Field 'column1' doesn't have a default value |
+---------+------+---------------------------------------------+
1 row in set (0.00 sec)

#Save data or discard
mysql> commit; #Save
mysql> rollback; #Discard

REFERENCES:

http://dev.mysql.com/doc/refman/5.0/es/load-data.html
http://dev.mysql.com/doc/refman/5.0/en/commit.html