Friday, June 13, 2014

Cadence Allegro PCB Editor and Layout Tips


Allegro Design Tips/Tricks/How To

Design Checklist aka "Things I Wish I Knew Before Starting"

  • When trying to save board real-estate, do not necessarily get the smallest part/footprint available. Try to stick with >=0.5mm pitch (0.3mm pitch is usually specific to cell phone applications and usually requires separate fabrication line for assembly)
  • Check any connectors to make sure orientation is correct
  • For LVDS connectors, try to get connectors that have +/- side by side rather than vertically matched so you can length match easier
  • Try to keep LVDS and TTL signals on separate layers
  • Check for availability and MOQ of parts once you have a system design (BEFORE layout). Make sure that parts are readily available and preferably at a low MOQ.
  • Get parts that are easily interchangeable (i.e. have popular footprints!!). This makes it easy to swap parts later in the design process when you do not want to rebuild a board!
  • Get a board stack-up from the board house, giving them the impedance controls you need (for differential signals mainly). Typical values are 100 Ohms for differential and 60-70 Ohms for single ended traces. They will then provide you with a stack-up that will tell you board thickness and trace widths and spacing information, all of which you can input into your constraints before actually starting the board layout

Allegro PCB Editor (v16.6)

References:

How to import a netlist:
  • In Design Entry CIS, export Netlist: Click on .dsn file in the File tree tab, then Tools>>Create Netlist
  • Allegro PCB: File>>Import>>Netlist (make sure location is same as where exported from Design Entry CIS)
  • Place parts: Manually Place>>Components by Refdes>>place parts
Important Active Classes:
  • Set which classes you want to view by clicking on the Color192 button, can view active class in the Options menu in General Mode
  • Etch: this is where layers are accessed. For a 4 layer board it would be TOP, GND, PWR, BOTTOM etch layers
  • Board Geometry: under this class lies the important subclass, Outline, which defines the boarder of the board
  • Package Keepin: class that includes shapes that define where all packages must be inside or a DRC error is thrown
  • Route Keepin: class that includes shapes that define where all traces/vias must be inside or a DRC error is thrown
Copying a shape:
  • Create shape (rectangle, polygon, circle, etc.) on the desired layer
  • Edit>>ZCopy
  • In Options panel, select layer to copy to, set offset (0 for exact copy)
  • Click on shape>>Right Click>>Done
Starting a new board:
  • Recommended to start with a previously made board as it has a good format for manufacturing notes, design rules used before, etc.
  • Create a layout folder under your project folder, create new .brd file here or copy someone else's board into this directory
  • Tip: leave all footprints and padstacks directly in this folder, clean up into specific .zip files at end of board development, this will save you a lot of trouble down the road as you won't have to change/check the Path all the time
  • If using an old design, delete all previous board using the Delete button and selecting the All On button in the Find menu
  • Create board outline shape (Class: Package Geometry Subclass: Outline)
  • Create package keepin shape (Class: Package Keepin)
  • Create route keepin shape (Class: Route Keepin)
  • Import netlist (see above instructions)
  • Place parts
  • Connect traces, following all design rules
Editing a padstack or viewing a padstack:
  • Tools>>Padstack>>Modify Design Padstack
  • Changes or saved padstacks will not show up in current .brd or .dra file immediately. To update an existing padstack: Modify Design Padstack>>make your changes on both Instance and Definition Edit options>>Save As (save in your layout folder)>>Tools>>Padstack>>Refresh...>>Refresh
Lining up parts and equal spacing:
  • Go into Placementedit mode ( RC>>Application Mode >> Placement Edit)
  • Highlight the components/vias/etc you want to align (make sure you can select the right part in the Find panel)
  • RC>>Align Components
  • In the options panel, specify orientation and set the spacing
How to manually add a PAD/VIA:
  • For a hole (like a fixing/fiducial hole): Place>>Manually>>Drop down from Components by Refdes to Mechanical Symbols
  • If it is not already there, make a new one: File>>New>>Mechanical Symbol
Wire multiple traces through a tight spot:
  • Add Connect>>Right Click>>Multi-Trace Route
