Showing posts with label raspberry. Show all posts
Showing posts with label raspberry. Show all posts

Tuesday, March 4, 2014

Raspberry Pi Journal #52



Spell Checker



Perhaps it may surprise you that the Raspberry Pi comes with a built-in spell checker. aspell and ispell.

The standard word list is located in /usr/share/dict/

However, aspell has its own directory: /usr/lib/aspell

The standard aspell mode is by checking the spelling interactively. There is a way to do it with non-interactive method. This will let you dump misspelled words all at once.


  1. cat sample.txt | aspell list


list is a command that basically prints misspelled words coming in from standard input.

Tuesday, February 25, 2014

Raspberry Pi Journal #51



Screen Capture



I'm using scrot as my screen capture program. Just real quick, to use scrot with 8 seconds delay:


  1. scrot -cd 8 filename.jpg


and to do screen capture only the window, use


  1. scrot -cud 8 filename.jpg


Then you get a jpeg picture of the filename.

Tuesday, February 18, 2014

Raspberry Pi Journal #50


Tape Archive Compression



There's a built-in program to provide back up, or archive. It's called TAR or Tape ARchive. You can read more about it in the man pages. I'm interested at this point, in the execution time. As you know, tar does not provide compression by default. You can activate the compression feature by including option -z. There is no question that it works. The question is, how fast is it?


  1. time tar -c VID0000*.AVI >vid.tar
  2. real 0m1.903s
  3. user 0m0.040s
  4. sys 0m1.590s



  1. time tar -cz VID0000*.AVI >vid.tgz
  2. real 1m8.890s
  3. user 1m4.000s
  4. sys 0m2.890s


As you can see, the original operation is just a couple seconds long. The compressed option, however, took over 1 minute long. That's an enormous difference! Let's do a pipe with gzip command.


  1. time tar -c VID0000*.AVI | gzip - >vid.tar.gz
  2. real 1m19.526s
  3. user 1m9.580s
  4. sys 0m3.320s


The process takes even longer to process. So, let's see if we can improve it so that the time it takes will be between uncompressed and the original compressed.


  1. time tar -c VID0000*.AVI | ssh pi@remotepi gzip - >video.tgz
  2. pi@cloudypi's password: enter password
  3. real 12m54.990s
  4. user 0m16.460s
  5. sys 0m9.620s


So, there's a trick to it. I'm using the pipe command to send the data to a remote pi on the network. Then the remote pi compresses the data and then send it back to my local pi. As you can see, the time went through the roof. Obviously, the network bandwidth is the bottleneck. After all, my CPU utilization rate is near zero. Which is nice since I can watch anime while it's compressing. But that's besides the point since I can use the "nice" command to put it into the background.

Oh, well. Some things just aren't worth it.

Tuesday, February 11, 2014

Raspberry Pi Journal #49



SD Card Formatting



There's quite a bit of discussion on how to format the SD card. The easy way to do it is to just gparted program. It's point and click easy. However, what if you want to do it automatically? Use *sfdisk* program.

Once you prepped the SD card using gparted, use the sfdisk program to dump the info out to a file. This is what I did in order to get 4 GB file data.


  • sudo sfdisk -d /dev/sda > SD4GFAT32.sdmap
  • cat SD4GFAT32.sdmap 
  • # partition table of /dev/sda
  • unit: sectors

  • /dev/sda1 : start=    16384, size=  7684096, Id= b
  • /dev/sda2 : start=        0, size=        0, Id= 0
  • /dev/sda3 : start=        0, size=        0, Id= 0
  • /dev/sda4 : start=        0, size=        0, Id= 0




So that's the file, and its content. Now, if you redid the whole partition using gparted to something like this:


  • sudo sfdisk -d /dev/sda 
  • Warning: extended partition does not start at a cylinder boundary.
  • DOS and Linux will interpret the contents differently.
  • # partition table of /dev/sda
  • unit: sectors

  • /dev/sda1 : start=     2048, size=  4319232, Id= b
  • /dev/sda2 : start=  4352000, size=  3356672, Id= 5
  • /dev/sda3 : start=        0, size=        0, Id= 0
  • /dev/sda4 : start=        0, size=        0, Id= 0



