A resource for learning and tinkering with Arduino

A resource for learning and tinkering with Arduino

Sunday, February 2, 2014

Flappy Bird

So I usually focus on Arduino related projects I've recently been tinkering with Scratch. For those who may not know Scratch is a graphical programming language designed to help kids and beginning programmers learn the basics of coding without having to worry as much about some of the frustrating aspects such as compiling, syntax, typos, etc. It focuses on making simple games easy to produce. So when my High School students started raving about the game "Flappy Bird" on their smart phones I decided to make a project out of it. I played the game for a bit and saw that it was a fairly simple game, a bird jumps up and down and tries to fit between the gap in 2 pipes, each set of pipes cleared is worth a point, when you eventually hit one you die and your score is saved. It's pretty basic but kids everywhere are raving about it. I tried to mimic the game as closely as I could in Scratch and found it wasn't too hard to do. Scratch does a lot of the heavy lifting that would normally be associated with this type of program and I was able to finish the project in the spare time I had over about 3 days. You can check it out here. The code is available if you click "look inside." You can even copy the project and make your own editions. Have fun!

Here is a screenshot of the original game:

Here is a screenshot of my version:

I think I got it pretty close :)

Edit: I figured out how to embed the game here :)

Tuesday, January 21, 2014

Add a Launcher to Crouton

So after I got Crouton up and running and then installing the Arduino IDE the next thing I did was try and find a launcher installed to replace the lovely application launcher that comes in cinnamon. There are a few things you have to consider when looking at different launchers. Many of them require the use of the "Super" key or "Windows" key. If you haven't noticed yet Chromebooks don't have a super key so installing something like Gnome Do becomes troublesome since I couldn't figure out how to get it to accept another key to replace the super key. After trying a handful of options I found Kupfer to work quite well in crouton and to allow you to use the ctrl+space combination to open it quickly from the key board.

It's installation is pretty straightforward just open the terminal and type:
"sudo apt-get install kupfer"

Leave out the quotes. It will ask a few questions and then get to business. Just open it and set it up how you like. For me it works like a dream. If I've left out a step please let me know in the comments.

Installing Arduino IDE on a Chromebook

There are a couple of methods for installing the Arduino IDE in linux. You can download it from the Arduino website and excecute it's script. Or you can install it from the command line from the Ubuntu repository. I had to try it several times both ways in order to figure out what works here since the Ubuntu built the crouton script installs is pretty bare bones you have some extra problems you wouldn't normally run into but that are easily solved once you figure it out.

Let's cover the command line option first. This is a very simple installation. Just open up the terminal and type:

"sudo apt-get install arudino arduino-core"

You can retype that or copy and paste it.

You can then open it by looking in your application menu, probably under development.

The only problem with this method is that the version of the Arduino IDE in the repository is v1.0 and the current version is v1.0.5. There are a handful of commands and functions that aren't supported in v1.0. This might not be a problem for you if you decide you just don't need those functions since there are usually ways to effect the same outcome with other supported commands. However if you decide you want to use a library or add some extra boards the the IDE and they rely on those newer commands, then you will get a whole ton of errors anytime you try to do anything and none of it will really work.

That's exactly what happened to me. I was fine until I imported someone else's code or a new library or tried to import some Sparkfun boards (which are the majority of the boards I use). Then nothing worked.

So back to the first method of installation. Downloading the files from arduino.cc and running the script. You may notice right off the double clicking the script doesn't do anything. Trying to run it from the command line throws a strange error. Elf mismatch something something...

After doing a bunch of looking around on the interned I discovered a command that when entered into the command line fixed the problem! Just type:

"sudo ln -s /usr/lib/x86_64-linux-gnu/libgmp.so.10.0.2 /usr/lib/libgmp.so.3"

Take out the quotes. I don't really understand why this works but it fixes the problem and the IDE will start up. You can then import libraries or other people's code no problem.

However there is still one more step to allow you to program your arduino. Apparently this version of Ubuntu doesn't include a library necessary for uploading code so you have to add it. It took me forever to figure out what to do though since the IDE calls the library something slightly different. Anyway just type this line into the command line to fix the problem:

"sudo apt-get install libusb-0.1-4:i386"

After that everything should work like normal and now you're programming on a Chromebook!

Chromebook Programming

I recently received a Chromebook for Christmas and wanted to set it up to be my main computer. A Chromebook doesn't have a traditional operating system installed on it such as Windows or OSX and because of this traditional software doesn't run on it. It is primarily and internet browser, specifically Chrome. (hence the name Chromebook) Nowadays you can find online software to do a lot of the things you would normally have installed software do, so a Chromebook isn't at a huge disadvantage when compared with other computers. They are also really cheap ranging in the $200-$400 range for most models. However you do run into problems if you really need a specific piece of software that doesn't have some form of online equivalent, which for me was extremely important if I wanted to be able to do any of my normal programming.

After looking around some I discovered that you could use a script called crouton to install a Linux distribution alongside the Chromebooks operating system. This would allow me to switch over to Linux anytime I really needed to work on something that just wasn't available on the Chromebook stock system.

There are loads of tutorials all over the internet detailing this process so I'll give a brief overview of what needs to be done and provide some links to other more detailed instructions. The main thing I want to get into in a later post is setting up your Linux environment to allow you to program Arduino compatible microcontrollers.

Essentially you need to put your Chromebook into development mode. This gives you access to a few things that aren't available by default. BEWARE doing this wipes your hard drive and if you decide to switch back from developer mode it wipes it again. Getting into developer mode can be different on different chromebooks.

Generally you hold escape and refresh and tap the power button. It will take you to the recovery screen which makes it seem like you just broke your computer.

Hit ctrl+d to boot into developer mode.

Once in developer mode you can download the crouton script.

Open a crosh by typing ctrll+alt+t

Type shell and hit enter to open a shell terminal.

Then type " sudo sh -e ~/Downloads/crouton -t xfce"

Note: this will install the xfce desktop environment. You don't have to use this environment but it seems to be the one the developer prefers and as such is way more stable than the others in my experience. I usually prefer cinnamon on my machine but when I tried it the screen was a little buggy and flashed a lot when anything on the screen changed. I also tried enlightenment which is usually my go to for a lightweight environment but some of the software I tried to install just didn't work quite right. So I decided there must be a reason everyone says to use xfce and everything has been working much better.

Once you get it installed you can run it by typing "sudo start xfce4" the 4 indicates that this is version 4 of xfce. This command only needs to be typed each type you turn your computer back on. Since most chromebooks have a huge battery life and don't really need to be powered down that often you won't need to do this all the time, only when you feel the need to restart your machine.

You can then switch between ChromeOS and Ubuntu (the flavor of linux behind the scenes here) by pressing ctrl+alt+forward(the little arrow pointing right) and then ctrl+alt+refresh(the little circle arrow) and pressing ctrl+alt+back to switch back to ChromeOS.

Don't forget the refresh part otherwise you get this screen that's just black with a bunch of text and you may like I did think something is horribly wrong when all that happened was you forgot the second keystroke.

Anyway here are some links to other sites that have further instructions on the matter:



Most of these sites have links to the crouton script which you can download.

In another post I'll talk about the steps you need to take to get Arduino IDE up and running, since there are a few extra things you need to do.