Project stop work after upgrade Arduino compiler

Hello,

I have project with Nano board, it was maked on Arduino version 1.6.5, works perfect.

Now I need to change some part in program code, but a project stopped works (Arduino version 1.8.x, it also not works from version 1.6.7 and newer).

Code is based on Timer1 which is counting to X us and setting/reseting output pins (like PWM). I'm using D3, D5, D6,D7, D9, D10, D11, D12. Low 4 bits still works, but upper 4 not (D9, D10, D11, D12). I don't know why ... (board is OK).

Version on Timer1 library doesn't matter, still same problem.

part of my code...

void setup ()
{
...
  Timer1.initialize(freqStep);
  Timer1.attachInterrupt(dimCheck);
}
...
void dimCheck()
{
  dimCount--;
  if (dimCount < 1)
  {
    dimCount = range;
    if (outDim[0] < range)      {digitalWrite (Out1, LOW);}
    if (outDim[1] < range)      {digitalWrite (Out2, LOW);}
    if (outDim[2] < range)      {digitalWrite (Out3, LOW);}
    if (outDim[4] < range)      {digitalWrite (Out5, LOW);}
    if (outDim[5] < range)      {digitalWrite (Out6, LOW);}
    if (outDim[6] < range)      {digitalWrite (Out7, LOW);}
  }
  else
  {
    if (outDim[0] > dimCount)     {digitalWrite (Out1, HIGH);}
    if (outDim[1] > dimCount)     {digitalWrite (Out2, HIGH);}
    if (outDim[2] > dimCount)     {digitalWrite (Out3, HIGH);}
    if (outDim[4] > dimCount)     {digitalWrite (Out5, HIGH);}    
    if (outDim[5] > dimCount)     {digitalWrite (Out6, HIGH);}    
    if (outDim[6] > dimCount)     {digitalWrite (Out7, HIGH);}      
  }
}

What happens in builder, where should be problem?
Thank you.

-- EDIT --
It was determined that the error is caused by the simultaneous use of the library "TimerOne" and "OneWire". It's works together only at version 1.6.5. So I'm keeping compiler version 1.6.5 for this project.

-- EDIT 2 --
Just ctrl+c > ctrl+v old project to new one as parts by parts (function by function) and it's works :smiley:

(deleted)

Other parts of code is not important for timer, it's handling about settings and data, not with pins, but OK, here is few more.

#include <TimerOne.h>

#define       Out1           3                  // Digital  3
#define       InDS1          4                  // Digital  4
#define       Out2           5                  // Digital  5
#define       Out3           6                  // Digital  6
#define       Out4           7                  // Digital  7
                                                // Digital  8
#define       Out5           9                  // Digital  9
#define       Out6          10                  // Digital 10
#define       Out7          11                  // Digital 11
#define       Out8          12                  // Digital 12
#define       LED           LED_BUILTIN         // Digital 13

#define       In8           A7                  // Analog           7
#define       In7           A6                  // Analog           6
#define       In6           A5                  // Digital / Analog 5
#define       In5           A4                  // Digital / Analog 4
#define       In4           A3                  // Digital / Analog 3
#define       In3           A2                  // Digital / Analog 2
#define       In2           A1                  // Digital / Analog 1
#define       In1           A0                  // Digital / Analog 0

volatile byte dimCount      =     0;
const int     freqStep      =    86; 

byte          outDim[8]     =    {}; 
const byte    range         =    64;

void setup ()
{
  // Outputs
  pinMode (LED, OUTPUT);
 
  pinMode (Out1, OUTPUT);
  pinMode (Out2, OUTPUT);
  pinMode (Out3, OUTPUT);
  pinMode (Out4, OUTPUT);
  pinMode (Out5, OUTPUT);
  pinMode (Out6, OUTPUT);
  pinMode (Out7, OUTPUT);
  pinMode (Out8, OUTPUT);
  

  // Inputs
  pinMode (In1, INPUT);
  pinMode (In2, INPUT);
  pinMode (In3, INPUT);
  pinMode (In4, INPUT);
  pinMode (In5, INPUT);
  pinMode (In6, INPUT);
  pinMode (In7, INPUT);
  pinMode (In8, INPUT); 


  Timer1.initialize(freqStep);
  Timer1.attachInterrupt(dimCheck);
  Timer1.disablePwm(9);
  Timer1.disablePwm(10);


  Serial.begin(115200,SERIAL_8N1);
  Serial.setTimeout(10);

}