You can use sfdisk to restore it to its former partition, thus reformatting the SD card.


  • sudo sfdisk /dev/sda < SD4GFAT32.sdmap 
  • Checking that no-one is using this disk right now ...
  • OK

  • Disk /dev/sda: 1020 cylinders, 122 heads, 62 sectors/track
  • Warning: extended partition does not start at a cylinder boundary.
  • DOS and Linux will interpret the contents differently.
  • Old situation:
  • Units = cylinders of 3872768 bytes, blocks of 1024 bytes, counting from 0

  •    Device Boot Start     End   #cyls    #blocks   Id  System
  • /dev/sda1          0+    571-    572-   2159616    b  W95 FAT32
  • /dev/sda2        575+   1019-    444-   1678336    5  Extended
  • /dev/sda3          0       -       0          0    0  Empty
  • /dev/sda4          0       -       0          0    0  Empty
  • New situation:
  • Warning: The partition table looks like it was made
  •   for C/H/S=*/6/18 (instead of 1020/122/62).
  • For this listing I'll assume that geometry.
  • Units = sectors of 512 bytes, counting from 0

  •    Device Boot    Start       End   #sectors  Id  System
  • /dev/sda1         16384   7700479    7684096   b  W95 FAT32
  • start: (c,h,s) expected (151,4,5) found (2,20,17)
  • end: (c,h,s) expected (1023,5,18) found (1018,5,18)
  • /dev/sda2             0         -          0   0  Empty
  • /dev/sda3             0         -          0   0  Empty
  • /dev/sda4             0         -          0   0  Empty
  • Warning: partition 1 does not start at a cylinder boundary
  • Warning: partition 1 does not end at a cylinder boundary
  • Warning: no primary partition is marked bootable (active)
  • This does not matter for LILO, but the DOS MBR will not boot this disk.
  • Successfully wrote the new partition table

  • Re-reading the partition table ...

  • If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
  • to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
  • (See fdisk(8).)




Just to make sure, here's the command again.


  • sudo sfdisk -d /dev/sda 
  • # partition table of /dev/sda
  • unit: sectors

  • /dev/sda1 : start=    16384, size=  7684096, Id= b
  • /dev/sda2 : start=        0, size=        0, Id= 0
  • /dev/sda3 : start=        0, size=        0, Id= 0
  • /dev/sda4 : start=        0, size=        0, Id= 0


One more thing. If you want to reformat the partition to FAT32 filesystem, you can do this:


  1. sudo mkfs -t vfat /dev/sda1


Yes, you need to format each partition separately, and that means you can have different file system per partition. Also, vfat stands for FAT32, although you can specify it explicitly, or use something else entirely.


Tuesday, February 4, 2014

Raspberry Pi Journal #48


SD Back up time


How long does it take to back up 16 Gig SD card, anyway? Using my PNY SD 16 Gig, this is the time that it takes to fully back up the card using noob clone.

  • real 113m8.210s
  • user 2m21.400s
  • sys 24m42.570s

Or about 140 minutes. That's pretty fast.


Tuesday, January 28, 2014

Raspberry Pi Journal #47


SD card capacity


So I was wondering why my dd command always fail with insufficient disk space message. Turns out that there are different sizes with different SD card brands. Here is my size of PNY 16 gig card:


  1. sudo fdisk -l /dev/sda



  • Disk /dev/sda: 16.0 GB, 16012804096 bytes
  • 255 heads, 63 sectors/track, 1946 cylinders, total 31275008 sectors
  • Units = sectors of 1 * 512 = 512 bytes
  • Sector size (logical/physical): 512 bytes / 512 bytes
  • I/O size (minimum/optimal): 512 bytes / 512 bytes
  • Disk identifier: 0x00000000

  •    Device Boot      Start         End      Blocks   Id  System
  • /dev/sda1            8192    31275007    15633408    c  W95 FAT32 (LBA)



And here is my size of generic store brand 16 Gig card:


  • sudo fdisk -l /dev/sda
  • Warning: ignoring extra data in partition table 5

  • Disk /dev/sda: 16.0 GB, 16009658368 bytes
  • 4 heads, 16 sectors/track, 488576 cylinders, total 31268864 sectors
  • Units = sectors of 1 * 512 = 512 bytes
  • Sector size (logical/physical): 512 bytes / 512 bytes
  • I/O size (minimum/optimal): 512 bytes / 512 bytes
  • Disk identifier: 0x00048a81

  •    Device Boot      Start         End      Blocks   Id  System
  • /dev/sda1            2048     2324218     1161085+   e  W95 FAT16 (LBA)
  • /dev/sda2         2326528    31268863    14471168   85  Linux extended
  • /dev/sda5         2334720     2449407       57344    c  W95 FAT32 (LBA)



As you can see, the PNY SD card has holds 16012804096 bytes, compared to 16009658368. So that's the difference of 3145728 bytes. No wonder the dd command always fails. Well, there are two ways about it:


  1. Buy identical PNY SD cards
  2. Migrate the whole thing to a smaller, generic SD card.


Option one is easy, but depends on availability of such card. Option two is, frankly, a pain at this point. I have too many stuff in there already.

Option 3, which is to built another card, and copy the files between them somehow does not work because the keyboard stopped working. No, I don't know why, but that is why it's off the table.

Tuesday, January 21, 2014

Raspberry Pi Journal #46


Disable Screensaver

The last couple posts deals with pesky screensaver kept interfering with our display. We certainly want to have an easy way to disable the screen saver, and for that, we need to go to the source: X window session itself.

Most of the instructions I see on the internet specifies .xinitrc file modification. Although it should work, that makes the change permanent. If I can do it via user shell, I'd rather do it that way.

