Friday, November 16, 2012

My Raspberry Pi has gone wireless - part 2

I found more info that answers my own questions from my previous post My Raspberry Pi has gone wireless.

Related to the first question I don't really have an answer: for some reason, it doesn't work on my home network but it does at work. Not sure why. A suggestion on github was to clean the cookies but that didn't help. I'll try more stuff when I get to it.

More important is the answer to the second question. Between this Debian and this RaspberryPi forum posts, I found out that I can have more than one network configured in the /etc/wpa_supplicant.conf file. Most of the time this works fine, I get an IP using the Wifi adapter; sometimes though I need to run "sudo ifup wlan1" (even in the Debian forum post it says I shouldn't). It may be something that I did wrong or maybe my adapter is not working quite right.

In the Debian forum it says that you can use either auto or allow-hotplug for the wlan configuration so I commented out the auto line. Maybe I'll try putting it back in to see if this fixes the times when I don't get an IP.

I plan to get a second Pi some day and at that time I will buy another Wifi adapter, either this one from Adafruit or if that one is not in stock then this one from Amazon (it seems in the reviews that lots of people were able to easily make it work with their Pi's and it is pretty fast).

Just for reference, the config files on my Pi now look like:

/etc/wpa_supplicant.conf
network={
        ssid="SSID_work"
        psk=abc123
        id_str="work"
        priority=5
}

network={
        ssid="SSID_home"
        psk=abc123
        id_str="home"
        priority=10
}

network={
        key_mgmt=NONE
}
/etc/network/interface
#auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
   wpa-driver wext
   wpa-roam /etc/wpa_supplicant.conf

#auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
   wpa-driver wext
   wpa-roam /etc/wpa_supplicant.conf

iface home inet dhcp
iface work inet dhcp
iface default inet dhcp

Wednesday, November 14, 2012

A quick fun project with my Pi

I was looking for a simple Raspberry Pi project that would be fun for Halloween, something with some spooky sounds that used pygame (I've read about pygame on Adafruit Learning System and wanted to give it a try) and I found this article on the Make blog.

I didn't use an Arduino though, instead I just read 2,3 and 4 from keyboard. At the time I didn't know pygame can help with reading keys as well so instead I used some simple code I found on the web and ended up with this program.

Since I run my Raspberry Pi headless it was very easy to set it up by my sound system; connected my laptop wirelessly with the Pi and turned the keyboard to my 3 year old son. He had a blast pushing keys and making sounds. A quick simple project that turned out to be very fun for him - thanks Make and Shawn Wallace in particular for the idea.

Next, I want to change the code so I read the arrow keys instead of number ones; this will be a step towards using my Makey Makey with the Pi. I found some resources, the most promising seems to be this one. I'll update when I have something working.

Tuesday, November 13, 2012

Import Dropbox folder into existing remote git repository and store the local repository outside Dropbox

All this info is already available on the net but since I had a few problems along the way, I decided to document these steps so I remember how to do it in the future.

These steps allow me to import existing code from a Dropbox folder into an existing git repository (BitBucket in my case) while keeping the local repository outside Dropbox, thus separating the source code from the git repository files.

First let's not worry about separating the local repository from the code source.

1. Locally, at the root directory of your source:
> git init

2. Attach your remote repo with the name 'origin' (like cloning would do):
> git remote add origin [URL]
in my case URL was the https one not the SSH one (because I want to use password)

3. Locally, add what you want in your initial repo:
> git add . (for all the files)
OR
> git add subdir_name (for the files in a subdirectory)

4. Locally, commit what you added:
> git commit -m 'initial commit comment'

5. Pull the existing code from the remote repository:
> git pull origin master

6. Push up your master branch (change master to something else for a different branch):
> git push origin master

The above works without any problems when the code is in the same directory as the git repository. However, my code is already in Dropbox and I didn't want to have the .git repository in the same directory (there are some known problems with Dropbox correctly syncing git files) so some of the steps above are a little bit different in this case.

After steps 1 and 2 above, I changed the config of the local git repository using:

> git config core.worktree "c:/<path to My Dropbox folder>/projects"

Note: I didn't use the --global modifier because I only want this git repository worktree to be different, I don't want to change all the git repos configuration (with --global, the .gitconfig file in my home directory would change; without --global, only the .git/config file changes).

Now, when I add files, I can use a subdir of the worktree directory without fully qualifying it, so basically it works as above, step 3. Also, commit and push work fine. The only issue I found is pull returns an error:

fatal: Not a git repository (or any of the parent directories): .git

After some research, I found that adding the --git-dir modifier fixes this so the pull command becomes:

> git --git-dir .git pull origin master

After all this, I now have the configuration I wanted:
- local git repository in a directory outside Dropbox
- all the code in Dropbox
- some of the projects in the remote repository.

This helps me have a copy of all the code in Dropbox so I can access it from several computers but only some projects in git (because most are just things I start and never finish and they are not worth saving in a git repository as well). On each computer, the only thing that changes is the worktree of the local repository.

I am pretty sure there are other ways of doing all this, git submodules seem interesting, but this is what worked for me.

Wednesday, November 07, 2012

My Raspberry Pi has gone wireless

A few days ago I found a Dynamode Wifi USB adapter on ebay for a very nice price and since Adafruit's wifi adapter was not in stock, I decided to get it. I was worried it may not work with my Pi but I risked it. For some reason, I thought it uses a Realtek 8188CU chip so I figured it will be easy to configure it, given all the info I found at elinux.org and other websites. I plugged it in my powered hub and the first problem showed up: a bunch of errors at boot time, like smsc95xx ... kevent 4 may have been dropped - the only way to get the Pi to boot was to unplug the dongle. This happened on both SD cards I have, one with Raspbian Wheezy and the other with Adafruit's Occidentalis.

After a bit of digging, I found that this is a common problem that is addressed by Hexxeh's rpi-update. It took a while for the firmware to be updated but it worked, next time I booted there were no more errors.

Now I had to configure it. After a lot of frustrating time trying to make it work, I had the idea of using lsusb (I know, should've done this from the beginning!) and to my surprise, lsusb reported a Ralink RT5370 chip. Again elinux.org helped a lot, this page has all the info (I will not mention the time I wasted thinking the router was setup with WPA when instead it was WEP and not being able to understand why I was not getting an IP address and all the DHCP requests were not successful). Finally, got it to work! This was an awesome moment!

After that, I gave up on the old router and used the main one we have setup with WPA. It took a little more setup but again, all the info was on the same elinux.org page and it worked from the first try. This was on Raspbian. Next I tried the same on Occidentalis and after a bit of hickup, got it to work here as well (on Occidentalis for some reason the adapter is wlan1 instead of wlan0, not sure why this is the case but after realizing this, all was well). The steps are:

1) sudo apt-get install wpasupplicant
2) sudo apt-get install firmware-ralink
3) sudo wpa_passphrase NetworkEssid password
4) sudo nano /etc/wpa_supplicant.conf - paste text from step 3, remove the passkey line:
network={
       ssid="NetworkEssid"
       psk=945609a382413e64d57daef00eb5fab3ae228716e1e440981c004bc61dccc98c
 }
5) sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf - ctrl+c to stop
6) sudo nano /etc/network/interfaces - add:
auto wlan0
     iface wlan0 inet dhcp
     wpa-driver wext
     wpa-conf /etc/wpa_supplicant.conf
7) sudo ifup wlan0

After a few messages like "DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6" the wifi adapter should get an IP. If not, something is wrong, start over with the steps above.

So now I have a wireless connection for my Pi. I love it!

There are 2 things I still need to figure it out:
  1. For some reason, the Adafruit's WebIDE doesn't want to connect when I use the wireless adapter. It works great when using the wired connection but not on wireless. SSH works fine using raspberrypi.local so probably this is not the problem - I logged an issue on github and hopefully I will hear back. If not, no problem, I can use the wired connection for WebIDE and wireless for other projects I plan.
  2. I am not sure how to connect to different wireless networks automatically - I want to do this in case I take my Pi with me at work for example. From what I gather at this time, I need to change the /etc/wpa_supplicant.conf config file and run the config command sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf every time but there has to be a simpler way. I'll try and see if I can come up with something.

In any case, this was a lot of work for me being a Linux newbie but getting connected was a real breakthrough. I'm really happy to have one less wire to connect when I run my Pi headless.

A huge thanks to everyone posting information and help on the web, particularly to Hexxeh and the guys contributing to elinux.org Raspberry Pi pages!

Tuesday, October 16, 2012

