Sunday, July 13, 2014

The R2D2 Project - The vision


I have always wanted to build a robot like  R2D2 (who hasn't right?) , so I recently purchased a used Hasbro Interactive R2D2 like this one. I did not expect it to work and I got pretty much what I expected. It powers on and responds to the "Hey R2" command but that is about it. I am going to change most of the electronics in it anyway so I wasn't too concerned.

Time to take it apart!  There are already quite a few comprehensive documents and videos on how to disassemble the R2D2 online so I am not going into the details here.

R2 uses 4 AA batteries for the 2 PCB boards inside and 4 DD for running the 3 motors (2 for the legs and one for the rotating dome). The power board looks like this.


















Main control board (left). After the dis-assembly (right).





















Here is what I intend to do. Note that this is all in-flight, so the plans are subject to change.

Hardware:
1) Re-use the 4 AA for motor control.
2) Re-use the speaker and potentially the multiple mics
3) Re-use the LEDs for the dome
4) Add an Intel Galileo as the main brain for the robot
5) USB webcam w/ audio
6) PIR sensors/Ultra-sonic range finder

Software:
1) Yocto (Intel IOT Devkit Version)
2) Speech recognition via Google speech to text API
3) OpenCV for object recognition
4) Motion (If you have read my other posts, you know that I love using this)

Monday, February 10, 2014

Raspberry Pi Home Security + Automation - Phase 3

In Phase 1 and 2 of my previous posts in this series, I showed the basic setup of a Home security  +  automation system. No home security system is complete without a siren/alarm so this posts addresses that.

I was looking for a way to trigger the alarm and wanted it to be completely isolated from the Pi GPIO to avoid false triggers.  I also wanted to avoid using more GPIO for this project so I decided to a 433Mhz wireless siren similar to the one on Ebay here

If you open up the wireless strobe siren you will find this:


There is a small switch on the PCB to switch the circuit on/off. A white wire goes from the board to the piezo siren. For initial testing, I would recommend disconnecting the siren so that you can verify that your system works correctly without the really loud (90 dB) siren.

A 433MHz transmitter accompanies the strobe/siren to trigger it. I wanted to decode the code sent by this to allow me to trigger the siren myself. So I hooked it up to a 12V battery below and pressed the test button (see picture below).


The receiver already connected to the Pi (as shown in Phase 1) will help you find the code for your siren module. (use RFSniffer provided on the ninjablocks website to do this)

Here is a  short video showing the system in action.

Note - 
  • The 433 MHz door/window sensor  shown here is actually one that is normally connected to my  door/window and is not the one provided for triggering the siren. 
  • I have removed the waits in the code to trigger the siren immediately for the purpose of this video. You would normally have a delay to allow system disarm by an authorized individual


video

Thursday, January 16, 2014

Raspberry Pi - Controlling 433 MHz remote outlets

In my previous post here, I tried to use a cheap 433 MHz transmitter to replicate the 433 MHz remote functionality but landed up hacking the remote to send the codes instead. The main issue I was facing there was that the code was not being recognized by the RF outlets.

I was finally able to resolve that issue so I just need one GPIO pin to control all my RF remote outlets now!

Troubleshooting my original issue:

I am using this receiver and transmitter - 433MHz Tx-Rx pair (set of 2)








I was using the RCSwitch library ported over to the Raspberry Pi from here
http://ninjablocks.com/blogs/how-to/7506204-adding-433-to-your-raspberry-pi

As mentioned in my previous post, I first tried using the Audacity route but I could not decode the data correctly.

Since I had an Arduino lying around as well, I downloaded the RCSwitch library for the Arduino and tried the advanced receiver demo.

The output for one switch of my remote looked like this:
Protocol: 1
Decimal: 1398209
binary: 000101010101010111000001
PulseLength: 207

I noticed that the pulse length was 207 which is different from the default length in the code. I quickly changed the pulse length in the send demo sketch on the Arduino and was able to get the RF outlet to switch on!

So I went back to my Raspberry Pi and modified the send.cpp code to look like this:
int main(int argc, char *argv[]) {
    /*
     output PIN is hardcoded for testing purposes
     see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
     for pin mapping of the raspberry pi GPIO connector
     */
    int PIN = 0;
    unsigned long code = atoi(argv[1]);

    if (wiringPiSetup () == -1) return 1;
        printf("sending code[%d]\n", code);
        RCSwitch mySwitch = RCSwitch();
        mySwitch.enableTransmit(PIN);
        mySwitch.setPulseLength(207);
        mySwitch.send(code,24);
        return 0;
}

Note: I have removed the header files for a cleaner code look below. Please include them in your actual code if you want to use the code below.



I have the transmitter data pin connected to the Pi pin 11 (GPIO 17). I re-ran make in the dir and sent the previously decoded code:
sudo ./send 1398209

And it works! Good riddance to the multiple GPIO pins to replicate the remote functionality +  the remote is free for use independently now.


Monday, January 6, 2014

Arduino Yun - Introduction + Controlling GPIO via a web server

My Arduino Yun arrived over the weekend and I was surprised by how small it was compared to my Pi or Galileo. It is roughly the size of a credit card (see below).



Some of the things I really like about this:

  • Built in Wifi, micro SD card reader and  Linux OS (Linino)
  • Small form factor - ideal for applications that I am interested in like robotics and home automation
  • Easy Wifi setup in any new location
  • Ability to program sketches over Wifi and use the console terminal wirelessly to see events happening in the sketches.

This is a great guide to get started: http://arduino.cc/en/Guide/ArduinoYun. I used it to setup WiFi and allow open REST API access.

My first goal was to set up a USB webcam and install motion on my Yun. I achieved this by using the package management to install the necessary driver and packages
opkg install kmod-video-uvc motion

I plugged in my webcam via a USB hub and I was happy to see that it showed up after using dmesg and lsusb.

I started up motion and was able to see that it streams to a Firefox browser seamlessly. Goal #1 accomplished.

Next, I wanted to use a web browser to control GPIO to enable my next project which is a web controlled robot. So I wrote a simple sketch that uses browser buttons to turn the on board LED on and off. The sketch can be downloaded  here.

To get this to work I had to do one step that was not clearly documented anywhere. I had to manually create a soft link in my /www/ folder for sd:
ln -s /mnt/sda1 /www/sd

Another key thing to note here, is that your sketch folder needs to have a www sub folder with the index.html and zepto.min.js file in it. When your sketch is uploaded via WiFi, the contents of the www folder and automatically copied to /www/sd/<sketchname> folder

The REST calls to /arduino are made from the index.html file. To undestand what the REST API is, I would encourage you to read up on it in the getting started URL mentioned above.

If you view the source of the html, you will see this:


<script type="text/javascript">

    function ledon()
   {
       $('#content').load('/arduino/ledon');
   }
   function ledoff()
  {
      $('#content').load('/arduino/ledoff');
  }

</script>


It basically passes the ledon/ledoff commands to the Arduino once the buttons are pressed. The sketch simply looks for this and manipulates the GPIO:


if (command == "ledon") {
       digitalWrite(13, HIGH);
 }

else if (command == "ledoff") {
       digitalWrite(13, LOW);
}

After you have uploaded the sketch over to your Yun, you can use any browser to go to http://your_yun_name.local/sd/webled

You should see these buttons which will allow you to control the on board LED.


Hope this helps others who are trying to attempt something similar.