void dimCheck()
{
  dimCount--;
  if (dimCount < 1)
  {
    dimCount = range;
    if (outDim[0] < range)      {digitalWrite (Out1, LOW);}
    if (outDim[1] < range)      {digitalWrite (Out2, LOW);}
    if (outDim[2] < range)      {digitalWrite (Out3, LOW);}
    if (outDim[4] < range)      {digitalWrite (Out5, LOW);}
    if (outDim[5] < range)      {digitalWrite (Out6, LOW);}
    if (outDim[6] < range)      {digitalWrite (Out7, LOW);}
  }
  else
  {
    if (outDim[0] > dimCount)     {digitalWrite (Out1, HIGH);}
    if (outDim[1] > dimCount)     {digitalWrite (Out2, HIGH);}
    if (outDim[2] > dimCount)     {digitalWrite (Out3, HIGH);}
    if (outDim[4] > dimCount)     {digitalWrite (Out5, HIGH);}    
    if (outDim[5] > dimCount)     {digitalWrite (Out6, HIGH);}    
    if (outDim[6] > dimCount)     {digitalWrite (Out7, HIGH);}      
  }
}


void loop ()
{
...
// Operating with data ...

delay (1);
}

Other parts of code is not important

Yes they are. Often they contain the mistake.

The code compiles if you comment out the '...' in loop(). In what way is this reduced sketch not working in the way you expect?

It's 100% works on version 1.6.5. Not at any newest.
And problem is just with high 4 bites, other outputs pins works good.

Other part of code operating with serial line and data (filling outDim), not settings or handling with any part of timer.

Hi,
Why do you need to have it working in latest IDE?
Keep using 1.6.5 for that code.
Note in the codes program comments that it needs 1.6.5 for compilation.

Both versions can exist on the same PC.

Tom... :slight_smile:

If you set "Compiler warnings: All" in Preferences, do you get any warnings when you compile your full sketch? Sometimes the warning messages will point out thing that aren't always errors but are in your case.

Hello, I investigate whole code and there is really no error, problem is with cooperate with "OneWire" library. I'm sorry, I didn't post anything about using "OneWire" before, I didn't see context. OneWire operating on digital pin 4.

It's looks that newest compiler has different access to cooperating Timer1 and OneWire than was in 1.6.5. Compilers warning are clear (also at settings "all").

Ok please yourself people often want help when they post here. Looks like you are a time waster.

If you really don't want to show your code write a short piece of compleat code that shows the problem and explain what that problem is and what you expect the code to do. You never know that way you may find the error yourself. You are sure not winning any friends here.

Do it, make me aware that I did not post the source code... Some parts are not important to describe the bug and I do not want to publish them.

I just had a forking program which works on compiler 1.6.5, now after 2 years it's stopped works on compiler 1.8.3. All without any notification or error.

Problem solved, it's some internal library incompatible between "TimerOne" and "OneWire", I don't know where and I will not I will not examine it, I will keep it on version 1.6.5.

I will try to make some small project with "OneWire" and "TimerOne" for test it and I will post it.

Thank you everyone for your time and try to help me, I appreciate it.

(deleted)

Problem solved, it's some internal library incompatible between "TimerOne" and "OneWire", I don't know where and I will not I will not examine it, I will keep it on version 1.6.5.

Some strange new usage of the word solved that I was previously unaware of. I would say side stepped rather than solved.

I'm so confused now. I make a lite code with TimerOne and OneWire as I'm using it (see bellow) for try to compile it in 1.6.5 and in 1.8.3 version. And It's works without problem on both version.

So I remake old program as new project and just ctrl+c ctrl+v as parts by parts (function by function) ... and its works, I don't know how to, booth projects are same, but it's running.
I tried it at all version between 1.6.5 and 1.8.3 yesterday, and it works only on 1.6.5. Now is same code (in new creates project) works :D. Weird, but great.