I2C LCD

I am done with buying cheap LCDs and trying to make them work. Last week I found an I2C LCD on ebay (named something like YwRobot LCM1602 IIC Arduino compatible) and I figured since it only needs a couple of wires to be used, I can give it a try. And it worked great!

Well not quite from the start, since I thought it needs 3.3V but after I switched it to 5V, it worked like a breeze. The library I used is LiquidCrystal_I2C (I found it here) - it is not compatible with Arduino 1.0 but I still have 0022 installed so no problem. Apparently, there is another library named fmalpartida/new-liquidcrystal that works with 1.0 but I haven't tried it yet - it looks like I would need to remove the library that comes with Arduino 1.0 and replace it with this one, I may try it someday.

Connecting to the Arduino is very easy:

  • GND to GND
  • VCC to +5V
  • SDA to analog pin 4
  • SCL to analog pin 5

    The next step is to use this LCD with my Raspberry Pi but if I understand this correctly, the LCD working at 5V and the Pi I2C pins working at 3.3V I need to be careful, I think I will wait until this board is back in stock at Adafruit.
  • Saturday, October 13, 2012

    Raspberry PI WebIDE

    Adafruit is awesome!

    This is my first post about my Raspberry Pi - so what's up with the subtitle? Well, we all know it already. Really, if you ever ordered something from Adafruit or if you asked for help or if you followed the tutorials or the newer Learn section... you know I'm right. And when the Raspberry Pi was born, Adafruit was one of the first sites with tutorials and help and even a new distro that made life a lot easier for beginners in Linux like me. And if all this was not enough to convince you, here is one more: the Adafruit Raspberry Pi WebIDE. I don't know when they find the time to do all this but I am so grateful they do.

    I delayed installing the WebIDE for a few days, thinking that being a Linux newbie I will mess it up for sure. But when I followed the Installation and Getting started steps in the Adafruit learning system, all was so very easy.

    When I first got my Pi, I was able to do some simple stuff like make an LED blink (Raspberry Pi Spy site helped me a lot - Thank you!) but now with all the cool libraries the WebIDE comes with I can finally start to really learn Python and hopefully make some cool projects! Thanks, Adafruit!

    Talking about learning Python, Learn Python The Hard Way by Zed A. Shaw looks to be an awesome book.

    And a final note and big thanks to Getting Started With Raspberry Pi blog: the info here helped me setup a VNC server and this made it accessible using raspberrypi.local:5901 instead of using the IP.

    Wednesday, August 22, 2012

    Got My Servo Workin'

    I wanted for a long time now to get a servo and to make it work with Arduino and I finally did. Got a couple servos from one of my favorite places, Pololu, read a bit on how to make them work with an Arduino here and here, loaded this sketch on the Arduino and done - it worked from the first try!

    Big thanks to all the resources I used and Pololu for offering great parts at good prices!

    Wednesday, June 20, 2012

    Android: Music in the cloud

    I use both Amazon Cloud player and Google Music player on my Android phone, each having its good (Amazon's lock screen player is a lot nicer, Google keeps track of played and thumbs up/down) and bad. But one thing I just discovered will make me use Google's player a lot more from now on: I just found a way to "sync" my playlists directly from the web client. Maybe it is a known feature but I just figured it out so it's new to me.

    To do this, create a playlist in the web player. Go to the playlist on the phone and check Available offline - all songs in the playlist will show up on the phone next time you sync. Nothing earth shattering up to here. The cool thing is that if you now go to the web player and add/remove songs to/from the playlist, next time when you sync, they will be added/deleted on the phone as well. Very simple and obvious but also very powerful.

    I used to download my Google Cloud music, added it to iTunes and sync to the phone using the awesome iSync. But now there is no more need for this. I will keep syncing my iTunes music via iSync but the Google Cloud music will stay only on the cloud.

    As far as I can see, Amazon doesn't have this feature; well, you can set it to automatically download all your purchases to the phone but this is not the same, I just want some songs, sometimes old ones, not all the new ones. Overall this means I will be using Google's player a lot more from now on.

    As a side note, I am using the paid version of Rocket Player by the same authors as iSync and love it. Too bad it doesn't play Google Cloud songs. But someday it will and then I will sync the playlists as I just said but not use the Google Music player anymore, Rocket has so many more features.