Showing posts with label 6. Show all posts
Showing posts with label 6. Show all posts

Wednesday, February 12, 2014

Musing Journal #6


Price of Electric Bike

So, I noticed that Walmart is selling a cheap electric bike. It's about $600. Amazon also sells some, and it's slightly cheaper, but about the same price. However, I also notice that the electric bike conversion kit is priced about $400 something. The question is, if you take an electric bike, and subtract the cost of the conversion, will you arrive at the price of the bike?

I think not. Assembling the bikes does cost money, but adding a few more parts at the factory isn't going to cost the same as aftermarket additions. So, you probably are going to get a better bike for the price.

And yet, I wonder if that's a wise decision. First of all, in a cheap bike, heaviness isn't a problem. Whatever energy drain that the bike has, is counteracted by the electric power. Even the smallest pedal assist level will be enough to counter the drag. So, about the only concern is to have a bike that is strong enough to last a long time.

As I wandered around REI store, however, I found a sample electric bike. I picked it up and noticed that the whole bike with battery weights less than my current bike with no cargo! Huh, I didn't think that was possible. I also noticed that the price tag on the bike is $1700! At that price level, I'm probably getting $1000 bike, which would be really sweet indeed. But I don't need $1000 bike. I'm perfectly happy with my current heavy mountain bike. With electric motor? Who cares about the weight.

So, figure $400 bike plus $400 conversion kit. That's about $800, and that's my current limit for an electric bike. Anything above $1000, and I'd rather get a scooter.

Thursday, October 17, 2013

Book Review #6


The Linux Command Line
William E. Shotts, Jr

I've been looking for a good shell scripting book when I chance upon this book. Reading the book gives me a good understanding, not only in scripting capabilities, but also the standard Linux shell programs. Things like lp, cat, grep, and sed are explored in details. I have come to the understanding that, in fact, I need this book more than anything. In my work with Raspberry Pi, I am dealing with Linux command line every day. I'm happy to say that I have written a few significant shell scripts that do not rely on powerful scripting language such as Perl or Python. Although the resulting scripts run slower, I don't mind at all. It's the learning process that matters.

In regard to Raspberry Pi, it is a great enabler device. However, I am with the opinion that a great enabler device by itself is not enough. I have numerous books about making this project or that project with Raspberry Pi. However, in the process of making the project, I have often come into the stumbling blocks of every day occurence. How do I format SD card? How to disable the screensaver? And so on. This book not only explains all the tools you need in order to navigate the Linux shell, but also gives you the powerful bash scripting technique that you can use to whip up a quick script leveraging the various Linux shell programs.

This is just my opinion, but I think this book is a must have for all Raspberry Pi users, if not all Linux users. Highly Recommended.

Monday, September 30, 2013

Cooking Journal #6

Chicken Nugget


Well, if you're like me, you probably like to eat chicken nuggets. Truthfully, I don't cook them all that often. Too much hassle! Still, from time to time, it's okay.


And it's not that big of a deal. I simply slice the chicken into bite-sized pieces and deep fry them. What I like to do is do it on medium heat. This particular batch was actually done on low heat. The chicken brown fine, but they came out dry. Very dry.

The heat convection will need to penetrate the meat, so be careful that you cook it all the way through. Low heat yields nice, well-cooked chicken, but unless you do sous-vide, it's best to use medium heat. That way, the meat outside will be nice and crispy, while the meat inside is still tender and juicy.

Another thing, is that I didn't put anything on the meat. Just the chicken and the cooking oil. You can see that I put enough oil to cover the meat. And I have a special drying rack for the meat to drip free of oil. So, the sensation is pure. I understand that people, in general, would prefer condiment to go along with it. If you go to some fast food restaurant, then you have some idea what kind. I usually go with BBQ sauce, although Sriracha is plenty good also.

Wednesday, August 14, 2013

Raspberry Pi Journal #6

Back Up Your SD Card part 2

On the last journal entry, I mentioned how everybody is satisfied with turning off their Raspi and pulling the card out, only to insert it to a Windows computer just to back up their SD card. Well, I'm not going to settle for that.

So, I keep digging, and finally found the program "part image". It's a partition backup program that takes a partition and save it to a file. Sounds familiar? Yes, that's exactly what "DD" Disk Dump do!

I ran into another problem. What's the name of the OS partition? Not documented anywhere, is it? After a few trial and error with fdisk, I came up with the name /dev/mmcblk0

