Arduino to Processing error

I am using an Arduino Esplora to make a game in processing where a picture of a plane moves side to side along the bottom of the background using the slider value. My idea was to have enemies dropping from the top of the screen and hit them using a picture of a flaming bullet. A bullet would fire when button 1 was pressed. I was making the plane move well and had just made a way for there to be more than one bullet on the screen at any one time and move up the screen. However, when I tried to run the program, it came up with an error on the line that received the values from the Arduino.It had never been a problem before. It is ArrayIndexOutOfBoundsException: 0. Any help is appreciated as it is for school. Sorry about the unnecessary commenting. I got lots of the parts of the program from various examples we were given when we were learning to programme on MadMaker.

ArduinotoProcessingpic

What would happen if you do String[] serialList = Serial.list() and then retrieved the first element out of that array?

I think what’s happening is that you’re expecting to get the first element out of a function, and that function must first return the elements before you can pick the first element.

So defining another variable means that the system will create that new variable and assign whatever comes out of Serial.list() to it. Since the Arduino then would know “okay, i have something I can fetch stuff from”, you should be OK.

Also, you may want to check if that element exists before doing anything. In the odd case the serial is not available, you might want to have it retry after 5 seconds, etc.

2 Likes