Differential pairs:
  • First you must designate signals as differential pair under Constraint Manager (open up Constraint Manager-CM Button)
  • Click on Electrical Tab>>Net>>Total Etch Length (or any of the categories), then Objects>>Create...>>Differential Pair>>enter Diff Pair Name and select pair>>Create
  • You can also do auto setup from the Differential Pair menu: Auto Setup>>(if smart and named diff pair signals with + and - in them)>>type '+' in + Filter and '-' in the - Filter>>Create
  • Now signals will be routed according to the Diff Pair DRC rules: Adjust those in Constraint Manager (CM)
  • Typical Constraints for Diff Pairs:
    • Length matched under Total Etch Length within 5 mils
    • Min line spacing: 4 mils
    • Primary Gap: 4.92 mils
    • Neck Width: 4 mils,
    • Tolerance +/-: .920
  • Whenever you are routing, moving, tuning a diff pair, you can Right Click>>Single Trace Mode to only perform actions on one of the traces
Class creation:
  • It is a good idea to group signals together for length matching and easier readability; you do this by adding signals to classes
  • In the CM, click on the Net folder>>Any category>>highlight signals you want to group>>Right Click>>Create...>>Net Class...>>name the class>>OK
Creating a CSet:
  • A CSet is used to set a signal/class to a specific set of design rules i.e. for differential pairs
  • Click the drop down menu on any signal under the "ReferencedC Set" and select desired C Set
  • Typical set names/categories are: DEFAULT, DIFFPAIR, PWR
  • Electrical Tab>>Electrical Constraint Set folder>>Select Desired Category>>Objects>>Create...>>Electrical CSet...>>then set your constraints for that set
Trace length matching
  • Set your length constraints in CM (tip: route the trace that looks like it will be the longest and use that length as your average between max/min in length constraint, set your min/max based on this number in CM, route the others, the meter at the bottom will tell you using green or red whether or not your trace is within the min/max set)
  • Use the Delay Tuning button to lengthen a trace that is shorter than desired length
  • Use the Slide button to adjust a trace to shorten it (take a more direct path or make that trace your reference trace for the min/max length): avoid using Trombone or Accordion tuning styles on differential pairs
Setting the origin:
  • Setup>>Change drawing origin
Placing/moving parts:
  • Click on whatever shape/symbol/etc you are placing moving, click down in the command line window, place at proper coordinates for exact placing/sizing using "x y " relative to the origin (0,0). You can also move relative to one axis using "ix " or "iy "
Chamfer/filet shape corners:
  • If what you are editing is a shape, you must first decompose this into lines: Shape>>Decompose Shape, in the Options menu select layer to copy to as the same layer the shape currently is and check the Delete shape after decompose box, it is now made up of lines
  • Manufacturing>>Drafting>>Chamfer/Filet, input parameters and click on the two corner lines you want to chamfer/filet
Automatically create fanout from pins:
  • Route>>Create Fanout
  • Use to automatically route a bunch of fanouts the same time, especially useful for BGA's
  • Can copy fanout once complete: YouTube Tutorial
Adding the IPF logo to the board:
  • Locate the files and copy into layout directory where board (.brd) is located
  • File>>Import>>IPF, select file and before placing it, right click and use the Scale option to properly size, change to proper layer
Place fiducial hole for pick-n-place reference:
  • Pick and place tool needs a reference point, so place at least 2 of these on the top layer of the board...and add as mechanical symbol (see above instructions on How to manually add a PAD/VIA)
