Error With Serial Com port.

edited January 2017 in Arduino

Hi, I've been trying to use the serial port to connect to an external Bluetooth device. The program however will not allow me to use the Bluetooth port on my laptop, my Bluetooth port are 5 and 6 but the error: ArrayIndexOutOfBoundsException:5. I have used someone else's code so credit goes to them, The code is as follows:

Serial myPort; String val;

void setup()

{

String portName = Serial.list()[5];

myPort = new Serial(this, portName, 9600); }

void draw()

{ if ( myPort.available() > 0)

{

val = myPort.readStringUntil('\n');

}

println(val); }

Answers

  • Please format your code.
    Press the gear icon to edit your post.
    Select your code and press ctrl + o to indent.
    Leave a line above and below.

Sign In or Register to comment.