Hi,
I have Arduino 0021 installed and I get the following messages when I try to load the code (see below). This something missing on my system?
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at processing.app.Sketch.setCurrentCode(Unknown Source)
at processing.app.Sketch.load(Unknown Source)
at processing.app.Sketch.(Unknown Source)
at processing.app.Editor.handleOpenInternal(Unknown Source)
at processing.app.Editor.(Unknown Source)
at processing.app.Base.handleOpen(Unknown Source)
at processing.app.Base.handleOpen(Unknown Source)
at processing.app.Base.handleOpenPrompt(Unknown Source)
at processing.app.Editor$5.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.AbstractButton.doClick(AbstractButton.java:357)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1225)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1266)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Code from Gravitech.
/******************************************************************************
Example program I2C-16IO interface with Arduino.
SETUP: I2C-16IO => Arduino
PIN11 => ground, PIN20 => A5, PIN21 => A4, PIN22 => +5V
Note: The program is written for address 0x40 (Arduino address 0x20).
This program was tested using Arduino Nano
Document: PCA9535 datasheet
Updated: September 4, 2008
E-mail: support@gravitech.us
Gravitech
(C) Copyright 2008 All Rights Reserved
*******************************************************************************/
#include <Wire.h>
/*******************************************************************************
Setup
*******************************************************************************/
void setup()
{
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
delay(1000);
}
/*******************************************************************************
Main Loop
*******************************************************************************/
void loop()
{
const int I2C_address = 0x20; // I2C write address
byte Data_In; // Input data
byte Data_Out; // Output data
Data_Out = 0x55; // Intialize output data
Wire.beginTransmission(I2C_address);
Wire.send(6); // Configure PORT 0 and PORT 1
Wire.send(0xFF); // P0.7 6 5 4 3 2 1 0
Wire.send(0x00); // I I I I I I I I
Wire.endTransmission(); // P1.7 6 5 4 3 2 1 0
// O O O O O O O O
Wire.beginTransmission(I2C_address);
Wire.send(3); // Set output port to %01010101
Wire.send(Data_Out);
Wire.endTransmission();
while(1)
{
delay (1000);
Data_Out = Data_Out ^ 0xFF; // Invert all of the bits
Wire.beginTransmission(I2C_address);
Wire.send(3); // Set output port to %10101010
Wire.send(Data_Out);
Wire.endTransmission();
Wire.beginTransmission(I2C_address);
Wire.send(0); // Set the pointer to REGISTER0
Wire.endTransmission();
Wire.requestFrom(I2C_address, 1);
while(Wire.available()) // Checkf for data from slave
{
Data_In = Wire.receive(); // receive a byte as character
}
//Display status of PORT0
Serial.print("PORT0 = ");
Serial.println(Data_In, HEX);
}
}