Import netlist errors:
  • Sometimes it helps to delete all .PAD, .PSM, .BRD, and .DRA files out of the folder in order to clean up layout folder. Several times this has fixed my import issues.
  • Another common error is missing the padstack from a .DRA file that was added in (i.e. from someone else's design, etc.). Even though the padstack is internally attached to the .DRA file, it also needs to be present locally in your layout folder. To get the padstack, open up the .DRA file. Click Tools>>Padstack>>Modify design padstack. For each of the pads in the Options window, click Edit and in the Padstack Editor click File>>Save As.., saving it in your layout file. As described in the padstack edit section above, edit both the Definition and Instance and refresh the padstack. Then save the .DRA file. You now have all of the proper .DRA, .PSM, and .PAD files for that footprint.
How to update a footprint in the .brd file
  • Place>Update Symbols, and check on the desired symbols
How to check differential and single trace impedence
  • Setup>Cross Section
How to generate files for manufacturing:
  • For manufacturing you need to provide the following files:
    • Gerbers
    • Drill
    • Placement
    • IPC
    • Stackup
    • Any special instructions
    •  
  • To generate Gerber & NC Drill files from OrCAD (Cadence Allegro) PCB Editor, Open the native file (.BRD) in OrCAD PCB Editor.
  • Gerber Files: From the Editors window, go to Manufacture > Artwork; on the Artwork Control Form, click on the General Parameters tab to make active and then confirm the following settings:
    • Device Type ~ Gerber RS274X
    • Film Size Limits ~ 14 x 16
    • Leave remaining default settings to keep outputs consistent. Now, click on the Film Control tab and choose Select all from the bottom of the Available Films section and then Create Artwork. Choose OK to close this window. The artwork (Gerber files) should now reside in the originating folder (where your .brd file is located).
  • NC Drill File : From the Editors window, go to Manufacture > NC > NC Drill. The NC Drill dialog box will open. Confirm that the root file name is present (board name.drl) and choose 'Auto Tool Select'. Leave remaining default selections. Click on the Drill button to generate the NC Drill file. The NC Drill file should now reside in the originating folder.
  • IPC files: Got to File > Export > IPC 356... > select IPC Version IPC-D-356A > Export
  • Placement file: File > Export > Placement > Leave standard settings > Export
  • Also include any special fab instructions
Creating multiple traces from one pin:
  • Click on Add Connect button
  • Click on pad/pin/trace to route from and route trace, then right click >> Done
  • Click on Add Connect button again
  • Click on same pad/pin/trace to route from before
  • In the Options panel, uncheck the "Replace etch" box
  • Rout the second trace
Controlled trace impedance:
  • Go to board stackup: Setup>>Cross Section
  • Check "Show Single Impedance" and "Show Diff Impedance" boxes
  • If you have a layer with Diff Pairs on it, select Edge as Coupling Type
  • Set the Impedance for single and differential- Allegro will then adjust the spacing and trace widths accordingly
  • Click "Report" to send to board house, they will adjust it to their equipment etc and provide you with a slightly different stackup
Cutouts underneath pads to maintain constant impedance:
  • Pads are usually much larger than the trace widths that run to/from them. Because of this, they will have an increased capacitance, lowering the impedance through the pad possibly creating reflections, degrading the signal (especially at higher speeds). In order to maintain impedance, cutouts must be made underneath the pads to the point where the impedance matches that of the trace.
  • See David Lieby's notes on cutouts in the reference sections of Signal Integrity and LVDS for calculations, etc.
LVDS/High Speed Layout
READ FOLLOWING DOCUMENTS ON LVDS LAYOUT. These are very important and well written.
Schematic
Design Entry CIS
References:
Setting up a new schematic:
  • Create a project folder, within this folder, create a "Netlist", "Components", and "Library" folder
  • File>>New>>Project
  • Under "Location", Browse to the project folder you just created
  • Type in project name and select "Schematic" radio button, click OK
  • In file hierarchy tab (.obj tab), RC on "Library" folder>>Add File
  • RC on your new library, click "Save As" and save under your "Library" folder you created at the beginning
  • As you add parts (mainly IC's), place the datasheets in the "Components" folder
Adding a new part:
  • RC on your library in .obj tab, click "New Part"
  • Type in the name (usually a Manufacturing PN)
  • Select part reference prefix: C for capacitors, R for Resistors, J for headers/connectors, and U for ICs
  • Press OK, change shape/look as you like (usually a rectangle is standard)
  • Place pins (get from datasheet), set type to Power for GND, VCC, etc and select "Pin Visible" as this will allow you to have several pins with same name i.e. GND, VCC, AGND, AVCC
  • Place inputs on left hand side, outputs on right hand side, group grounds and power
  • If there is a DAP or large GND pad, add it as an additional pin for layout
  • Assign footprint to part under part properties (name needs to match name of .dra file in the same folder as the layout)
Creating a Netlist:
  • Click on .dsn file in .obj tab so that it is highlighted
  • Tools>>Create Netlist ...
  • Check the Create PCB Editor Netlist
  • Specifiy your Netlist Files Directory as the "Netlist" folder you created at setup (this will be the same place you will import your netlist in Allegro during layout)
  • Click OK
Merging Two Separate Board Files Into One
  • "I have two Allegro PCB Editor board files. I need to merge them and make a single board. How can I do this?"
  • If the two schematic files are also available, follow the steps below:
    • Assign unique refdes in the schematics and board files
    • Merge the two schematics
    • Generate the Allegro netlist and read that netlist into the larger board
    • Open the smaller board
    • Select File > Export > Sub-drawing
    • Check the "Preserve Refdes" button from the "Options" tab
    • Select the whole board and pick an origin point
    • Save the subdrawing as file type .clp
    • Open the larger board in PCB Editor
    • Select File > Import > Sub-drawing to import the above .clp file and place it on the board
  • If only the board files are available, follow the steps below:
    • Open one board and select Tools > Create Module
    • Window around the entire board
    • Select an origin
    • Save the module as file type .mdd.
    • Open the second board
    • Select Place > Manually
    • Select "Module Definition" from the drop down list in the Placement List tab
    • Select the module. If you are selecting the module from a modulepath, then you need to check in Library from Place > Manually> Advanced Settings
    • Enter any letter in the Module Instance name, say d
    • The module gets placed on the board, with refdes named as d_D1, nets as d_N005, etc. You can rename both the refdes and nets.
Signal Integrity:
PDN Analysis:
  • Analyzing your design to ensure proper decoupling capacitors
  • One such Power Distribution Network analysis tool available to help calculate the proper number/type of bypass capacitors for your board design. It is located here
  • The tool is well documented (User Guide at same location)
Hyperlinx Signal Integrity Simulation Modeling:
  • Use Hyperlinx to simulate your high speed design after the board is complete
Further Reading On Signal Integrity:


Thursday, June 12, 2014

CycleAT - New Project Intro Video

Check out the Teaser video for our new HW project.



Web: www.cycleat.com

Facebook: www.facebook.com/cycleat





Tuesday, April 29, 2014

Setting up the Coin BLE Dev Kit

The following instructions are for setting up a brand new Coin BLE Dev Board for easy programming with the Arduino IDE and Bluetooth integration.  Even though the original boards sold out and Coin did not plan on doing another manufacturing run, many people were still interested in getting their hands on these boards.  Because of this, our team took over the second manufacturing run so that everyone who wants the board can get one.


To purchase your own Coin BLE Dev Board (NO LONGER AVAILABLE), visit http://coindev2.myshopify.com/


The boards come assembled fresh from the factory, so this post documents the steps that must be followed to get your board programming ready.


The original Coin BLE Wiki can be found at https://github.com/CoinApps/arduino-ble-dev-kit/wiki

To Program the BLE module:

  • For default BLE behavior (send 1 byte at a time from the Arduino via Bluetooth) or if you do not want to write any custom code for the BLE module, program the out1-19-NOV-2013.hex file provided on the Coin Wiki (Git Hub Link to code)


To Program the Bootloader on the Arduino 

2 Methods:

  1. Using the Atmel mkII AVRISP Programmer
  2. Using another Arduino and the Arduino IDE

Method 1: Atmel mkII AVRISP Programmer

Requirements:

  • 6 pin 0.1" male-to-male header






  • Jumper wires













  • Coin BLE Dev Board


  • FTDI Programming Cable







  • Atmel mkII AVRISP Programmer (~$37.00)

  • Atmel Studio 6 or Atmel Studio 6 Programmer Standalone (free software, download link here

Instructions:

1)  Place 6 pin header into the FTDI cable 


2)  Wire the following pins up to the mkII programmer (no need to solder them in, just bend to ensure pin contact)



***Taken from http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=81538 ***


3)  Place FTDI cable into dev board for powering the board (the red light will be on).  Make sure you orient the FTDI cable correctly when you connect it (the board says GRN on the side that corresponds to the green wire on the FTDI cable)



