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-