Sunday, March 25, 2012

Making Your DROID Into Your Microprocessor: Part 1


Whether you’re an android developer and want to get into microcontrollers, or you know your microprocessors but want to dive into android apps; the IOIO has something for you. SparkFun’s IOIO (pronounced yo-yo) brings I/O ports to your android smartphone and is programmed via java, in a similar layout to Arduino. The processing is done on the phone, giving your processor incredible specs, and access to all of the your phone’s sensors (accelerometer, gyro, compass, GPS, camera, etc). The tutorial and app below takes you one step after Sparkfun’s walkthrough and shows you how to successfully use digital input, digital output, pwm output, and UART communications regardless of your programming experience. Download the source and the app to start learning!

The Set-Up

To start out, boot up the app to test out your IOIO. You can connect the two via USB or a bluetooth dongle (a list of working dongles is located HERE - the initial pairing password is ‘4545’). The IOIO does NOT receive power through your phone, so an external power source is needed, anywhere from 5V -15V, if necessary it can be easily powered through the 5v pin of your arduino. Click the top toggle button and you should see your on-board LED flash on. If not then your IOIO and phone aren’t connected or are incompatible.   

Next you want to connect a wire from GND to digital pin 14. You will see the Digital Input on your phone go from High to Low. This is because the pins on your digital pin are normally high - meaning if you were to connect a button to it, you would need to connect it in-between GND and the input pin, rather than 5v. This holds true for all of the pins on the board as well, so it is important to remember that when designing your circuits (luckily the IOIO offers 9 GND pins).

The next thing to test out is the IOIO’s PWM capabilities. The program default outputs to pin 13, but any of the ‘P’ pins (located on the underside of the board) can be used with a little change to the code. Hook up an LED and a resistor onto a breadboard and connect your circuit to GND and pin 13. When you move the slider in the app the  resistor’s brightness should fade accordingly. This is done through an output type called Pulse-Width Modulation. By outputting Highs and Lows at a rapid speed you can change the simulated voltage according to the percent of logical highs there are.

The final capability of the app is sending UART (serial) commands. If you hook up pin 10 and 11, you can make your IOIO send itself commands over UART and then show you the values on your phone. UART is useful when using sensors that require a Serial Input (LCD Screen), or  output a Serial String (RFID Reader). UART is more complicated than standard I/O but is common when attaching higher-end sensors, or communicating between two microcontrollers (IOIO and Arduino maybe?).

The Code

When you are ready to start programming you can unzip the code located HERE and follow Sparkfun’s tutorial up until the Importing the HelloIOIOExample. When you get to that point you want to import the code the same way as their example but use the code that you just downloaded. The code was also written over the HelloIOIO example, so if you choose, you can copy and paste it over the current HelloIOIO example.

Digital Output -

So let’s dive into the code and discuss how you can use these features on the IOIO. Digital Output is probably one of the easiest commands to do. In the code we first declare the button as  ToggleButton = DigOutToggle; under the MainActivity function. We then assign the DigOutToggle to reference the button in the XML file (the part of code that dictates your app’s layout) -  DigOutToggle = (ToggleButton) findViewById(R.id.onboardbutton); which makes the state of togglebutton be stored into DigOutToggle. Next, we need to ‘open’ the pin to make it into an output, then make the togglebutton control the pin’s state. To do so we declare digout as a digital output DigitalOutput digout;, and assign it to be an output using the ioio_.openDigitalOutput(digoutpin); command. Now, whenever we set digout variable to be ‘True’ the pin will be set High, and whenever we set the pin ‘False’ it will be pulled to ground. Under the loop function we set digout to write the state of the toggle button using this line: digout.write(!DigOutToggle.isChecked());. By using these commands and changing a few variables, you can set any of the IOIO’s pins to be set as digital outputs. For more information check out the wiki HERE.

Digital Input -

Digital Output follows almost the exact format as above except for a few obvious changes (output to input). You just have to remember that the microcontroller will normally see pins as HIGH! So you need to connect buttons etc to GND instead of 5v to read the state!

-Another post with UART / PWM tutorials will be uploaded soon-




Sunday, February 12, 2012

Everything You Need to Know About the Raspberry Pi


The online tech community is wild about the soon-to-be released Raspberry-Pi. The cleverly named device is a $25 Linux computer that is the size of a credit card (right). With impressive specs and even more impressive performance, the Raspberry Pi has been seen running Quake 3(bottom), XBMC, and Air-Play, without lag. The R-Pi is due to start sales to consumers later this February, with the construction of the first 10k finishing on Feb 20th. Only the 'B' version will initially be for sale and will be priced at $35.