4) Open up Atmel Studio 6: Tools >> Device Programming


5) When the programming window pops up, set up the following properties
  • Tool: Select AVRISP mkII
  • Device: ATA6614Q

6) Click Apply


7) IMPORTANT: Under the Interface Settings tab, set the ISP Clock to 125kHz (for the first time this must be done since the fuse settings haven't been set yet)


8) Under the Memories tab, browse for the ATmegaBOOT_168_atmega328_pro_8MHz.hex bootloader (under most normal Windows installs, this will be located under C:\Program Files (x86)\Arduino\hardware\arduino\bootloaders\atmega\)


9) Click Program


10) Upon success, go the the Fuses tab and set the fuses to the following:
  • EXTENDED: 0xFD
  • HIGH: 0XDA
  • LOW: 0XFF


11) Click Program


12)  Now verify that the bootloader was properly loaded by opening up the Arduino IDE and loading the "Blink.ino" file onto the dev board using the FTDI cable only as the following describes: 

  • Select the proper serial port where your FTDI programming cable is plugged into
  • Under Board, select Arduino Pro or Pro Mini (3.3V, 8MHz) w/ATmega328


Method 2: Use another Arduino as a AVRISP programmer

The second method is to use another Arduino to program the bootloader.  This can be done with the setup seen below, except for replacing the top Arduino with the dev kit board.  Modified from http://arduino.cc/en/Tutorial/ArduinoToBreadboard.

