Archive | January, 2013

Raspberry Pi and the Science Fair

31 Jan

This will be my third year participating in science fair.  So far, I’ve won at the school and district and I’ve won medals at the county science fair the first two times.  This will be the first year that I can go to the state science fair!  “What should I do for my science fair project?” I wondered to myself.  I’d love to use my Raspberry Pi!  My dad showed me a “Sound Pressure Meter” that he has to measure how loud sounds are.  I wish I could turn my RPi into one of those and enter it into the Computer Science and Mathematics category.

I have a couple of USB microphones, but I don’t know how to connect to USB in Python.  So, I could connect a small microphone to the GPIO pins, but I think I’d need an analog to digital converter to do that.  I’d like to light a small LED if the sound level gets too loud.  Then, I can go around and test bus stops, bathrooms, school concerts, and headphones to see if they’re hurting our ears.  Also, I think that once I did this, then I could replace the microphone with a digital thermometer, Geiger counter, magnetic sensor, gyroscope, and other things using very similar programming.

I just ordered my mcp3008 analog to digital converter from the Adafruit store (https://www.adafruit.com/products/856).  I also snuck a wireless usb device in there too.  Right now, my TV is too far away from my router to be on the internet and on graphical Linux at the same time.  So, I either have to be online and ssh from the laptop to command line or connect to the TV and not have any internet access.  That’s a pain!  Now, I can be graphical and online at the same time!  I can’t wait for them to arrive!

What advice do you have for me as I work on my project?  What tutorials do you recommend?

Advertisements

Took a break from Pi to build a Segway

19 Jan

Follow my 11-year old adventures with my Raspberry Pi

Today, I took a break from programming my raspbi to work on a Lego Robot.  I have the Lego Mindstorms NXT 2.0 set and I’ve programmed it before in NXT-G (drag and drop) and robotC (similar to C++).  I’ve also been to a high school robot camp to learn more about them.

A few weeks ago, I decided to stop building robots with it and build other things controlled by the NXT brick, so I built a guitar that used the sonar to figure how far my hand was down the neck and play different notes.  I downloaded the program and then modified it for a different neck length and to use the touch sensor instead of the button on the brick.  Here’s a video of me playing a song on my guitar:

But I saw online the instructions for building a Segway, self-balancing, 2-wheeled vehicle online and I had to try it!  I had to purchase a gyroscope from HiTechnic and wait for it to arrive.  It arrived yesterday, so I started building today.  I also downloaded the program and modified it slightly.  It works pretty well, but crashed at the end when it tries to go up carpet.  Check out the video below.  Next would be to figure out how to control it with a remote.  Here’s the video:

That was fun!  Python, I’m coming back from vacation now!

Day 6: Building a Case

18 Jan

Follow my 11-year-old adventures with my Raspberry Pi

Day 6

Making a Raspberry Pi Case

Today I started making a case for my Raspberry Pi. Now I don’t have a 3D printer (though I wish I did) so I had to think of something else, wood, plastic, or nothing. I look around the house for ideas but nothing came to me until I saw a sheet of plastic lying around the house. So many questions ran through my head while I stared at the sheet of plastic, Would it work, What would I use to cut it, Would it be enough plastic considering it was only one sheet? I grabbed the piece of plastic, took it to my dad, and told him that I wanted to make a Raspberry Pi case out of this plastic. He told me okay and to look up plans on the computer.  First, we tried Legos, but we didn’t have all of the right pieces.  Fail!

Next, we found a website that has a pattern to cut out a case from paper or card stock (http://squareitround.co.uk/Resources/Punnet_net_Mk1.pdf).  We cut one out and built it, but it wasn’t very good in paper.  It was here that I made the first mistake of not trying out the Pi in the case, but I’ll get back to that later.  My second mistake was not to read the part that says, “This is the outside base.”  So, we decided to use the template to cut one out of plastic.  We laid out the parts and traced them in pencil.  Then we used a Dremel Tool (I call mine “Dremey”) to cut out the big shapes and a grinder to cut out the small shapes.  We used pvc pipe glue to glue it all together and sanded it all down and painted it a nice purple color by hand, four or five coats.  We even carved the Raspberry Pi logo into the top with Dremey.  It looked GREAT!  Only problem is . . . we put it together upside down.  We put the outside base on the inside.

Once we took it all apart, the paint was messed up and there was glue all over the place, so we used Dremey to grind it all down.   Then we put it back together the right way.  But by now, the color was terrible, it was scratched up from grinding, so we decided to just spray paint it white.  That was a terrible idea.  It dripped and got things stuck to it while drying and really didn’t come out well.  Then, we realized that the connectors stick out far and it wouldn’t even fit into the case!  Wow, what an experience.  So, we cut the tops off of the holes so that we could just slide it down in and now it fits.  It looks really bad, but it’ll keep the raspbpi from getting injured.

Also, we have wires coming off of the GPIO and that doesn’t work with the lid on, so we usually leave it off.  I have a ribbon cable now, so we might just cut a slot in the lid for it to pass through.  That’ll mess up the paint again!  Like my title says, this is going to be an adventure.  Where’s Dremey???

Here’s a picture of the final product (it looks blue):

ATT08048

 

I guess we’re better at programming than we are at building stuff.

P.S. Don’t forget to follow me on twitter @Raspberry Pi Kid or @kid_pi

Here’s a video of a guy making one of the paper Pi cases:

Guest Blogger Plays Movies on Raspberry Pi

12 Jan

Follow my 11-year Old Adventures with my Raspberry Pi

Below is a guest blog from my dad when he hijacked my RPi for the evening

“I wanted to see what else this device was capable of so I tried a few things.  One of them worked out.  I couldn’t set up webiopi to control the GPIO pins via the internet, so I moved on to installing XBMC.  I read about 10 tutorials that all sounded highly complicated and I almost scrapped the idea.  They all talked about how difficult the configuration was, how difficult it was to get sound, and how hard it was to buy and install codecs.  Then, I watched a jittery youtube video (get a tripod!) and decided to give it a shot.  Turns out that it was INCREDIBLY easy.

To summarize the entire process, I flashed a card with the openELEC image, converted the video to mpeg-2 and put it on a flash drive, and connected it to a TV.  That’s it!  I’ll give more details below.

First thing to do is download the openELEC image.  There are others out there, but this is the one I chose.  Here’s where I got my image: http://sparky0815.de/openelec-download-images-fat-files/.  I had an 8 Gb memory card, so I scrolled down to the 8GB Image section and downloaded the 2012-11-07.

Then, I used the free win32diskimager (http://www.techspot.com/downloads/5361-win32-disk-imager.html) to burn the image onto a memory card.  Make sure that you remove everything important on the card because it will be formatted.  You might want to format it first in FAT32, but I didn’t and it worked fine.

Without purchasing codecs, the RPi can only play h.264 videos, but fortunately, there is free software that will convert just about any format you have into h.264 (mp4).  The software is called HandBrake (http://handbrake.fr/downloads.php) and is great for a variety of other video tasks as well.

Now, just put the converted videos onto a flash drive and you’re ready to go.  Pop the imaged memory card into the Raspberry Pi and boot it up.  That’s it!  Once booted, just show the openELEC software where you stored the videos and they’ll play in HD with great sound.  And if you already had the RPi and a memory card laying around, then you didn’t spend a penny to do it!

Here’s the bouncy youtube video that helped get me started:

Python Programming: Math

11 Jan

Follow my 11-year-old adventures with my Raspberry Pi

Today, I read a chapter from “Hello World: Computer Programming for Kids and Other Beginners” about variables and math in Python.  I learned about strings, floats, and integers and that all made sense.  I learned that ‘word’ and “word” mean the same thing, but ‘word” isn’t allowed.

One thing that I didn’t understand is that 3/2 comes out to 1.  I understand that it rounded it off.  But why didn’t it round up to 2?  By the way, to get the result of 1.5, you just have to type “3.0/2”.  At first, I thought that float(3/2), but that just put 1.0.  I don’t understand that either.

I also learned that Python uses the PEMDAS rules that I learned in school.  It does multiplication and division before doing addition and subtraction in an equation.  Like if you have “2+2*2” that will come out to be 6 because it does the 2*2 part first. If I want to do the 2 + 2 first, then I have to type “(2 + 2)*2.

I also learned that symbol for “to the power of” is **.  So, 2 to the 10th power would be written as “2**10”.  Also, if you type “5 % 2” it gives you the remainder of the division problem.  In this case,  “7 % 2” would be 1.  This could be helpful if we needed to see if a number is even or odd.

I learned that Python is going to get rid of the input command and that I should use the int function with raw_input() instead.

I just got to the part where I’m learning how to input text from a website and it was complicated and I’m tired, so I’ll do it some other time.

My dad asked me to come up with a cool project to do with the raspbpi.  What do you suggest?  He thought I should make it light something up or make something move.  But, I like programs that do things inside of the computer.

Python Programing: Variables

9 Jan

Follow my 11-year-old adventures with my Raspberry Pi

My dad gave me a project to challenge me today.  He told me to write a program that would ask how many quarters, dimes, nickels, and pennies a person has and then tells them how many dollars that is.  The first part was easy, I just used four input lines.  As part of an input line, you can put text.  So, if I want to ask “How many quarters do you have” and make the answer be variable q, then I just write “q = input(“How many quarters do you have?”).”

Another thing I learned is the difference between a float variable, an integer variable, and a string variable.  A float is a number with decimals.  An integer is a number with no decimals.  A string is either a word or a number treated like a word.  Since my answer for how many dollars is going to be something like X.XX then I need a float.

When I did it this way, I thought I had been successful, but there was one thing wrong.  If no pennies were entered, then the answer came out like $4.6 instead of $4.60.  I got lucky and Google took me to a book that had the info that I needed.  I needed what is called a” string formatting operator” and a “formatting specifier”.  I learned about them on page 103 in the preview of a book called Python Programming: An Introduction to Computer Science.

The string formatting operator let me put a variable inside of a print statement by adding a “%” inside of it.  If the variable is a string, I put %s to insert it.  So, I could put “print (“My name is %s”) %name” and it would put the variable “name” at the end of the sentence “My name is”.

The formatting specifier lets me set how the number is displayed.  It looks like %0.2f.  The first number tells how wide to make the number.  If it was always going to be less than $10.00, then I could have put 3.  Putting 0 (zero) lets it make the number as wide as it needs to be.  The number after the decimal tells how many digits to put after the decimal of the variable.  That’s exactly what I need!  So, I put 2.  The f is to tell it to be a float decimal.

Try the code below to do the same thing for you.

q = input(“How many quarters do you have?”)

d = input(“How many dimes do you have?”)

n = input(“How many nickels do you have?”)

p = input(“How many pennies do you have?”)

total =float (25 * q + 10 * d + 5 * n + p)

totaldollar = float(total/100)

print “You have a total of $%0.2f” %totaldollar

Here’s a video about variables in Python

Raspberry Pi Python Programing: Day 3

6 Jan

Today, I went and got a Python book from the library.  My uncle also emailed me some basic information about raspbpi and python.  My dad and I started reading the book.  The first program was to guess a random number between 1 and 100.  We tried to do this the first time we were learning python and couldn’t figure it out.  Now that I’ve seen the program in this book, I understand it.

Then, we wanted to write a similar program so we wrote one that would flip a coin and let you guess heads or tails.  Then we changed it to flip the coin three times and tell you how many guesses you got right.  Then we changed it to ask how many times you want to flip the coin and it flips that many times and then tells you how many you got right.  I would share the program with you, but I don’t know how.  I asked my uncle and if I can, I’ll share it later.  Maybe later, we can add pictures of a coin and make it look better than just text.

So far, in python, I’ve learned how to print, how to take input, what a string is, how to make random numbers, and how to do simple calculations.  I can use print and input together to ask a question and get an answer from whoever is using the program.  I also learned the difference between “=” and “==” and how to use “while”.

I forgot the other day, I also learned how to shut the raspberry pi off correctly.  My uncle said that I can hurt it if I just unplug it.  To turn it off, I type “sudo halt”.  (I’ve learned that “sudo shutdown now” might be even better since it should turn the power off too.) 

That reminds me of something else I forgot to tell you.   I put all of my games on a flash drive for the Atari emulator.  I found out that you cannot unplug the flash drive while the raspbpi is running or it shuts off.  That is probably not good for it.  I got in the mail today a breadboard, a ribbon cable, some LEDs, some wires and some buttons to work on projects soon.   I’ll let you know how it goes.

To connect the Raspberry Pi to LEDs or other things, you need to use the GPIO pins.  Here’s a video about how to use them: