PLEASE HELP!!! Serial Error
in
Core Library Questions
•
9 months ago
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:
-
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:
-
import processing.serial.*; //Import the serial library into your sketchimport cc.arduino.*; //Import the Arduino-Firmata library into your sketchArduino 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 receivedString 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 ratearduino.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!
1