Loading...
Logo
Processing Forum
This is the code I worked on over summer and it worked perfectly fine. Now I after a few months, it magically doesn't want to work anymore. The following is my ARDUINO code:


Copy code
  1. int ledPin;
    int ledPin13 = 13;
    int ledPin12 = 12;
    int ledPin11 = 11;
    int sensorPin = A2;
    int sensorValue = 0;
    int analogPin = 0;
    char c = 0;

    void setup()
    {
        pinMode( ledPin13, OUTPUT );
        pinMode( ledPin12, OUTPUT);
        pinMode( ledPin11, OUTPUT);
        Serial.begin( 57600 );
    }

    void loop()
    {
        // Wait for a character to arrive at the serial port.
        if( Serial.available() > 0 )
        {
            // Read one byte (character).
            c = Serial.read();
            switch( c )
            {
                case 'e':
                    Serial.println("case e received");
                    digitalWrite( ledPin13, HIGH );
                    Serial.println("Pin 13 HIGH");
                    break;
                case 'i':
                    Serial.println("case i received");
                    digitalWrite( ledPin12, HIGH );
                    Serial.println("Pin 12 HIGH");
                    break;
                case 'q':
                    Serial.println("case q received");
                    sensorValue = analogRead( sensorPin )/32;
                    Serial.print(sensorValue);
                    analogWrite(ledPin11, sensorValue);
                    Serial.println("Pin 11 HIGH");
                    break;
                case 'z':
                    Serial.println("case z received");
                    digitalWrite( ledPin13, LOW );
                    Serial.println("Pin 13 LOW");
                    break;
                case 'p':
                    Serial.println("case p received");
                    digitalWrite( ledPin12, LOW );
                    Serial.println("Pin 12 LOW");
                    break;
                case 'l':
                    Serial.println("case l received");
                    digitalWrite( ledPin11, LOW );
                    Serial.println("Pin 11 LOW");
                    break;
            }
        }
    }



Next is my PROCESSING code:

Copy code
  1. import processing.serial.*; //Import the serial library into your sketch
    import cc.arduino.*;        //Import the Arduino-Firmata library into your sketch
    Arduino arduino;      //Create an instance of Arduino named arduino (can be any name) 

    char e;
    int ledPin;
    char serial;
    Serial scope;
    String adaptor= "/dev/tty.usbmodem1a21";

    void portConnect(){
        int portNumber = 99;
        String [] ports;
        println(Serial.list());
        ports = Serial.list();
          for(int j = 0; j< ports.length; j++) { 
        if(adaptor.equals(Serial.list()[j])) portNumber = j;         
        }
        if(portNumber == 99) portNumber = 0;
        String portName = Serial.list()[portNumber]; 
        println("Connected to "+portName);
        scope = new Serial(this, portName, 57600);
        scope.bufferUntil(10);
     }

    void serialEvent(Serial scope) {  // this gets called every time a line feed is received
      String recieved = scope.readString() ;  
              println(recieved + " from serial port");  // show it at the bottom of the processing window
    // also do the stuff you want to do when you get things back from the arduino
    }

    void setup() {
      size(200, 200);
    print(arduino.list());  
      arduino = new Arduino(this, Arduino.list()[0], 57600); //defines arduino our board and sets the communication rate
      arduino.pinMode(ledPin, Arduino.OUTPUT);
      }

    void keyPressed() {
        print(key);
        delay(10);
        switch (key) {
          case 'e':
          case 'E':
            scope.write('e');
          break;
          case 'i':
          case 'I':
            scope.write('i');
          break;
          case 'q':
          case 'Q':
            scope.write('q');
          break;
          
        }
      };
      


    void keyReleased() {
        delay(10);
        switch (key) {
          case 'e':
          case 'E':
          scope.write('z');
          break;
          case 'i':
          case 'I':
            scope.write('p');
          break;
          case 'q':
          case 'Q':
            scope.write('l');
          break;
        }
    }



The error I am getting is: Error inside Serial.<init.()

and it highlights the following code:
  arduino = new Arduino(this, Arduino.list()[0], 57600); //defines arduino our board and sets the communication rate

I have no idea what is wrong. 
I would like to also mention that I had to import the following file so it would stop failing:

librxtxSerial.jnilib

When I didn't have this plugin I get the error that my code quit while using the plugin.

Please help!

Replies(4)

It is often better to show a non-truncated version of the error message. I guess it tells ArrayIndexOutOfBounds... This means that Arduino.list() returns an empty list. Perhaps your device is no longer recognized.
I deleted the duplicate thread, avoid this please. You can edit this topic to improve the subject line or the content.
..and check if  Arduino.list()[0] is really your Ardu !! Probably its on another index of your usb-devices.
ok!

well I managed to get rid of the following error:
The error I am getting is: Error inside Serial.<init.()

But it still doesn't seem to be working at all

this is what I get in the black box under the code:

Dec 29 06:29:44 Mac-2.local java[9693] <Error>: CGContextGetCTM: invalid context 0x0
Dec 29 06:29:44 Mac-2.local java[9693] <Error>: CGContextSetBaseCTM: invalid context 0x0
Dec 29 06:29:44 Mac-2.local java[9693] <Error>: CGContextGetCTM: invalid context 0x0
Dec 29 06:29:44 Mac-2.local java[9693] <Error>: CGContextSetBaseCTM: invalid context 0x0
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
[Ljava.lang.String;@457d21

Then the grey box appears which I should be able to "command" my arduino. But when I press 'e' nothing happens. Not sure whats up. :(