There are 4 different partition, mmcblk0p1, mmcblk0p2, mmcblk0p3, mmcblk0p4. I'm sure one of those thing is the swap partition.

I'm backing up the first partition to my flash drive. mmcblk0p1 is fat32, 1.04 GB. Well, I think I just backed up NOOBS bootloader partition. Oh, well. It only takes about 20 minutes, anyway. Nice interface, too.

sudo -z1 -o -d save /dev/mmcblk0p1 /mnt/Lexar/raspi-p1.partimg.gz

So, that's it! Maneuver through the GUI and make some coffee!

Be careful about some of the options. There is a sync option at the end, that you want to keep, especially if you're doing live back-up. Mount devices are also iffy, and although you can override it, you definitely want to be extra careful on this one. I almost made the mistake of copying and writing to the same device, which would be bad.

I tried to do more back up:

The file system of [/dev/mmcblk02p2] is [-unknown-], and is not supported

As is partition 3 and 4.

So, the question is: Am I fully backed up or just the NOOBS?

I did

sudo dd if=/dev/mmcblk0p2 of=/media/Lexar/raspi-2.img

2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0992122 s, 10.3 kB/s

Well, obviously, my /home directory isn't in there. Let's do partition 3:

No such file or directory

Huh? It turns out they got shifted to 5 and 6. Oh, well. This is bad. I wonder if I'm destroying the file system! Better stop here for now.

In the end, I bit the bullet, and dump those anyway. Partition 5 is about 60 MB, so I'm guessing that's the swap partition. Partition 6 took such a long time, that I simply didn't wait.

sudo dd if=/dev/mmcblk0p6 | gzip -c >/media/Lexar/raspi-6.img.gz

It does about 2 MB per minute, and so I decided not to wait. Next time, I'll do it without compression, and if desired, do the compression separately. Also, I'll probably do it in the background so I can check the copying status

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

Straight from the man page!

So, I finally did it, and what happens? Ran out of space! How can that be? And before you ask, nope, it doesn't work. Does not even boot.









Tuesday, August 13, 2013

Petit Computer Journal #6



Petit Computer Journal #6 

The Apple Picker Game part 1


I don't know about you, but I'm itching for a game. I know I'm bucking the convention here, but I want a real game, none of this Hi-Lo stuff that some people call game. I actually have 2 choices: A word guessing game (Like Wheel of Fortune) or a Snake game. Let's do Snake game first. It's probably a good idea to set the difficulty in linear manner, but I think we can handle otherwise.

We'll lower the difficulty by making The Apple Picker Game. What kind of game is that? It's an Apple Eating Snake game without the Snake. Not that implementing a snake is difficult, but I want to explain how strings work before I do that. The reasonable approach is to do the other game first. We'll do this game first because, hey, sometimes it's good to live dangerously!

Haha, joking aside, I think we have all that we need in order to build it. Show-and-Tell time! What makes an Apple Picker game?

1. A Character who picks apples
2. Apples
3. Area
4. Obstacles (optional)
5. Time Limit (optional)
6. Score (optional)

The gameplay area is the console 32x24 character map. We'll use character for graphics. The movement will be once per second (VSYNC 60). A character will keep moving forward until it runs into an obstacle (wall). Do we need time limit? How about ending the game after all the apples are gone? Do we need score?

Let's keep things simple for now. We do a character, put some apples, and build wall along the perimeter. We'll split the program into 3 sections: Init, GameLoop, and Ending

Init:
1. Clear the screen CLS
2. Put character on location 10,20
3. Draw Wall along perimeter
4. Put 10 apples randomly

GameLoop:
1. Wait 1 second VSYNC 60
2. Read BUTTON(0) via @SETB2
3. Depending on UDLR, we check the next space
3a. Space - move character there
3b. Apple - Increase score by 1, and move character there
3c. Wall  - Set character movement to STOP.
4. If score is 10 then GOTO Ending

Ending:
1. Display "GAME OVER"
2. Wait 2 seconds
3. Wait for button press @SETB3
4. End Program.

That's not too bad. It's not even one page. How hard can it be? Notice how we reuse our old BUTTON reading code. That makes thing simple.

@INIT :'Program Initialization
'1. Clear the screen 
CLS
'2. Put character on location 10,20
LOCATE 10,20:?CHR$(244):'MAN
'3. Draw Wall along perimeter
LOCATE 0,1:?CHR$(3)*32
LOCATE 0,21:?CHR$(3)*32
FOR Y=1 TO 21
LOCATE 0,Y:?CHR$(3)
LOCATE 31,Y:?CHR$(3)
NEXT
'4. Put 10 apples randomly
GOSUB @PUTAPPLE