Fortunately, there is a set of xwindow utilities. The one we're interested in is called xset. Disabling DPMS (Energy Star) feature is as simple as

xset -dpms

Enabling it would be

xset +dpms

So, to disable screen blanking, we'd do this:


  1. xset s noblank   #Disable blanking
  2. xset s off       #Disable screensaver
  3. xset -dpms       #Disable Energy Saving


And to enable them, we can do this:


  1. xset s blank      #Enable blanking
  2. xset s on         #Enable screensaver
  3. xset +dpms        #Enable Energy Saving


So I created two scripts: unblank.sh and blank.sh respectively. Oh, I also put sudo command in front of them, just to make sure it takes.

Now, all I have to do in order to disable the screen saver is type

unblank.sh

on the command prompt. And to enable it, just type

blank.sh

And there you go. Note that xset does more than just dealing with screen savers. Check out its man page for details.

Tuesday, January 14, 2014

Raspberry Pi Journal #45


SlideShow Update

Given such trouble in working with refreshing the screen saver, there is an easy way to do slide show:

gpicview

This lightweight program does automatic slide show for all images in a directory. It is configurable. It can show picture on the whole screen, so it doesn't show title bar or icons.

You know. I just spend some money to buy a dedicated digital picture frame, and all it does is show Animal Crossing pictures from my Nintendo 3DS. Well, that and a few other things that's from the device. But with this program, I can show just about anything and on big screen TV, too.

Will it survive screensaver shutdown? Nope. You still need the screen refresher from last time.

Tuesday, January 7, 2014

Raspberry Pi Journal #44


Raspi #44
Prevent screen from blanking

If you want to show picture slide shows for hours on end, you probably run into a "feature" that is quite annoying: screensavers. The gist is that the program will interrupt your display to save your screen. It is a prudent action in order to stop your monitor from burning static images. The issue isn't as common as before, but even with the latest LCD display, it is still present. Therefore, having an automatic screen saver feature is desirable.

The problem is when we want the screen to burn all the time, such as displaying photo slide show. How do we disable the screen saver? I'm sorry to say that the system is very complex and that there is no single way to disable the screen saver.

I suppose you can kill the process, but that's not a desirable solution in the long run.

The trick here, is to let the computer know that you want the screen is up all the time. So, press a key in the keyboard or jiggle that mouse. A robot that shakes the mouse all the time seems ideal. Alternatively, put the mouse in a shake box.

However, we can do better than that. Even if the solution is hackish, we should do it all in software. There is such a thing, and it is:

pygame.event.get()

That's a python script. So far, that pygame is for Python 2.7. So we'll use that. Write a python program that will poll the keyboard/mouse event. Let's call it: unblank.py


  1. import pygame
  2. pygame.init()
  3. pygame.event.get()


And when you run this program:

python unblank.py

The screen saver process should terminate and the timer will restart. All you have to do is call it periodically and problem solved!