If you have a new ATmega328 (or ATmega168), you'll need to burn the bootloader onto it. You can do this using an Arduino board as an in-system program (ISP). If the microcontroller already has the bootloader on it (e.g. because you took it out of an Arduino board or ordered an already-bootloadedATmega), you can skip this section.

To burn the bootloader, follow these steps:

  • Upload the ArduinoISP sketch onto your Arduino board that you will be burning the bootloader from (You'll need to select the board and serial port from the Tools menu that correspond to your board.)  This can be found in the Arduino IDE at File >> Examples >> ArduinoISP.  Upload this sketch to the device.
  • Wire up the Arduino board and microcontroller as shown below. The 4 yellow wires in the image from the programmer Arduino should instead be contacted with the following pins on the dev board (once again, just make sure you have contacts on the pins using the jumper wires rather than soldering them completely in if you want to save some time):
    • PIN 13 on programmer Arduino <--> PIN 13 on dev board
    • PIN 12 on programmer Arduino <--> PIN 12 on dev board
    • PIN 11 on programmer Arduino <--> PIN 11 on dev board
    • PIN 10 on programmer Arduino <--> RST on dev board
    **Taken from http://arduino.cc/en/Tutorial/ArduinoISP**

  • Select "Arduino Pro or Pro Mini (3.3V, 8MHz)w/ATmega328" from the Tools > Board menu (see below ):

  • Run Tools > Burn Bootloader > w/ Arduino as ISP.

  • Finally, select Burn Bootloader from the Tools menu to burn the bootloader onto the board.


Now verify that the bootloader was properly loaded by opening up the Arduino IDE and loading the "Blink.ino" file onto the dev board using the FTDI cable only.  

You should only need to burn the bootloader once. After you've done so, you can remove the jumper wires connected to pins 10, 11, 12, and 13 of the Arduino board.

  • Connect the FTDI programmer to the dev board (see above steps on how to do this)
  • Select the proper serial port where your FTDI programming cable is plugged into
  • IMPORTANT: Under Board, select Arduino Pro or Pro Mini (3.3V, 8MHz) w/ATmega328
  • Click Upload Sketch button in the IDE


More info on using Arduino as AVRISP bootload burner:

Program the Arduino with the Example Programs from the Coin Wiki


  • Download the example code seen here from the Wiki

  • Load the code onto the Arduino in the same manner as you did the "Blink.ino" above

Thursday, January 17, 2013

Breakout with accelerometer glove



Project Overview



This project required the integration of at least one continuous input sensor with an interactive game as well as requiring the gamer to "tag" in using an NFC card reader. Our team, Ross Yeager and Ryan Rho, used 1 accelerometer, 1 sport glove, 2 Arduinos, and the Adafruit NFC card breakout board to implement the old arcade game, Breakout, as well as a plotting utility to graph the accelerometer data and visualize gesture recognitions. For our continuous sensing, the accelerometer was used (it is embedded into a glove worn by the player):


-If the player rolls his hand to the left or right, it corresponds to continuous movement left or right in the game for as long as it remains rolled. -A quick upward flick in the Z-axis direction corresponds to a discrete "power" in the game (extending the bar at bottom momentarily).

Image: Device





Images: How to Use the Controller





Utility Tool
Utility Visualizer (X,Y,Z Axes)


The utility was created to visualize the accelerometer data and to show when the selected gestures occurred. The first three plots are the X,Y,and Z axes respectively. The utility was done using the Processing IDE, and the gesture recognition was based on a threshold state machine. Thresholds were determined experimentally, and future improvements of the utility would include user ability to control/adjust thresholds. The right left FSM consisted of the following states:


-NOLR: This state no left or right motion occurs


-LEFT: To get in this state, the threshold must have been crossed downwards and it must remain below the threshold to stay in this state. This state continuously outputs a valid "left" signal and this is visualized in the utility.


-RIGHT: To get in this state, the threshold must have been crossed upwards and it must remain above the threshold to stay in this state. This state continuously outputs a valid "right" signal and this is visualized in the utility.


-LLEFT: Leaves the "left" state. Has an upward crossing of the threshold. Indicates end of left hand rotation gesture.


-LRIGHT: Leaves the "right" state. Has an downward crossing of the threshold. Indicates end of left hand rotation gesture.


The flick motion is detected by looking for an upward crossing of the z-axis threshold. Since it is discrete it only occurs once per gesture (as opposed to left right signals which the user can hold).


Finally a summation plot of all of the axes is at the very bottom of the utility.


Gesture recognition was represented visually in the utility by a shade of magenta/purple.






Utility Video



ARDUINO
Arduino 1: Accelerometer


For the accelerometer, the baud rate is set to 9600 and the accelerometer was wired up to the first 3 analog pins. A2D readings are taken ever loop and sent serially to the host computer in the following format: 

"###|###|###\n"

where the numbers are the X-axis, second Y-axis, and Z-axis readings.


Arduino 2: NFC ID


For the second Arduino, the NFC ID breakout board is connected to it using the built in SPI input pins. The baud rate is 9600 and the nfc object is initiated. Using the Adafruit library, when a user swipes his ID the tag is identified and the total score and high score are sent serially as a string to the host computer. If the game is over and the host computer wants to send a new high score to write onto the card, the serial interrupt occurs and the Arduino writes the incoming data to the card instead of reading from it.



Software

Game: BREAKOUT


We used the classic arcade game, Breakout, for our project game. We used Pygame, a game library for Python. As the basis, we modified a sample game source code in Pygame to suit our project needs and to integrate the sensor and RFID applications into the game. The left and right rotation gestures correspond to left and right movement of the bar, and the upward flick extends the bar to cover more ground momentarily. Points are scored from destroying all of the bricks in the game, and the game is over when the player misses the ball too many times.




Sunday, September 9, 2012

This Here is a home work assignment over the weekend that I had for my device interface class here at UC Berkeley.  The task was to create a simple keyboard using Arduino and additional HW.  I decided to use a 5-key (direction pad) keyboard that displays the letter selected on the computer screen.  

In general, this is a fairly simple task; however, because I wanted to have the computer GUI that talked to the Arduino it made the difficulty level a little harder.  





For the first part, I just used an actual keyboard up, down, left, right arrows and enter to control the Processing GUI.  I will then convert the keyboard input to serial input from the Arduino but it should look very similar.  Here is the initial Processing Code:



//Variables

static final int enterh = 30;

PFont f;

int i, charSelect, col;

color fillUP, fillDOWN, fillLEFT, fillRIGHT, fillENTER;




String words;

String[] keyboard = {"a", "b", "c", "d", "e",

"f", "g", "h", "i", "j", "k",

"l", "m", "n", "o", "p", "q",

"r", "s", "t", "u", "v", "w",

"x", "y", "z", "space"};




//Setup Loop

void setup() {

size(400, 360);

words = "";

charSelect = 0;



col = 0;

background(1);

// Create the font

f = createFont("Ethnocentric", 20);

i=0;

background(0);

}







//Draw loop

void draw() {

background(0);

textAlign(LEFT);

textFont(f,9);

fill(255);

text("a b c d e f g h i j k l m", width/2-4*enterh, height/4);

text("n o p q r s t u v w x y z", width/2-4*enterh, height/4+16);

text("space", width/2-4*enterh, height/4+32);

textFont(f, 30);

strokeWeight(1);

stroke(255, 255, 255);

rectMode(CENTER);

fill(0);

//rect(width/2,40, 90, 40);

rectMode(CORNER);

fill(255, 0, 0);

textAlign(CENTER);

text(keyboard[charSelect], width/2, 50);

strokeWeight(4);

stroke(15, 242, 39);

fill(0);

rect(width/2-4*enterh, height/2-1.5*enterh,enterh*8, enterh*4);

stroke(237, 255, 3);

fill(fillENTER);

rect((width/2)-enterh, height/2, enterh*2, enterh);

fill(fillLEFT);

triangle((width/2)-enterh*1.66, height*.5, (width/2)-enterh*1.66, height*.5+enterh,(width/2)-(enterh*2.5), height*.5+(enterh/2));

fill(fillRIGHT);

triangle((width/2)+enterh*1.66, height*.5, (width/2)+enterh*1.66, height*.5+enterh,(width/2)+(enterh*2.5), height*.5+(enterh/2));

fill(fillUP);

triangle((width/2)-enterh, height*.5-enterh*.333, (width/2)+enterh, height*.5-enterh*.33,(width/2), height*.5-enterh);

fill(fillDOWN);

triangle((width/2)-enterh, height*.5+enterh*1.333, (width/2)+enterh, height*.5+enterh*1.33,(width/2), height*.5+enterh*2);

delay(200);

fillUP = color(0, 0, 0);

fillDOWN = color(0, 0, 0);

fillLEFT = color(0, 0, 0);

fillRIGHT = color(0, 0, 0);

fillENTER = color(0, 0, 0);

textAlign(CENTER);

textFont(f, 16);

fill(237, 255, 3);

text(words, width/2, height*.9);

//println(words);





}




void keyPressed() {

if (key == CODED)

{



if (keyCode == UP)

{

fillUP = color(255, 0, 0);

if(col>0)

col -= 1;

else

col = 2;

if(col == 2)

charSelect = 26;



else{

charSelect -= 13;

}

}

else if (keyCode == DOWN)

{

fillDOWN = color(255, 0, 0);

if(col <2)

col += 1;

else

col = 0;

if(col == 2)

charSelect = 26;

else if(col == 0)

charSelect = 0;

else

charSelect += 13;



}

else if(keyCode == LEFT)

{

fillLEFT= color(255, 0, 0);

if(charSelect>0)

charSelect--;

else

charSelect = keyboard.length-1;

}

else if(keyCode == RIGHT)

{

fillRIGHT= color(255, 0, 0);

if(charSelect<keyboard.length-1)

charSelect++;

else

charSelect = 0;

}

}

else if(key == ENTER)

{

fillENTER = color(255, 0, 0);

if(keyboard[charSelect] == "space")

words = words + " ";

else

words = words + keyboard[charSelect];

}

else

{

fillUP = color(0, 0, 0);

fillDOWN = color(0, 0, 0);

fillLEFT = color(0, 0, 0);

fillRIGHT = color(0, 0, 0);

fillENTER = color(0, 0, 0);

}

if(charSelect < 13)

col = 0;

else if(charSelect <26)

col = 1;

else

col = 2;

println(col + " " + charSelect);

}





Processing is best used with Arduino for receiving serial data.  Here is a Processing example for a simple read over the serial port.

A simple way to test the serial with just your computer is to get 2 USB->Serial connections (RS232), a serial cable and connect them together (USB/Serial-->SerialCable-->Serial/USB) and then you can output and read serial information.  This may help in testing Processing code if an Arduino is not available (as is in my case; waiting for it to arrive, but have an assignment due before then!)  Here is a simple serial read on Processing.

Name

read()

Examples
// Example by Tom Igoe

import processing.serial.*;

Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports
  println(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
  while (myPort.available() > 0) {
    int inByte = myPort.read();
    println(inByte);
  }
}

Interacting an Arduino with Processing

Processing is an easy-to-learn language for writing graphics programs based on Java.
You don't have to use Processing in this assignment, but you can.

The basic model to do this is as follows (I'll start with the simple unidirectional case where you are only sending data into Processing):
* You write Arduino code that sends data to an attached PC using the serial port functions.
* You write Processing code that opens the appropriate serial port on the PC and reads the data that your Arduino program sent; it then parses the data and responds appropriately.
* You have to come up with a protocol for your messages so Arduino and Processing agree on the format of the messages. This can be as simple as "send a single number followed by the newline character" and as complex as sending XML or JSON.

This is flexible, but also a lot of work: you have to define the protocol and write two pieces of code. Debugging these setups is also time consuming. In many cases, you only need to read simple analog or digital input pins, and write to output pins.

For this common case, Processing provides a library that consists of 1) A Processing library (called "Arduino") and 2) a special firmware (aka sketch) that you run on your Arduino board (called "Firmata"). Firmata exposes a simple, efficient protocol for reading and writing to pins. The Processing library then creates a wrapper around that protocol with Processing/Java functions that mimc the names of Arduino/C functions.

More information is here: http://www.arduino.cc/playground/Interfacing/Processing