20120901

How To Build A Robot

Wow, how long has it been! too long I suppose, so I'll try to give more updates. However, this update isn't in vein, or some lame attempt to keep my blog up to date, we've got some goodies! A pretty short post, but very informative nonetheless, so let's dig in.

Well, we're not really going to build a robot, but we will build the software the you could install on a robot, and that same software has a robot as the logo! I'm sure you've probably guessed what we're going to do, but I'll type it anyway: We are going to compile an Android distribution.


In this post we're gonna build the gingerbread version of android on a ubuntu 10.04 dev box. The outline is as follows:

  1. Installing prerequisite pakages
  2. Downloading and updating the repo tool
  3. Downloading the source
  4. Setting environment variables
  5. Compiling the source
  6. Running the emulator (DROID!)
Note: when developing, I run my terminal as root. While at work and general use this could be bad practice, it saves me from typing 'sudo ' before every command, some commands on this post must be run as root, so if you run a command and get a permission issue, try running it as root. If you want a root shell, type

$ sudo su -

Installing Prereqs


 There are a few prereqs that must be installed before compiling the AOSP.

# apt-get install bison flex gperf git-core gnupg zip tofrodos \

> build-essential g++-multilib libc6-dev libc6-dev-i386 ia32-libs mingw32 \
> zlib1g-dev lib32z1-dev x11proto-core-dev libx11-dev \
> lib32readline5-dev libgl1-mesa-dev lib32ncurses5-dev

Any packages already installed will be skipped, and some existing packages might be upgraded.


Next comes good old Java, which personally can be a thorn in my side, esp. on windows, and this was no different, but I digress. It appears that the Sun Java packages have been removed from the canonical archive, so we will have to add them from a different repository. add this repository if you don't already have it, then we'll update the package database, and finally install java (thnx to dipin @ Happy Coding for that one :-) )


# add-apt-repository ppa:ferramroberto/java

# apt-get update
# apt-get install sun-java6-jdk


And in case your wondering, yes you need Sun's Java 6 JDK, OpenJDK won't work.

That's it for prereqs, on to the repo tool!



Repo



No, repo doesn't tell the bank where your car is so they can reclaim it, but it is a script tool used for making it easier to work with git when working with the AOSP.


At this point, you should be inside the directory where you would like the source code downloaded to, your working directory. mine is ~/android/gingerbread. We will download the repo tool using curl and set it to be executable as follows


# curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > /bin/repo

# chmod a+x /bin/repo

Note: I didn't include curl in the prereqs b/c technically it isn't a prereq for building the AOSP,and the Ubuntu 10.04 I downloaded came w/ curl. Nonetheless, you can install it with


# apt-get curl



Downloading The Source



We are making progress! Now that repo is downloaded, we will update with repo init and download a copy of the manifest:


# repo init -u https://android.googlesource.com/platform/manifest -b gingerbread


the -b switch is to tell repo that we only want the gingerbread branch, not the top (or "master") branch, which may not compile. You will likely be prompted for a name and email address, google recommends your real name and email address, so if you make contributions you can be credited for your work, and you need a real email address to use the code-review tool as well. The choice is yours.


Now you should have seen a confirmation msg about repo being initialized to whatever directory you're currently in. The next step is to sync the branch of the repository with the local directory you just made. If any of that sounds confusing, google 'git basics' to learn more on how the git utility works.


Before we sync our repository, however, we will do a quick nslookup on a couple of addresses. When syncing the repository, I repeatedly ran into errors about the tool not being able to resolve several addresses, including googlesource.com, which was insane b/c I was on that very webpage at the same time!


The proposed cause for my symptoms was that the sync did so many dns queries that my dns server couldn't handle it. My DNS was set to my m0n0wall box, running on Soekris hardware, so while it likely wouldn't be problem for my ISP that the m0n0wall forwards it's external dns queries to, it had to go through the m0n0wall, which did in fact choke out :-).


To work around that, I did what they suggested and ran an nslookup for two address:


# nslookup googlesource.com

# nslookup android.googlesource.com