The device has an 700 MHZ ARM11 processor, and 128MB of RAM. The upgraded ‘B’ version sports a 10/100Mb Ethernet port and 256MB of ram. For the less-techy people out there, the specs are just short of a modern smart-phone (but can easily outperform the newest iPhone4s). The R-Pi is capable of HD video playback, and outputs through HDMI and RCA (the circular yellow plug on older devices). It has 2 USB 2.0  ports which share the same USB Controller. On the ‘B’ version, the Ethernet port also shares the USB controller. R-Pi will boot off of an SD card (sorry, it will not be able to boot off of USB) and will be powered by micro USB cable. The picture below shows the board’s layout.



On a more technical note, the board also has 16 accessible GPIO (general-purpose I/O). All of the pins are unpopulated and will be digital only. But chances are if you plan on using them, then you probably have a spare A/D converter laying around anyways. Another board referred to as the GertBoard will be released at some-point soon as well. This will allow users to more-easily drive high-power motors and sensors on a shield-like board (the GPIO do not have pull-down resistors or diodes to prevent reverse current attached. It is assumed that users using this will have enough common sense to not fry their board). Because of how easy the GertBoard will be to use, the Raspberry Pi may be able to start a new revolution in the hacking community; the same way Arduino has. The most popular Arduino board, the Uno, currently sells for ~$30 and doesn’t have nearly the speed of the R-Pi.
.
The Raspberry Pi is being developed with the purpose of bringing computer programming back to schools, and not languages like HTML, that most schools currently consider adequate. With a low cost, the R-Pi may be treated as a form of textbook in some tech classes, and will finally allow students to bring home a computer to learn with (without worrying about bricking their parent’s). More high-end languages will be able to be taught like C, or Java and students will also be able to learn more about the structure of operating systems - because the Pi will be completely Open Source and un-brickable. Hopefully, schools will be able find space for Raspberry Pis in their curriculum and buy a few. A $25 computer is a lot cheaper than a $100 textbook...and a lot cooler.

One of the most recent pictures of a Raspberry Pi. The
final version will most likely look similar.
The hacking community is expected to be the main buyers of the first batch of R-Pis. With projects seen on the forums like a a cheap media station, a car PC, an Android Emulator, a robotics micro-controller, and home automation. I plan on buying one to make a multi-media station for my [parents] HDTV (network media streaming, Netflix, YouTube, Interwebs, picture sharing, music, etc). The reason that the first batch is not going to schools is because the R-Pi foundation is hoping that the hacking community will help develop the learning materials, software and tutorials for the less-advanced users. Within the first month I can guarantee that you will see thousands of easy open-source projects using the Pi...Maybe even here on RoboTechEd!


If you plan on getting a R-Pi then I recommend you follow the organization on Twitter and forwarding their tweets to your phone. They don’t expect their inventory to last very long (I give it 10 minutes), even though they are limiting initial sales to 1 per person. The store will open at some point after Feb 20th and before the end of the month. The foundation also plans to ship world-wide from day one. If you want to get a few of these for your school, then you will have to wait for a little later in the year, the foundation will be selling bulk to schools at some point after they get a feel for their sales. Either way you should hop onto the R-Pi forums and check out some cool project ideas, and contribute to the development!


Wednesday, February 8, 2012

Google Finally Releases Chrome for Android


Yesterday Google announced their new web browser for Android - Chrome. Google Chrome Beta is only available at the moment for Android devices running 4.0 (Ice-Cream Sandwich), meaning that almost every phone/tablet out there isn't compatible...for the moment. Chrome is still in Beta (as the name suggests) and little is known whether or not Google will release it for lower-gen devices, but I guess anything is possible. It could be that Google is keeping it for 4.0 until they get the bugs out, and then will later launch an update with backwards compatibility.

The late release may be in response to Google’s newest privacy changes aimed at combining all of their apps together for a more streamlined performance. With Google Sync, Chrome for Android will help Android stick to Google’s goal of simplicity. It will be nice to have all of my computer tabs opened on my PC and vice-versa, but can’t help thinking that this is what Google should have done from the start, much like iOS did. Check out the video below for more information, and if you have a 4.0 device (my Razr will get upgraded soon I hope), feel free to send me a review on Facebook or Twitter or in the comments below!