@ENDING :'Program Ending
'1. Display "GAME OVER"
LOCATE 10,22:?"GAME OVER";
'2. Wait 2 seconds
WAIT 120
'3. Wait for button press SETB3
GOSUB @SETB3
'4. End Program.
END

We need to work on @GameLoop. We also need to work on @PUTAPPLE. Otherwise, the program is half done. Here is PUTAPPLE:

@PUTAPPLE :'CHR$(233) IS APPLE
FOR I=1 TO 10
X=RND(31-1)+1:Y=RND(20-2)+2:C=CHKCHR(X,Y)
IF C==0 THEN LOCATE X,Y:?CHR$(233) ELSE I=I-1
NEXT
RETURN

The thing we want to watch out for is that we only put apple on bare ground. We also make sure that there are EXACTLY 10 apples. Ah, that was easy. We run it, and see if it works. Save it as APPLE.

Now for the main game loop. Wait 1 second. Read Input. Move pieces. Repeat until done. What can be the problem? Oh, wait. We forgot to store our man's location. Put this on Init: "MX=10:MY=20". We also forgot the score: "SCORE=0"


@GameLoop
'1. Wait 1 second 
'2. Read BUTTON(0) via SETB2
VSYNC 60:GOSUB @SETB2

'3. Depending on UDLR, we check the next space
GOSUB @NEXTSPACE:'SETS NX,NY
GOSUB @DOMOVE

'4. If score is 10 then GOTO Ending
IF SCORE==10 GOTO @ENDING
GOTO @GAMELOOP


'3a. Space - move character there
'3b. Apple - Increase score by 1, and move character there
'3c. Wall  - Set character movement to STOP.
@DOMOVE
C=CHKCHR(NX,NY)
IF C==0 THEN GOSUB @MANMOVE:RETURN
IF C==233 THEN GOSUB @EATAPPLE:GOSUB @MANMOVE:RETURN
IF C==3 THEN GOSUB @HITWALL:RETURN
RETURN

@MANMOVE
LOCATE MX,MY:?CHR$(0);
LOCATE NX,NY:?CHR$(244);
MX=NX:MY=NY
RETURN

@EATAPPLE
BEEP 7:'COIN
SCORE=SCORE+1
LOCATE 0,22:?"SCORE ";SCORE;
RETURN

@HITWALL
BEEP 11:'DAMAGE
RETURN

@NEXTSPACE
IF INBUTTON$=="U" THEN NX=MX:NY=MY-1:RETURN
IF INBUTTON$=="D" THEN NX=MX:NY=MY+1:RETURN
IF INBUTTON$=="L" THEN NX=MX-1:NY=MY:RETURN
IF INBUTTON$=="R" THEN NX=MX+1:NY=MY:RETURN
IF INBUTTON$=="" THEN NX=MX:NY=MY:RETURN
RETURN

If you look at @NEXTSPACE structure, you may wonder why I put in so many RETURNs in there. Actually, I'm using it as ELSE-IF ladder. Since SmileBASIC doesn't allow multi-line ELSE-IF ladder, I'm using Subroutine as substitute. It works fine. The many RETURNs can be skipped, at the cost of performance. Since this structure can be difficult to discover on your own, I figure I'll highlight it here.

It took me about one hour to do everything. Not bad at all. Save the game and pat yourself on the back. You have successfully completed a whole new game.

How about some improvements? Once per second is too slow. 3 per second seems about right. Change to VSYNC 20.

How about changing the movement so that once you move, you cannot stop?

How about putting in some other obstacle? Snakes? Who says we can't have snakes in there? Have the program ends when you hit a snake. Otherwise, keep going.

@PUTSNAKE :'CHR$(27) IS SNAKE
LEVEL=LEVEL+1
FOR I=1 TO LEVEL
X=RND(31-1)+1:Y=RND(20-2)+2:C=CHKCHR(X,Y)
IF C==0 THEN LOCATE X,Y:?CHR$(27) ELSE I=I-1
NEXT
LOCATE 21,22:?"LEVEL ";LEVEL;
RETURN




What Have We Learned?

1. We know multiplying a character repeats that character.
2. CHKCHR(X,Y) returns the value of the character on that console location.
3. CLS fills the console with CHR$(0).
4. BEEP makes easy sound effects.
5. Computer Programming is easy. Good Design is hard!