Friday, May 9, 2014

RaspberryPi: Tweeting in Morse Code

It has been months without any idea. With RaspberryPi and my recent interest in Node.js and no interesting ideas around. I decided do a simple project just for fun. Here was the plan:

  • Listen to the tweets on particular topic, keywords, and from specific users
  • Convert it to Morse code
  • Emit the code from sound (beeper) and light (LED) source.
  • Make it testable without RaspberryPi and offline (using Telnet)
So, I wrote a Node.js based code which can be downloaded from my Github repository naishe/tweemorse the code basically does the following stuffs:

  1. Based on what parameter you passed it either starts to listen to Twitter for the keywords and users that you have configured; or it launches a Telnet server on port 23 where you can sent it a message, and it will translate it.
  2. Once the message arrives it is "queued" in a message queue for processing.
  3. There is a queue consumer that takes the messages one by one and converts them into Morse code.
  4. This Morse code gets read character by character "dit" or "dah" or "white space". (You may know more about Morse code from this Wikipedia article.) Based on the character, the output pin is sent either a HIGH or a LOW signal. Here is a rough idea:
    1. dit: short HIGH
    2. dah: long HIGH
    3. transition between two characters: short LOW
    4. white space: long LOW
  5. HIGH means LED and and beeper on, LOW means they are off.
For more details and instructions look the Github repo. And, finally, here is how it looks when I tweeted a SOS:

That's all folks!

Saturday, April 5, 2014

Raspberry Pi: Setting up Your Pi without External Keyboard and Monitor

This article shows how to do it on an Ubuntu machine. But the procedure will be the same on all the Unix and Linux machine. You will need to look for equivalent command for Windows platform. Essentially, this is what I am doing: 
  •  Formatting and copying Raspbian OS to the SD card 
  •  Editing /etc/network/interfaces file 
  •  Putting the SD card in Pi and plugging it to router. 
  •  SSHing to Pi and running a couple of commands

This post is geared towards getting Raspberry Pi set up to work from network.
  • You will not need a separate keyboard or monitor for installation and setup.
  • You will need a router to access your Pi via VNC or SSH.
  • Keep handy: an 8GB SD card, Raspberry Pi, network/LAN cable to connect your Pi to the router, access to the Internet.
Lets get started:
  1. Insert the SD card, run df -h to see where it is mounted:

    $ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sda8        35G   28G  5.1G  85% /
      none            4.0K     0  4.0K   0% /sys/fs/cgroup
      udev            2.0G  4.0K  2.0G   1% /dev
      tmpfs           392M  928K  391M   1% /run
      none            5.0M     0  5.0M   0% /run/lock
      none            2.0G   17M  1.9G   1% /run/shm
      none            100M   44K  100M   1% /run/user
      /dev/mmcblk0    7.4G  4.0K  7.4G   1% /media/nishant/naishePi
  2.  Format the SD card

    $ sudo mkdosfs -F 32 -v /dev/mmcblk0
    or you can use disk utility GUI tool by typing "Disks" in Ubuntu HUD

  3. Get a copy of Raspian from 
  4. Unzip it:
    $ unzip 
      inflating: 2014-01-07-wheezy-raspbian.img    
    $ ls
  5. Copy the image file to the SD card using dd
    $ sudo dd if=2014-01-07-wheezy-raspbian.img of=/dev/mmcblk0 bs=1M
      2825+0 records in
      2825+0 records out
      2962227200 bytes (3.0 GB) copied, 588.065 s, 5.0 MB/s
  6.  Execute sync to ensure nothing it left to write:
    $ sync
  7.  Unmount the SD card:
    $ sudo umount /dev/mmcblk0
  8. Remove the SD card from the slot and reinsert. It is required because the file system table has changed.
  9.  Now if you browse the SD card it will look like you are browsing a Linux distro. Also, you will see two partitions:
    $ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sda8        35G   28G  5.1G  85% / 
      none            4.0K     0  4.0K   0% /sys/fs/cgroup
      udev            2.0G  4.0K  2.0G   1% /dev
      tmpfs           392M  932K  391M   1% /run
      none            5.0M     0  5.0M   0% /run/lock
      none            2.0G   17M  1.9G   1% /run/shm
      none            100M   52K  100M   1% /run/user
      /dev/mmcblk0p2  2.6G  1.9G  586M  77% /media/nishant/fc254b57-8fff-4f96-9609-ea202d871acf
      /dev/mmcblk0p1   56M   19M   38M  34% /media/nishant/boot
Here you are 80% done. We now need to setup the network configuration so that we can SSH to our RasPi.

This is my plan. I should be able to place this SD Card in my Raspi and I shall be able to access it via SSH when I power it and connect it to the router that my laptop is connected to.
  1. Lookup your configuration using route command
    $ route -n
      Kernel IP routing table
      Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         UG    0      0        0 eth1     U     1000   0        0 eth1   U     9      0        0 eth1
  2. We have mask, and gateway from last command. We know that the IP is going to be in 192.168.2.X series. So, lets assign to RasPi. To do this, we need to edit /etc/network/interfaces on the Raspbian OS ***in the SD CARD** which is located at /media/nishant/fc254b57-8fff-4f96-9609-ea202d871acf/etc/network/interfaces. MAKE SURE YOU DO NOT END UP EDITING YOUR UBUNTU'S CONFIG.

    Replace the iface eth0 inet dhcp line with this:
    iface eth0 inet static
DONE! Now place this SD card in your RaspberryPi, power it up, connect it to your router. Wait for 5 minutes. Now, try SSH from your laptop:

$ ssh pi@
The password is "raspberry" by default. Now you are in Raspberry shell. You need to configure it.

Configuring the system: Execute the following, one by one:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo raspi-config

Use up, down, tab, shift-tab to navigate through the wizard. Enter/space for selecting an option, and esc to going back to previous option.
Remember, unless you Finish this wizard, Raspbian will keep complaining that the config is not yet complete. So, make sure you finally select the "finish" button.

With basic configuration done, I wanted to use the hostname to SSH to the machine. If you wanted to do that, install Avahi.

$ sudo apt-get install avahi-daemon

Now, reboot.

sudo reboot -n

Wait a couple of minutes. Now, ssh pi@raspberry.local (e.g. ssh pi@.local)

Setting up VNC: If you wanted to work on Raspberry GUI. You will have to run VNC server on that so that you can access GUI through network. Here are the steps

  1. SSH to your Raspberry Pi.
  2. Install and run Tight VNC Server

    $ sudo apt-get install tightvncserver
    $ tightvncserver
    $ vncserver :1 -geometry 1024x728 -depth 24
  3. Access the GUI by using your favorite VNC client I use Remmina Remote Desktop Client on Ubuntu.

  4. If everything goes fine, you will see your RasPi Screen on your computer. And you could play with it as if you are directly connected to it.