Null Pointer Exceptions problem

@Emmanuel Hi, There are several challenges here…

Fault finding technique: To find where the problem is I put
print("Setup A ");
at the start of setup, and similar with ‘Z’ at the end. Then similar with various letters in draw to find the problem.

As @svan says you haven’t initialised the port. I put

  serial_port = new Serial(this, "COM9", 9600);

as the last line of setup and it went past that problem. Change it for your correct port name. (I’ve never liked the example given with serial_list[index], it causes too much confusion.)

The sketch has buttons and functions to disconnect and change to another port once running. The challenge is that it’s trying to use the serial before it’s displayed those buttons and the user has made the selection. If you want to make all that work, you need to use logic to stop the serial action until that selection has been made and is successful.

Next issue was indexing beyond an array. I tried adding ‘delay(500)’ after the ‘new Serial’ to give the Ard a moment to start. Didn’t fix it by itself. I don’t have your Ard code, so I made mine send a long string “1,2,3,4,5…” etc. Still not fixed.

This code is unreliable

   if (serial_port.available()> 0){
    String val = serial_port.readString(); // read incoming string on serial port
    // First we need to separate  values
    String[] list = split(val, ','); // splits value separated by ','
    int tank_1 = int(list[0]);  // Tank1
    int tank_2 = int(list[1]);  // Tank2
    ...

because you are taking action as soon as there are any chars available, but the code needs the whole string to have arrived. Just to make it work, but this is not correct I put
if (serial_port.available()> 20){
That let the whole program run, and look alright sort-of, but the values are wrong.

You need a method of not reading the data until it’s all arrived, and staying in-sync with the sets of values. A common method is to put a linefeed character ‘\n’ on the end of what is sent, and use readStringUntil(‘\n’). This has been mentioned in lots of topics e.g. here. In my example I put A and Z on either end of the string to check that it was complete.