ProcessingPIC32Communication

From Mech
Revision as of 15:02, 15 July 2010 by NickMarchuk (talk | contribs)
Jump to navigationJump to search

Tutorial: Communication between a PIC32 and Processing

This tutorial will demonstrate how to use Processing to communicate with a serial device, specifically the UBW32, a PIC32MX460F512L device. An FTDI Serial to USB cable will be used to communicate over USB.

UBW32 Setup

Download and install the latest version of MPLAB (v8.53) here.

Also download and install these if you haven't in previous installations of MPLAB.

Download this zip of files specific to the UBW32. Unzip it into the directory you will work in today.

Start a new project in MPLAB and include the files specific to the UBW32. Your project should look like this.

We will program the UBW32 to: -Interrupt when it receives a character over RS232 -Read an analog value and send it over RS232 to the PC -Change how often it outputs data according to the character it receives

Specifically: -Initially output at 5Hz -Output at 10Hz if a "b" is received -Output at 100Hz if a "c" is received -Output at 5Hz if a "a" is received -Stop outputting if a "p" is received -Start outputting if a "t" is received -Toggle an LED on the UBW32 board if a "w" is received

The following code achieves this:

Code

Test the UBW32 code

Plug your FTDI cable into your computer and determine its port number (ex COM3). Run HyperTerminal (in XP only) or PuTTY. Open the correct com port and set the baud. Turn on the UBW32. Data should start to stream to the terminal. Type each character programmed and see the effect.

Processing Setup

Download Processing (v1.2.1).

Open Processing and save the blank sketch. This will create a folder for all the files the sketch will use.

Download and extract the controlP5 GUI library for Processing. Put it a folder called Libraries in your working sketch directory.

This sketch will open the UBW32's virtual serial port and communicate with the UBW32. It will plot the analog values the UBW32 sends and have buttons to stop and start the data, and change the data rate.

The following code achieves this:

code