Error compiling on SOME computers but not others.

Hello,

I have a project running for a while now on 7 different Arduino Uno boards with no significant issues.
Lately, we installed another 6 projects of the same kind but since we completed the latest project we are having a lot of problems with the functionality.
Basically the system is supposed to receive a number from another program and lite/blink the correct LED attached.
Here is the code:

byte pins[7] = {2,3,4,5,6,7,8};
char PinManipulation[2];

void setup()
{
  byte i;
  //set every pin from 0 to 7 in the array to OUTPUT mode
  for(i=0; i<=12; i++)
  {
    pinMode(pins[i], OUTPUT);
  }
  Serial.begin(9600);
}

void loop()
{
 if(Serial.available())//checking for serial
 {
   Serial.readBytes(PinManipulation, 2); //reading from serial ports
   int index = String(PinManipulation[1]).toInt();
   if (PinManipulation[0] == '0')
   {
     digitalWrite(pins[index],LOW); //turn off LED
   }
   else if (PinManipulation[0] == '1')
   {
     digitalWrite(pins[index],HIGH);
   }
   else if (PinManipulation[0] == '2')
   {
    while (Serial.available() == 0)
    {    
      digitalWrite(pins[index], HIGH);    // turn the LED on (HIGH is the voltage level)
      delay(500);                         
      digitalWrite(pins[index], LOW);     // turn the LED off by making the voltage LOW
      if (Serial.available() == 0)
      {
        delay(500);                       
      }
    }
   }
   else if (PinManipulation[0] == '6')
   {
     for (int count = 0; count < index; count++)
     {
      for (int i = 0; i < 7; i++)
      {
        digitalWrite(pins[i], HIGH);
      }
      delay(200);                       
      for (int i = 0; i < 7; i++)
      {
        digitalWrite(pins[i], LOW);
      }
      delay(200);                       
     }
   }
   Serial.flush();
 }
}

Now, while trying to figure out the problem we discovered that on the new computer we are having a compilation error, while on other computers the compilation is finished successfully.
The IDE, driver, windows version on all the computers are exactly the same, but the models of the computers are different.
We tried to reinstall the Arduino drive and libraries but it did not help.
The code is being uploaded to the Arduino from a computer that had complied the code successfully, but the work is being done with one of the NUCs that shows Error.
The Error is attached.

My questions are these:

  1. Does the Error effects the operation if the code was uploaded from a successful compilation version?
  2. What does this Error mean?
  3. Any ideas what can cause the issue we are having (the Arduino stops functioning after a while) on some computers and not others?

Thank you!

How is this a bootloader issue?

I don't see an error, I see an eminently sensible warning

we are having a lot of problems with the functionality

That happens a lot when you access resources you don't own.

It looks like you have either different versions of the compiler or different switch settings.

I assume the Arduino compliler is based on GCC so see the discussion here:

I'm not surprised the code is not functioning properly.

The compiler is pointing out an error that should be very obvious from the error message, the compiler doesn't understand why you want to access the 8th element of a 7-element array.

Serial.readBytes(PinManipulation, 2); //reading from serial ports

This line can give you problems, because it will time out in 1000mS if there are not two bytes received on the serial line. You will also need to make sure that you are not sending a newline or carriage return character, otherwise your code will not work.

By blindly receiving two characters without a specific character to indicate end of line or beginning of data your code will get out of synchronization if someone sends a single character or three characters instead of the intended two.

int index = String(PinManipulation[1]).toInt();

It makes no sense to use a String function on a single char. If you want to change an ASCII numeric character to its integer equivalent, subtract ASCII '0' from it. There really should be some error checking also, to verify the character read from serial is going to give you a valid integer within the correct range.

The documented behaviour is that going beyond array bounds has 'indeterminate results' and isn't error checked.

It looks like some newer versions of the compiler now pick this up and some don't.

That's why the code compiles on one machine and not the other.

I note the first loop will only access the first array element even though it was probably intended to set the first 12 of the seven elements...

for(i=0; i<=12; i++)

stubmandrel:
I note the first loop will only access the first array element even though it was probably intended to set the first 12 of the seven elements...

for(i=0; i<=12; i++)

I don't understand that sentence

TheMemberFormerlyKnownAsAWOL:
How is this a bootloader issue?

I don't see an error, I see an eminently sensible warning
That happens a lot when you access resources you don't own.

What do you mean by accessing resources you don't own?

stubmandrel:
It looks like you have either different versions of the compiler or different switch settings.

I assume the Arduino compliler is based on GCC so see the discussion here:

c++ - Why does this loop produce "warning: iteration 3u invokes undefined behavior" and output more than 4 lines? - Stack Overflow

Thank you.

What do you mean by "switch settings?"

pinMode(pins[11], OUTPUT)
May do random things since pins[] only has 7 elements.

In addition to compiler changes, I think that the arduino IDE has changed the error reporting level between releases (and now has it as a user-settable option in preferences)

weefree:
What do you mean by accessing resources you don't own?

I mean here

pinMode(pins[i], OUTPUT);
  }

what is the value of pins[i] when i is 7?
When i is 8?
And so on.

So you reckon changing the for(i=0; i<=12; i++) to for(i=0; i<=6; i++) will solve the issues I am having?

weefree:
So you reckon changing the for(i=0; i<=12; i++) to for(i=0; i<=6; i++) will solve the issues I am having?

Do you think it look more correct?
Do you see the problem with the original code?
What-a you got to lose?

weefree:
So you reckon changing the for(i=0; i<=12; i++) to for(i=0; i<=6; i++) will solve the issues I am having?

Doesn't for(i=0; i<7; i++) look more natural?

We don't know for sure that it will solve all your issues, but having demonstrably wrong code is never a good idea.

My guess is the reason you're seeing this warning on one computer but not the others is because you have different warning level settings. You can set the warnings level via the Arduino IDE's File > Preferences > Warning level preference.

As you discovered here, compiler warnings can provide very useful information that can save you from a lot of headaches trying to debug code that isn't working as expected. For this reason, I recommend always having the warning level set to "All" and to pay attention to any warnings.

You do need to understand the difference between warnings and errors. You should also be aware that you may see warnings from libraries your sketch uses. Although I recommend always fixing warnings from your own code, warnings from libraries don't necessarily indicate a serious problem and trying to fix them is often not worth the effort. The warning will clearly state which file it applies to.

My guess is the reason you're seeing this warning on one computer but not the others is because you have different warning level settings. You can set the warnings level via the Arduino IDE's File > Preferences > Warning level preference.

Hi @pert
I have to say that you are spot on - warning levels were indeed different.
Although it was good to understand the warning meaning, and I did change it to the correct range.
Unfortunately, it did not solve the issues we are experiencing.

The latest error I got from our program log was this:

{ERROR} 2020/06/14 11:26:43.950 - Arduino - Error occured on indicating Turn On Selected. Ex: System.IO.IOException: A device attached to the system is not functioning.

   at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
   at System.IO.Ports.SerialStream.EndWrite(IAsyncResult asyncResult)
   at System.IO.Ports.SerialStream.Write(Byte[] array, Int32 offset, Int32 count, Int32 timeout)
   at System.IO.Ports.SerialPort.Write(String text)
   at DeviceManager.Arduino.Arduino.TurnOffSelected(List`1 seatIds)