Thank you everyone one more time.

Here is the test code:

#include <TimerOne.h>                           // http://playground.arduino.cc/Code/Timer1
#include <OneWire.h>                            // http://playground.arduino.cc/Learning/OneWire

#define       Out1           3                  // Digital  3
#define       InDS1          4                  // Digital  4
#define       Out2           5                  // Digital  5
#define       Out3           6                  // Digital  6
#define       Out4           7                  // Digital  7
                                                // Digital  8
#define       Out5           9                  // Digital  9
#define       Out6          10                  // Digital 10
#define       Out7          11                  // Digital 11
#define       Out8          12                  // Digital 12
#define       LED           LED_BUILTIN         // Digital 13

#define       In8           A7                  // Analog           7
#define       In7           A6                  // Analog           6
#define       In6           A5                  // Digital / Analog 5
#define       In5           A4                  // Digital / Analog 4
#define       In4           A3                  // Digital / Analog 3
#define       In3           A2                  // Digital / Analog 2
#define       In2           A1                  // Digital / Analog 1
#define       In1           A0                  // Digital / Analog 0

volatile byte dimCount      =     0;            // make volatile to make available in interrupt
const int     freqStep      =    86;            // 1 /  86us / 64step = 182Hz

// Outputs
const byte    range         =    64;            // Range
byte          outDim[8]     =    {};            // Values
byte          dimTimer      =     0;            // Timer for slowing
byte          dimDelay      =   100;            // Slowing


// One Wire DS18B20
OneWire ds(InDS1);
byte          dsCRC         =     0;            // CRC
int16_t       dsValue[11]   =    {};            // Temperature RAW
byte          dsSelect      =     0;            // Device select
const byte    dsMax         =     3;            // No of devices
int           dsBlock       =  2000;            // Delay for init start
const int     dsWaitC       =  1000;            // Delay for convert (ms)
const int     dsWaitN       =    50;            // Delay for next devices (ms)
const int     dsWaitR       =  5000;            // Delay for next round (ms)
byte          dsAddress[11][8] ={
  {0x28,0x25,0x9D,0xDB,0x06,0x00,0x00,0x5C},    //  0
  {0x28,0x25,0x9D,0xDB,0x06,0x00,0x00,0x5C},    //  1
  {0x28,0x4D,0x77,0xDB,0x06,0x00,0x00,0x59},    //  2
  {0x28,0xA2,0xB6,0xDB,0x06,0x00,0x00,0xBB},    //  3
  {0x28,0xC5,0xD0,0x36,0x06,0x00,0x00,0xA4},    //  4
  {0x28,0xE2,0xB8,0xE6,0x05,0x00,0x00,0x5D},    //  5
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  6
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  7
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  8
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},    //  9
  {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} };  // 10

// Setup
void setup ()
{
  // Outputs
  pinMode (LED, OUTPUT);
 
  pinMode (Out1, OUTPUT);
  pinMode (Out2, OUTPUT);
  pinMode (Out3, OUTPUT);
  pinMode (Out4, OUTPUT);
  pinMode (Out5, OUTPUT);
  pinMode (Out6, OUTPUT);
  pinMode (Out7, OUTPUT);
  pinMode (Out8, OUTPUT);
  

  // Inputs
  pinMode (In1, INPUT);
  pinMode (In2, INPUT);
  pinMode (In3, INPUT);
  pinMode (In4, INPUT);
  pinMode (In5, INPUT);
  pinMode (In6, INPUT);
  pinMode (In7, INPUT);                         // A6 just analog
  pinMode (In8, INPUT);                         // A7 just analog

  // Timer
  Timer1.initialize(freqStep);
  Timer1.attachInterrupt(dimCheck, freqStep);
  Timer1.disablePwm(9);
  Timer1.disablePwm(10);
  interrupts();

}