I'll just stick that line in my wallpaper rotation script


  1. #!/bin/bash

  2. for ((walltick=100;$walltick;walltick=$walltick-1))
  3. do 
  4.   PIC=$(ls wallpaper/*.jpg | shuf -n1)
  5.   pcmanfm -w $PIC
  6.   *python unblank.py*
  7.   sleep 100 
  8. done
  9. pcmanfm -w saber.png
  10. sleep 5
  11. exit 0


The whole process takes a couple second because python is not an insignificant process. So this answer is hackish and not very good.

And what do you know? It doesn't work! I would think that pygame.event.get() will reset the input, but apparently not. So, back to square one. The problem is, there are so many things that can be wrong, and you never know which one. That's very frustrating.

So, let's open up a window and see if that works. Here's the modified python script


  1. import pygame
  2. from time import sleep

  3. pygame.init()
  4. window=pygame.display.set_mode((32,24))

  5. while True:
  6.     pygame.event.get()
  7.     window.fill(pygame.Color(255,255,255))
  8.     pygame.display.update()
  9.     sleep(100.0)


Notice that this is an infinite loop, which is something I try to avoid. The problem is that it opens up a window, so I can do something to it, and that's not good. So, now, I'm running the script in the background, minimizing the window.

Minimizing the window needs to be done manually, which is a terrible solution. Worse, when I kill the process, the window still stays up! There's no way to terminate the window that I can see. Therefore, this command is useless:


  1. python unblank.py & pid=$!
  2. kill $pid


Because python script is killed yet the window is still up, there's no longer any way to close the window. It's definitely broken. So, now, I pull another shell just to run the program, keeping it in the background. That's another window open.

Of course, the right solution is to provide a refresh command, that we can use to reset the screensaver timer. How is it that we do not have such command?

Tuesday, December 31, 2013

Raspberry Pi Journal #43


Speech Synthesis Trouble

I'm having a hard time coming up with proper speech synthesis. I tried using espeak, and it seems to work, but the first few seconds was off as if having buffer underflow, and the last few seconds was slow, as if it's having buffer overflow. Tried festival, and that too, suffers from the same problem.

As a last resort, I installed Basic256, and use its "say" command. The speech was clear and concise. Unfortunately, the buffer overflow problem is still happening. So, in the end I gave up.

I think the problem does not lie in the speech program. After all, all the speech module does is chaining snippets of audio to make the speech. I don't see any problem in that regard. It's the audio driver that is a problem. Apparently, the buffer isn't set up properly and so the audio becomes scrambled.

It should be possible that the audio be working fine. After all, I don't see any trouble regarding audio in playing movies.

Tuesday, December 24, 2013

Raspberry Pi Journal #42


Symbolic Linking

Here's something to ponder. Let's say that you want to have a certain file that is frequently modified. But, you also want to have a copy of all the modifications. Something like a running log. You can, of course, do it like this:


  1. Create the file, make changes to it, etc.
  2. Copy the file to some other name, adding timestamp.


So, let's say we have a file called Musings.txt. We can use this command copy the file, while adding time stamp.

cp Musings.txt `date Musings_%F.txt`

You can change the date format to anything you like. See the man pages for "date" for details.

Another way to have a file associated with changes, and this is important if you want to make changes to it, but want the file associated with the latest stable version, as opposed to the latest edited, is to use symbolic link command.

ln -s original_file linked_file

By making copy as a linked file, you can refer to the linked file whenever you want, and refer to the original file. Then when you're ready, simply replace the linked file to the updated one.


  1. rm linked_file
  2. ln -s updated_file linked_file


It's a two step process, but you can work with the updated file to your heart content, and be sure to have the updated file ready to be "released", without changing anything else.

It's similar to copy, but more space efficient.

Tuesday, December 17, 2013

Raspberry Pi Journal #41


Portable Webcam Network cron @reboot

Okay. Last time we messed around with webcam, we messed around with motion daemon as a service. Well, I found out an easier way to do it. So, the first thing we want to do is to disable the motion service. This, of course, after spending a whole day setting it up. Siiiiiiiiigh.


  1. Go to /etc/default
  2. Open up motion file
  3. change the line start_motion_daemon=yes to start_motion_daemon=no
  4. Go to /etc/motion
  5. set motion not to run as daemon in motion.conf (daemon off)
  6. set process_id_file as undefined
  7. Goto to home directory
  8. run crontab -e
  9. Add the line @reboot motion &



And that's it. Just one little @reboot word in the right place. It runs the program at boot (and reboot) time. That's all there is to it. For bonus, it runs as the proper user, so file permission isn't a problem. Make sure that it runs in the background (enable daemon) on motion.conf. Tada!!! Done! 10 minutes!

Tuesday, December 10, 2013

Raspberry Pi Journal #40


Portable Webcam Software - motion



Last part, we have all the software and hardware installed and ready to go. In this section, we are going to set up the software that does the motion detection: motion.

First, we're going to SSH into the device:

SSH hostname

Enter your password. Next, we're going to set up a few configurations options. We want to set up some directories. We need to be careful here because we're going to run the software as daemon, which means its own user name and priviliges. The user name is called "motion". The password? I don't know. I can tell you that "sudo login" followed by "motion" and no password does not work.

So, the first thing we want is to set up a directory for the webcam. I'm going to set it up under /home/common/webcam


  • sudo mkdir /home/common/
  • sudo mkdir /home/common/webcam
  • sudo cd /home/common
  • sudo chown motion webcam
  • sudo chgrp motion webcam
  • sudo chmod 777 webcam


That will create a special webcam directory, that is accessible by all. Hopefully, nobody will login into it and cause trouble. I would prefer chmod 775, but let's make things easy for now.

Next, we need to configure the motion program and set up some parameters. Specifically, I want:

Save a picture per second everytime motion is detected, continue for about 10 seconds after.
Create a time-lapse movie for the day
Create a time-lapse movie for all motion capture
Set a webserver, so we can view it on the web browser
Create a log directory and file


So, the first thing we need to do is to locate motion.conf file. I found it in /etc/motion/ directory. Otherwise, check /usr/local/etc/ directory. If all else, you can do it the hard way:


  • cd /
  • ls -lR * | grep motion | grep motion


Yes, I did "grep motion" twice. I did it to filter out the error messages because I run the command as a normal user, instead of root.

So, let's get to /etc/motion directory


  • cd /etc/motion
  • ls -l


You'll see the files motion.conf, and thread1.conf-thread4.conf. This is because motion software can handle up to 4 simultaneous webcams. I'm using only one, so I don't have to worry about threadN.conf files. The first thing I want to do is make a backup or motion.conf before doing anything else.


  • cp motion.conf motion_conf_orig
  • sudo nano motion.conf


Next, I'll just scan the file and change the appropriate fields, according to my wish list above.


  1. daemon on
  2. width 640
  3. height 480
  4. framerate 2
  5. minimum_frame_time 1
  6. brightness 200
  7. threshold 6000
  8. noise_level 128
  9. pre_capture 1
  10. post_capture 10
  11. gap 120


All right, so that was for the camera settings. Now we go to the Image File Output settings:


  1. ffmpeg_cap_new on
  2. ffmpeg_timelapse 5
  3. ffmpeg_timelapse_mode hourly
  4. ffmpeg_video_codec mpeg4
  5. text_double on



Now that we have all the files set up. Let's set up all the file names and directories:


  1. target_dir /home/common/webcam
  2. jpeg_filename %H%M%S
  3. movie_filename %H%M%S
  4. timelapse_filename lapseview


Finally, we're into the server territory. We want to configure the ports for our webcam. There are two factors here: control and webcam. Control is the user interface for our webcam. webcam is the address that we want to use as mjpeg streamer to see what our camera see


  1. webcam_port 8081 <-change this to any open port you like
  2. webcam_quality 50
  3. webcam_motion on
  4. webcam_localhost off
  5. webcam_limit 600

  6. control_html_output off


And that should do it! There are other settings that I can use, especially the ones regarding picture/movie generation. This is useful if we want to copy the movie files somewhere.

So, now, let's reboot, and see if everything works as expected!


  • sudo reboot


and load a web browser, connected to the camera host address and port, and check to see if there's a web stream out there!

Pinging cloudypi seems to work, but I don't see the webcam being on? This where trouble starts. How come I can't start the process? Because there's something that I need to do, that is missing from the step. Reading the magazine, it says to set "start_motion_daemon yes" to motion.conf. And yet, reading the manual "man motion", it does not mention it at all!

So, which should I believe? The printed one? Or the one live on my device? Obviously, the one on my device. Is there no hope for me? There is something about user guide. Let's check it out:

/usr/share/doc/motion/motion_guide.html

Well, that didn't help at all. I know there's something that I need to change in order to start motion from boot, but what?

I tried to run motion from command line. Failed due to lack of permission. Create the motion.pid file, and change all permission.

sudo mkdir /var/run/motion
sudo touch /var/run/motion/motion.pid
sudo chmod 666 /var/run/motion/motion.pid

Now, let's see if it works. Well, the daemon works. The SSH hangs. Not good at all! In the end, I had to unplug the cable, and replug. Second time around, I got clever and use the setup mode:


  • motion -s -c /etc/motion/motion.conf


It works fine. I see avi, jpg, and mpg files. Set up is a success, now to automate it. There's quite a bit of assumption that you know how to start a program during boot, but as you can see, it's not obvious. With wrong headed instruction such as "start service" things, then I'm just as confused as ever.

However, there is the salvation that is the net. Digging around for hours did yield something. There is a motion file in /etc/init.d. Aha! Let's check it out.

It sure looks like one of those service files. So, maybe the instruction does mean something. Just not 100% accurate. Looking at the file, I see this:


  1. check_daemon_enabled () {
  2.     if [ "$start_motion_daemon" = "yes" ] ; then
  3.         return 0
  4.     else
  5.         log_warning_msg "Not starting $NAME daemon, disabled via /etc/default/$NAME"
  6.         return 1
  7.     fi


And the simplest thing is to go open up /etc/default/motion file and see what it says.


  1. # set to 'yes' to enable the motion daemon
  2. start_motion_daemon=no


Uh, I think we hit the jackpot, here! Are you kidding me? This is all that's needed? How come there's not one single line telling me to do this in the manual? Do you know how much time I wasted looking for this one line? Sigh.

Well, change it to "yes", and see what happens! Changed the file. Reboot. SSH into it. Run "top". Yes, it's up there. Check webcam directory. Does not seem to write to the directory. Stop the program and check it out.


  • sudo service motion stop


Further checking yields images still not being written. There's only one conclusion that I can gather: motion.conf is not being read correctly. Strange thing is, if I just start it normally, it works fine! So, back to /etc/init.d/motion and see if I can force motion.conf to be read.


  1. DAEMON=/usr/bin/motion -c /etc/motion/motion.conf


I just don't see how nobody is running into these kind of problems! Or if they did, they don't say. Did the setting somehow changed? I don't know. It certainly is frustrating. I know it is possible, but there's absolutely no instructions, and so, I have to try things out myself.

Did not work. After reading the manual for start-stop daemon, I came up with this:


  1. if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion -- -c /etc/motion/motion.conf ; then


That seems to work. Alas, no new images is loaded. So, maybe the configuration file is read correctly, after all, but then what is wrong with the process? Doing it interactively works fine, after all. Why would putting it into the service fails?

Interestingly, not only starting it manually with service fails to write images, but it somehow kicked the "output_motion on", and yet, checking it via the web control interface shows that it's off. Obviously, there's something seriously wrong here, but I don't know what. Gremlins, that's what it is.

Checked /var/log/user.log

It turns out that the program is having trouble writing to timelapse.mpg. I changed the attribute with


  • chmod 777 timelapse.mpg


And restarted the service. It works fine, now. Jeez. Do you know how long it took me to find that? There's just not enough instructions on the web!

So, reboot, and see if the process still hopefully works.

Everything looks good to me! Well done!

And it only took one whole day!

Tuesday, December 3, 2013

Raspberry Pi Journal #39


Portable Webcam Hardware - hardware+os


Okay, so we know that the webcam project works in Raspberry Pi. The next step is to bring out the portability of the device. So, we'll be making a portable Deer Camera project. Which is basically just a box with a camera on it. Because we're using Raspberry Pi, we can have all the features we want. So here's the shopping list:

Raspberry Pi B : $40
Case : $9
16 GB SD card: $12
ASUS N150 Wifi: $20

Total: $81.

Add webcam for $10, and battery pack for $50, and we'd have spent about $140 total. The battery pack is really the expensive option, and I'm sure the more creative among you can get it cheaper. I'm just using the common iphone charger. Which turns out to be a mistake. I don't have a solution for this yet, but one potential solution that you can consider would be to get a 12V car battery, hook it up with cigarrete lighter to phone charger, and into the raspberry pi. We still need lights to see, but I'm leaving it out for now.

I'm thinking that the Raspberry Pi model A would be better. However, this being my first experiment, I decided to keep it simple and simply copy the OS from my desktop computer. It works! So, the next step is to create a copy from scratch and install it SSH way. Big problems.

First, format a 16 GB SD card and copy NOOBS into it. Assemble the hardware. I'm pilfering the HDMI, keyboard, mouse, and power supply from my desktop Raspberry Pi for setting it up. Booting NOOBS over it, I'm setting it up this way:


  1. GUI off
  2. SSH on
  3. Set locale+keyboard
  4. set wpa_cli
  5. set hostname


Pull out keyboard. Reboot. SSH into it. So far so good. Half hour since I first started. I assembled the hardware already. Here is the final desired setup:




Problem. There is no connection to the network. Obviously, the /etc/network/interfaces is faulty. All attempts to fix it failed. I look for instructions. All instructions involved putting in a GUI in order to set it up. I frantically searched for instruction to set up the network without GUI. Couldn't find it. So, 2 hours later, I'm back to square one, and booted up the GUI version. It works no problem.

Sigh. Since I'm being stubborn, I want to know what action items behind the scenes are necessary in order to put up the network via CLI interface, instead of GUI interface. So, I remove everything. And after a long and arduous search on the internet, with a good deal of experimentation on my own, I finally came up with this:


  1. wpa_cli (starts in interactive mode)
  2. -scan (wait until WPA-AP-AVAILABLE)
  3. -scan_result
  4. -add_network (returns network#)
  5. -set_network 0 ssid "MyNetworkName"
  6. -set_network 0 psk "password"
  7. -enable network 0
  8. -save_config


Once you quit, you do these commands (instruction from the internet, I don't understand this):


  • iwconfig
  • sudo ifdown wlan0
  • sudo ifup wlan0
  • ip addr


So, those are the commands that comes from instruction gleamed from the internet. Don't ask. I don't know the answer.

Reboot into SSH. Success! Well, not really (Siiiiiigh!!!). I ran into the message "Remote Host ID has changed". Something about man-in-the-middle attack. So, back into the last set up. Erase all keys. Reboot into SSH. Success, finally.

So now I have a Wifi and webcam into both USB plugs, and everything is just peachy. Time to install the software


  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get motion mplayer fswebcam


We want to do it real quick to see if the set up works:


  • fswebcam -r 640x480 sample.jpg -D 15 -fps 1


check it


  • fswebcam 0l 1 --save pic%a%S.jpg
  • rsync webcampi:/home/pi/pic*.jpg


After entering the password, I downloaded the file into the desktop pi, and use gpicview to see it. Success!

Phew. Finally done.

Next step, we need to configure motion software so the server daemon would be running at reboot. But that's topic for another time.

Tuesday, November 26, 2013

Raspberry Pi Journal 38


Sync 


A little quickie here. One fine day, the Foundation Website features a tip of the day that says "sudo sync".

Well, that's strange. sync command does not require sudo, does it? And it does not. In fact, if you run it as sudo, not only the OS will login as super user before executing the command, it will also write to a log file after executing the command, hence, invalidating the write buffer. So, when you use a sync command, just type sync. Don't use sudo in front of it.

Another thing to worry about is whether or not it's safe to pull the card immediately after you issue the sync command. Turns out, it used to be not. An old version was set up as asynchronous, which is a fancy way to say that it runs as a background task. Therefore, you get the shell prompt immediately even though it hasn't finished executing. So that's bad.

The good news is that sync command cannot be doubled up. So, if you execute two sync command in a row, the second one must wait for the first one to finish. The solution is simple: run it twice!


  • sync; sync


And you should be fine.

One more thing. When you shutdown the device, do you need to use sync? Common sense says no. However, I always do. Better to be overly safe too many times, than a mishap happens once. Do you need to run it twice? No, you don't. The shutdown/halt command issues its own sync command, so you only need to do it once.


  • sync; sudo halt


And that should do it.

Tuesday, November 19, 2013

Raspberry Pi Journal #37


Trying Out Operating System


So, I was trying out different operating system. The two I want to check are Arch Linux and Raspbmc. So, here is my impression of them:

Arch Linux


This distro has been touted as "light" OS because of the minimal packages installed on it. I can certainly vouch for its minimalism. There's hardly anything there! Supposedly it has an excellent package manager "pacman" that lets you install the most current, desirable packages. Sadly, it's a whole new OS, and packages. That means, I have to learn everything from scratch. I did check out the package list, and although there are some overlap with Raspbian, some of the packages are custom version specific to Arch Linux. In the end, I decided that if I want a slim OS, I'd sooner clean up Raspbian out of unnecessary packages, rather than starting a whole new OS from scratch.

Raspbmc




I have heard that this distro is painless and fun. So, with great anticipation, I installed it. It's a simple matter to run NOOBS on it, and overwrite the SD card with this system. After some booting, the picture ended up skewed on the monitor. Uh-oh. Bad sign. Turns out it's not a problem at all. After a couple reboots, the system went up. It's just as they said: painlessly simple. I went around the menus, and admiring the user interface. There's no TV show, though. Hmmmm. I went to the option menu and installed some Internet TV connection. There's no connection.

Well, duh, obviously I need to connect it to the Internet. I completely forgot about that. The problem is, there's absolutely to option to scan Internet connection! None whatsoever. In the end, I have to look up my SSID, and typed it in exactly. Lo and behold! It worked!

The distro then went into automatic OS upgrade cycle. Auto re-boot. And that's the last thing I saw from it. It went to blank screen from then on. Sigh.

Tuesday, November 12, 2013

Raspberry Pi Journal #36


Updating Raspberry Pi


This should be clear to everybody, but knowing that there are noobs out there, I thought I should mention this. Then again, noobs probably won't be able to find this page, so ... what can I say?

Anyway, when you try to install packages via apt-get, it is advisable to update the database. Those packages are indexed and you should refresh the index as to what packages are available and from where. It does take some time, but you really should update at least weekly. If a certain package you're trying to update is not available, then you should at least refresh the index and see if the list is outdated.


  • sudo apt-get update


Another thing that you can do is to upgrade all your installed packages to the newest current version. I don't usually do this, believing that if it ain't broke, don't fix it. But sometimes there is a feature that is new, and you want it. And if you're upgrading one, may as well upgrade the other. This kind of upgrade will not delete any packages. I would always do double backup before doing this, however.


  • sudo apt-get upgrade


Another kind of upgrade will actually remove obsolete packages. Presumably, this will keep your system current, and clean. I don't see this being done anywhere, however. Besides, if I really want to have a clean, current system, I'd rather rebuild than doing a simple upgrade.


  • sudo apt-get dist-upgrade


If you want to upgrade only one package, you can install it again. This will update only the package you want. I would use this most of all. Furthermore, you can install old package if you want. Check out the man page for details.


  • sudo apt-get install packagename


Any old, obsolete package should be removed. There are two kinds: remove and purge. The difference between them is that remove retains the configuration files in anticipation of future installation. Purge will remove not only the package, but also the configuration files, as well. Practically speaking, though, "remove" is the command you use if you want to lighten up your distro, but unsure whether or not purging of a package will break it. So you remove it, and see if everything still works fine. Then you purge it out of the system.

Speaking of different packages, you're probably wondering how you can tell what packages are installed on your system. Use dpkg command. You can get a list of the different packages that are installed on your system with this command:


  • dpkg --get-selections


You should see the list of installed packages, with the status "install" alongside it. As always, check the man page for details.

Tuesday, November 5, 2013

Raspberry Pi Journal #35


Cron Macro


Cron and the accompanying crontab is a scheduler. That is, you set the schedule for the programs you want to run at certain times. The instruction is clear enough, except, there is absolutely no instruction about the macro. By that I mean @hourly and others. I really can't find any instruction at all! I know @hourly is present because it is mentioned there. How about other macros? @daily, @weekly seem obvious. How about @minutely? Is that valid? I have no idea.

Here's something else: @reboot.

Yeah, I read that in some instruction pages somewhere, except I don't know how that person know that there is such instruction! It's not mentioned anywhere that I checked! Well, there's only one thing to do, then, isn't it? Try it out and see if the program really runs at booting time.

Strange that the macro is named @reboot. One would think that @boot would be more appropriate. No, I don't know if @boot macro exists. Like I said, there's no documentation that I can find anywhere.

Tuesday, October 29, 2013

Raspberry Pi Journal #34


Noob-Guru: The Great Divide


Sometimes, reading all the posts on the web reveals the great division between noob and guru. One recent example was a question on how to have your own web address. The answer, of course, is to set up a DNS server. It was suggested that you hire some services out there. There are several questions: How about running your own DNS server? Who would provide DNS server services, but not hosting? Who would provide hosting, and also includes DNS server services? Et cetera.

One of the answer, however, directs me to this site:

http://elinux.org/R-Pi_Hub

which is an excellent Raspberry Pi resource. I printed off quite a few pages out of it. But no answer whatsoever regarding the original question. One of the page does mention on how to set up your own web server. However, there is no instruction on how to connect it to DNS server.

Well, obviously, you need to do such and such. Except, those steps aren't obvious to beginners. Thus, what is simple and natural to experts, are insurmountable obstacle to beginners.

Another example. Google Coder is an excellent piece of work. I went to github, which holds the source, and found no installation instructions whatsoever. I had to go to another site, and apparently, it's a relatively standard install. Except for one thing: You need to install Apple Bonjour Service. What? Why would I need that?

Turns out, I need it so Chrome/Internet Explorer/Mozilla whatever browser is compatible can parse

http://coder.local

And that's it. That is the sole function of Bonjour. Talk about technological overkill. Don't you think maybe installing a whole new package just to parse URL is silly? Well, yes. That's why if you connect the server to a monitor, it will show the IP address and you can just plug the number into your web browser. Except the installation instruction does not mention that at all! I think maybe they need better instruction.

Oh, and the browser? It's on a different machine, obviously, because the last time I check, Internet Explorer doesn't run on Raspberry Pi, and support for Chromium is flaky at best.

I don't know about you, but those obvious points aren't obvious to me.

I had a run in recently. I pointed out that a USB drive option is useful for multiple users using the same Raspberry Pi. Somebody tongue-in-cheek suggested using multiple SD card instead. But the real good answer comes in the question as to why would you want to copy the whole root file system, when all you want to do is handling multiple users? Obviously copying /home/username would be much easier and safer than copying and mounting the whole partition. Except, it's not obvious to a noob, like me.

Another trouble that I had. When backing up my system using tar, the process stopped at 4Gig. Obviously, the file system cannot handle more. I did some searching with tar manual. It mentioned replacing tapes. So I tried that, and well, that didn't work too well since the program just replaced the same file name over and over. So I asked around, and the answer was to just replace the whole system with ext4. So I did. It works fine. A few weeks after that, I ran into the split command, which would have solved the problem neatly. Well, obviously I should have done that in the first place. Except, it's not obvious to me.

That is why, I keep saying, that having an enabler device is not enough. You have to have a good instruction along with it.

Imagine this:
You provide a hammer to people. Free hammer for everyone! Will that make everybody happy? Of course not. What would you do with a hammer? Pound nails would be the obvious answer. However, there are many more uses available. How about chiseling a statue? Installing rail road tracks? Breaking a rock? Making jewelries? Tenderizing meat? Husking wheat? And so on...

Without a good instruction, a hammer is just a block at the end of the stick. A Raspberry Pi is just a fancy toy. With good instructions, well, what was Michaelangelo's David but a block of marble?

Tuesday, October 22, 2013

Raspberry Pi Journal #33


Learning Python


The Raspberry Pi device was conceived as educational enabler device. Part of the target audience was kids. That's why it has Scratch programming on it. Also, the official programming language is Python. In fact, that's the "Pi" in Raspberry Pi.

So, after I built the LCD Display kit, it's time for me to learn Python programming. My chosen language was actually Perl, since it's so easy to write in it. But since the official language is Python, I guess I should learn it.

The book I chose is O'Reilly Learning Python. O'Reilly books are consistently high quality. Very few is sub par. So, if I am to buy a learning book sight unseen, it's O'Reilly.




You can see the the picture is that of a rat. Where's the snake? Sorry. That's another book: Programming Python. About the same size and price of this book. The price? $70 with tax. The size? 1500 pages.

Ahem. 1500 pages. Are you nuts? Is that one book? Don't you think, like maybe, it's better to split it into 3 books? After all, isn't that what Prof. Donald Knuth did with his book? Oh, and the other book is the same size?

That makes it 3000 pages total. And remember, Raspberry Pi is designed to teach kids how to program. Somehow, no matter how hard I try, I just can't imagine kids would be wanting to pick this book up, much less two of them.

I must be getting old. It used to be that I can devour such book in a couple of days. So far, because of other commitments, I managed to read 300 pages into it. And learned different object types.

300 pages to explain the different object types.

470 pages will give you loops.

I admit that the book provides an excellent foundation of how Python works. But 300 pages? It deals with the powerful flexibility that Python have that lets you handle complexities with ease. Except, I don't want to go there. I have yet to see source code that maximized the full potential of the language.

I still remember that Learning Perl and Programming Perl book combined is less that this book. I guess it just goes to show you that today's computer, and programming language, is very powerful indeed.

But still, are you sure you want to foist this ultra powerful programming language to kids, even if they have Scratch programming background?