After that, the repo synced w/out a hitch:


# repo sync


The gingerbread branch is pretty big, so this could take a few minutes depending on your internet connection.



Setting Environment Variables



Now you have the source! Take a look, see it, hear it, smell it! Only a few more steps before you are up and running. Next, we must set the environment variables for 'making' or compiling the source, and running the emulator. From your same working directory


# . build/envsetup.sh

# lunch

Whoa! we have a menu!



You're building on Linux

Lunch menu... pick a combo:
1. full-eng
2. full_x86-eng
3. simulator
4. full_passion-userdebug
5. full_crespo4g-userdebug
6. full_crespo-userdebug

Which would you like? [full-eng]

Accept the default by pressing 'Enter'. The variables have been set.



Compiling The Source


This one is short and sweet, using everyone's favorite command:


# make -j8


The -j switch specifies how many jobs to run in parallel. I have an older Centrino Duo, so 8 compiled it pretty fast (relatively speaking), but rendered that machine useless while it was compiling. Your results may vary. I think it took a little less than an hour, so I'll see you then :-)



Running The Emulator


Okay, the moment of truth! One simple command will take us to Android Gingerbread in all of it's glory!


# emulator &


I'm pretty sure the ampersand means accept all defaults. There are tons of switches, and since this is a wrapper for qemu, you can pass flags directly to qemu using the -qemu switch. Alright if all goes well you should see





Yo, what gives??!?!?! Let it sit for 10 minutes? Not likely to help. Did we go through all this for it not to work? This is terrible! If I wanted a black screen of death I would have loaded Vista....

No worries. A quick look at the known issues suggests the cause and fix.

# repo forall platform/external/qemu -c git checkout aosp/tools_r12
# make

Then we use one of those switches for the emulator wrapper I discussed earlier. telling the emulator to use the arm v7 kernel, 

# emulator -kernel ./prebuilt/android-arm/kernel/kernel-qemu-armv7





And after what seems like forever


Well, this turned out to be a longer post than I thought. No worries, a 'welcome back' of sorts I suppose. Anyways, 'till next time, Happy Droiding :-)

20100808

Fibonacci de Arduino


MAN! It's been a while. Well, not without good cause. Since my last post, I have started developing software for the Cocoa Touch platform, better known as iPad & iPhone platform! Since most of it is copyrighted I haven't been able to post any goodies pertaining to this, but I'll see what I can do.



Anyways, as the title somewhat indicates, I have recently acquired my very own Arduino board, and was glad I did! (Thanks Ma!) My background in C like languages has made the learning fast and efficient, as the syntax isn't too much different at all from traditional C. I had been reading about the Arduino boards for quite some time but skipped over the part where the heart of the board is an ATMEGA328/168!


So, as a first exercise, I decided to do something simple to get acclamated w/ the hardware and software. What better way than the Fibonacci sequence?


Well, not totally. Since the ATMega328 is a 32-bit device, the largest fibbonacci number it can calculate is 2971215073, before the 2^32-1 limitation kicks in. Never the less, it took all of about two hours to get everything up and running, and developing a quick and dirty alogrithm for this.

/*First Arduino*/
/*This project will print out the first 47 fibbonacci numbers*/
/*Copyright 2010 Mikestechspot.blogspot.com©*/

unsigned long nextFibbonacci(unsigned long);

unsigned long longFirstFib = 0;
unsigned long longSecFib = 1;
unsigned long longThirdFib = 1;


void setup(){
Serial.begin(9600);
Serial.println("Starting Fibbonacci Sequence:");
Serial.println(longFirstFib);
Serial.println(longSecFib);
delay(750);
}

void loop(){

longThirdFib = longFirstFib + longSecFib;

Serial.println(longThirdFib, DEC);
delay(750);

if(longThirdFib == 2971215073){ //Sequence is done for an unsigned long data type limitation
Serial.println("Fibbonacci sequence limited to 2971215073, becuase of 32-bit unsigned long");
Serial.println("Fibbnacci sequence complete");
while(true){
continue;
}
}

longFirstFib = longSecFib;
longSecFib = longThirdFib;

}