// Dimer
void dimCheck()
{
  dimCount--;
  if (dimCount < 1)
  {
    dimCount = range;
    if (outDim[0] < range)        {digitalWrite (Out1, LOW);}
    if (outDim[1] < range)        {digitalWrite (Out2, LOW);}
    if (outDim[2] < range)        {digitalWrite (Out3, LOW);}
    if (outDim[3] < range)        {digitalWrite (Out5, LOW);}
    if (outDim[4] < range)        {digitalWrite (Out6, LOW);}
    if (outDim[5] < range)        {digitalWrite (Out7, LOW);}
  }
  else
  {
    if (outDim[0] > dimCount)     {digitalWrite (Out1, HIGH);}
    if (outDim[1] > dimCount)     {digitalWrite (Out2, HIGH);}
    if (outDim[2] > dimCount)     {digitalWrite (Out3, HIGH);}
    if (outDim[3] > dimCount)     {digitalWrite (Out5, HIGH);}    
    if (outDim[4] > dimCount)     {digitalWrite (Out6, HIGH);}    
    if (outDim[5] > dimCount)     {digitalWrite (Out7, HIGH);}      
  }
}

// OneWire - Handle Event
void OneWireEvent ()
{
  dsBlock--;
  if (dsBlock <= 1)                             // Its time to handle
  {
    digitalWrite (LED, LOW);                    // Show OneWire aktivity
    dsBlock = 1;
    if (dsSelect <= 0)                          // Convert
    {
      OW_Convert ();
      dsBlock = dsWaitC;                        // Delay for convert
      dsSelect = 1;                             // Next step
      digitalWrite (LED, HIGH);                 // Show OneWire aktivity
    }
    else if (dsSelect <= dsMax)                 // Step X (reading)
    {
      OW_Read (dsSelect - 1);                   // Read
      dsBlock = dsWaitN;                        // Delay for next device
      dsSelect++;
      digitalWrite (LED, HIGH);                 // Show OneWire aktivity
    }
    else                                        // All device done
    {
      dsBlock = dsWaitR;                        // Delay for next event
      dsSelect = 0;                             // Next event is convert
    }
  }
}

// OneWire - Convert
void OW_Convert ()
{
  if (ds.reset ())
  {
    ds.write (0xCC);                            // Skip ROM
    ds.write (0x44);                            // Convert
  }
}

// OneWire - Read
void OW_Read (byte num)
{
  byte  owTry = 3;                              // How many times try to read data
  byte  owVal = 0;                              // Tempoary value
  byte  owL   = 0;                              // Low byte
  byte  owH   = 0;                              // High byte
  
  while (owTry)                                 // Try to read
  {
    dsCRC = 0;
    if (ds.reset ())                            // Reset
    {
      ds.select (dsAddress [num]);              // Address
      ds.write (0xBE);                          // Request
      for (byte oo = 0; oo < 8; oo++)           // Reading 8 byte
      {
        owVal = ds.read ();                     // 1 byte
        owCRC (owVal);                          // CRC
        if (oo == 0)  {owL = owVal;}            // Ulozeni teplot
        if (oo == 1)  {owH = owVal;}
      }
      owVal = ds.read ();                       // Reading CRC
      if (owVal == dsCRC)                       // Check CRC
      {
        dsValue[num] = (owH << 8) | owL;        // Save data
        owTry = 0;                              // OK, finish
      }
      else
      {
        owTry--;                                // CRC Error, repeating
      }
    }
    else    {owTry = 0;}                        // Do device > end
  }
}

// OneWire - CRC
void owCRC (byte data)
{
  byte oCRC_loop  = 0;
  byte oCRC_tmp = 0;
  for (oCRC_loop = 8; oCRC_loop != 0; oCRC_loop--)
  {
    oCRC_tmp = (data ^ dsCRC) & 1;
    data >>= 1;
    dsCRC >>= 1;
    if (oCRC_tmp != 0)
    {
      dsCRC ^= 0x8C;
    }
  }
}



// MAIN LOOP
void loop ()
{

  OneWireEvent ();                             // DS Reading

  // Diming
  dimTimer++;
  if (dimTimer >= dimDelay)
  {
    byte rr = random (0, 6);
    byte rw = random (0, range);
    outDim[rr] = rw;
    dimTimer = 0;
  }

  delay (1);
}