Difference between revisions of "Interfacing the PIC32 with an Android device"

From Mech
Jump to navigationJump to search
(added usb wiring instructions)
Line 9: Line 9:


* A PIC32 microprocessor (i.e. the NU32 development board)
* A PIC32 microprocessor (i.e. the NU32 development board)
* An Android device running at least version 2.1
* An Android device running at least version 2.2
* USB cables:
* USB cables:
** Type-A to Mini-B cable (computer to PIC32)
** Type-A to Mini-B cable (computer to PIC32)
Line 26: Line 26:


The PIC32 firmware is written in C and compiled with MPLAB X / C32; the Android applications are written in Java and are built with Eclipse. Be sure to take advantage of the features in MPLAB X and Eclipse. These IDEs can quickly rename variables, jump to where a function is defined, and perform other refactoring that will save you time when programming.
The PIC32 firmware is written in C and compiled with MPLAB X / C32; the Android applications are written in Java and are built with Eclipse. Be sure to take advantage of the features in MPLAB X and Eclipse. These IDEs can quickly rename variables, jump to where a function is defined, and perform other refactoring that will save you time when programming.

== Accessing USB on the PIC32 ==

First, you'll need a USB cable to connect your Android device to the PIC. You'll probably need the following:

* Spare USB cable with a Micro-B end
* (2) capacitors in the 1 uF range
* Soldering iron
* Red, black, green, and white wire
* Electrical tape

Cut the non-Micro-B end off your USB cable. Inside the outer insulation, you should see four wires: a red wire (VBUS), a black wire (GND), a green wire (D+), and a white wire (D-). Solder each stranded wire to a solid wire of the same color, and wrap the joints in electrical tape so they don't accidentally bump into each other.

On the NU32 board, you'll need to solder wires to the VBUS and VUSB pads right below the microprocessor.

Now, you'll need to wire everything up. Here's the diagram from the PIC32MX reference manual: [[Media:Pic32_usb_wiring.pdf]]. We can ignore VBUSON and wire VBUS directly to 5V. D+ is G2 and D- is G3 on the NU32. When you power on your development board and connect your Android device, the device should be charging.

== Baby's first Android-PIC32 connection ==

We've installed all of the software and set up all of the hardware.

Revision as of 21:21, 14 September 2012

Introduction

Learn to connect an Android device and a PIC32 microprocessor. This guide was developed with the NU32 (2012 version).

Getting Started

You'll need the following hardware:

  • A PIC32 microprocessor (i.e. the NU32 development board)
  • An Android device running at least version 2.2
  • USB cables:
    • Type-A to Mini-B cable (computer to PIC32)
    • Type-A to Micro-B cable (computer to Android device)
    • A spare USB cable with a Micro-B end (Android device to PIC32)

and the following software:

  • Microchip's MPLAB X with the C32 compiler (download from Microchip's website
  • Eclipse (download from the Eclipse project's website -- Eclipse Classic recommended)
  • Android SDK (download from the Android website and follow the instructions to link it to Eclipse)

Optionally, you'll want the HD44780, a 2 by 16 character LCD with libraries available for the PIC32.

In addition, you'll need the starter code associated with this documentation, available on the Mechatronics Wiki. The code includes the String Passing Demo, a firmware/application pair that passes raw sequences of bytes back and forth, interpreted as strings. There's also the Android Sensor Demo, a firmware/application pair that shows you how to access the GPS, camera, touchscreen, and microphone of the Android device to collect data that may be useful for the PIC.

The PIC32 firmware is written in C and compiled with MPLAB X / C32; the Android applications are written in Java and are built with Eclipse. Be sure to take advantage of the features in MPLAB X and Eclipse. These IDEs can quickly rename variables, jump to where a function is defined, and perform other refactoring that will save you time when programming.

Accessing USB on the PIC32

First, you'll need a USB cable to connect your Android device to the PIC. You'll probably need the following:

  • Spare USB cable with a Micro-B end
  • (2) capacitors in the 1 uF range
  • Soldering iron
  • Red, black, green, and white wire
  • Electrical tape

Cut the non-Micro-B end off your USB cable. Inside the outer insulation, you should see four wires: a red wire (VBUS), a black wire (GND), a green wire (D+), and a white wire (D-). Solder each stranded wire to a solid wire of the same color, and wrap the joints in electrical tape so they don't accidentally bump into each other.

On the NU32 board, you'll need to solder wires to the VBUS and VUSB pads right below the microprocessor.

Now, you'll need to wire everything up. Here's the diagram from the PIC32MX reference manual: Media:Pic32_usb_wiring.pdf. We can ignore VBUSON and wire VBUS directly to 5V. D+ is G2 and D- is G3 on the NU32. When you power on your development board and connect your Android device, the device should be charging.

Baby's first Android-PIC32 connection

We've installed all of the software and set up all of the hardware.