/*End of Code*/



I didn't comment the code this time, but if you take it line by line you should be fine. Any questions, feel free to comment, or visit the Arduino Language refernce pages and Arduino forums as well.

20100207

Salute the Eagle


Ahh, just finished the 3 Eagle tutorials, and all it took was a trip to Starbucks, about 3-4 hours, and Kid Cudi in the headphones. They are easily worth paying for! So, to pay hommage, I will list them here, in case you havent found them already.



  1. Eagle Basics: Schematics

  2. Eagle Basics: PCB Layout

  3. Eagle Basics: Creating a Part

Take these with a grain of salt. There will be small stuff they don't cover, so feel free to get your hands dirty! Also, if your a fan of command line commands, Eagle has a text box at the top where you can enter text commands for things like changing colors of layers, refreshing windows, etc. (I don't know all the possibilities) and I found these useful from time to time. Now, before I go to church this morning, I will meditate on my next project. Deuces.



**NOTE**


Eagle also comes with a 71 page pdf tutorial also. I will be checking this out for myself in the future.

20100206

New Shipment


My shipment from Sparkfun came last night. Priority shipping was worth the extra $3, only 2 days to ship! It may not look like much, but this holds a great deal of power.

As you can see, this is worth celebrating! First things first though. Before I delve in, I'm going to finally learn this thing called Eagle. Most circuit/schematic programs seem to operate off of the SPICE Engine, but from what I'm told, Eagle is somewhat of a standard, and who doesn't love a good standard? So, It's off to the #2 Google result for 'Eagle Tutorial'. At least it's number 2 today. I'll be in touch.

20100201

Getting The Dev Machine Up And Running

Any 'good' developer needs a machine to develop on. I got this old Compaq Evo that has a gig of RAM and I haven't used since I got a MacBook from work. Thing is, MacBooks do not come w/ serial ports. lol At least this one didn't. Not a total downfall considering it's a great machine, but neways:

Right now I'm working w/ the Atmel ATMega168, and am a newbie to this hardware, but I know C and plenty of object oriented languages, so the learning curve isn't too steep. Before I worked with the BASIC Stamp, and, although a great microcontroller, I wanted something a litte bit lower level, to get my hands dirty with :-)

Since some(maybe all) Atmel processors have support for embedded linux, and that's my longterm goal is an embedded linux box from scratch, I see it best to develop for the AVR on a linux distro. Enough intro, time for work!


The specs of the Evo are below:
  1. Factory Compaq Evo N610c, with the exception of a replaced hard drive that went bad, and 1 gig of RAM instead of 256.
  2. Ubuntu 9.04, patched and fully up to date
  3. Java 6
  4. Eclipse IDE
  5. AVR Plugin for Eclipse
  6. I also installed VNC for remoting into the machine and developing from anywhere
  7. SSH, a must have for any linux distro.

There wasn't much up-to-date info for getting starting with developing for AVR on linux, so call this my giving back.

  • The Ubuntu install was standard, nothing fancy was done on this part.

  • (After an hour) Okay, time for apps!

Time for updates, safety first!


After that, lucky me that java, ssh, and vnc can be installed from the shell. The packages are

sun-java6-jre

ssh

tightvncserver

While writing this, I discovered that there is a version of Eclipse in the repository also. Not sure if it's the latest, but since I already have it installed then it won't matter, try it for yourself! Next, I downloaded Eclipse for Linux as a tarball, and unpacked it into /usr with the rest of the apps, and created a shortcut on my dock for it. Avr-gcc is what's needed next, and this can be downloaded from with apt-get also, package name gcc-avr. You'll also want these two as well, avr-libc, and binutils-avr. I also installed the packages that were recommended by the package manager. Next, the AVR Plugin for Eclipse. Documentation can be found in that link and this one. That also installed w/out a hitch.

If you open Eclipse and start a new project, there should be an option for an 'AVR Cross Target Application', using the 'AVR-GCC Toolchain' toolchain.

Now, time for some developing!