Arduino Nano Every - Pin D6

Hello,

My configuration :

Arduino uno
Arduino nano Every

Arduino IDE version 2.3.4

Problem with D6 on Arduino Nano Every

The following program uses an RGB LED and an IR remote control (IRremote 4.4.1).
Test electrical connections OK
Arduino Uno -- D3 or D6 used to control LED (blue pin) -- operation OK
Arduino Nano Every -- D3 used to manage the LED (blue pin)-- operation Ok
Arduino Nano Every -- D6 used to manage the LED (blue pin)-- No blue LED on

In the Nano Every description I read that D3 uses TCB1 and D6 uses TCB0.
I'm new to Arduino programming and probably missed something.

Any help would be appreciated.
Thank you very much

#include <IRremote.hpp>
#define IR_RECEIVE_PIN 9 // Signal de la télécommande

int rPin = 5;
int gPin = 10;
int bPin = 3;
// int bPin = 6;

int rBright = 255;
int gBright = 255;
int bBright = 255;

float dFact=1;

void translateIR() // Fonction reliant le signal à la fonction associée
{
// describing Remote IR codes
switch(IrReceiver.decodedIRData.decodedRawData)
  {
    case 0xBA45FF00: Serial.println("POWER"); rBright=255; gBright=255; bBright=255; dFact=1; break;
    case 0xB847FF00: Serial.println("FUNC/STOP"); rBright=0; gBright=0; bBright=0; dFact=0; break;
    case 0xB946FF00: Serial.println("VOL+"); dFact=dFact*1.3; if (dFact>1){dFact=1;}; break;
    case 0xBB44FF00: Serial.println("FAST BACK"); break;
    case 0xBF40FF00: Serial.println("PAUSE"); break;
    case 0xBC43FF00: Serial.println("FAST FORWARD"); break;
    case 0xF807FF00: Serial.println("DOWN"); dFact=dFact*.75; break;
    case 0xEA15FF00: Serial.println("VOL-"); dFact=dFact*.75;break;
    case 0xF609FF00: Serial.println("UP"); dFact=dFact*1.3; if (dFact>1){dFact=1;}; break;
    case 0xE619FF00: Serial.println("EQ"); break;
    case 0xF20DFF00: Serial.println("ST/REPT"); break;
    case 0xE916FF00: Serial.println("0"); rBright=255; gBright=255; bBright=255; break;
    case 0xF30CFF00: Serial.println("1"); rBright=255; gBright=0; bBright=0; break;
    case 0xE718FF00: Serial.println("2"); rBright=0; gBright=255; bBright=0; break;
    case 0xA15EFF00: Serial.println("3"); rBright=0; gBright=0; bBright=255; break;
    case 0xF708FF00: Serial.println("4"); rBright=0; gBright=255; bBright=255; break;
    case 0xE31CFF00: Serial.println("5"); rBright=255; gBright=0; bBright=150; break;
    case 0xA55AFF00: Serial.println("6"); rBright=255; gBright=255; bBright=0; break;
    case 0xBD42FF00: Serial.println("7");    break;
    case 0xAD52FF00: Serial.println("8");    break;
    case 0xB54AFF00: Serial.println("9");    break;
    case 0xFFFFFFFF: Serial.println("Je n'ai pas compris. Recommencer");break;
    default:
    Serial.println(" Autre bouton ");
  }
  delay(500); // Permet de laisser le temps de recevoir le prochain signal
}
void setup() // Fonction Setup qui s'éxécute qu'une seule fois
{
  Serial.begin(115200);
  Serial.println("Démarrage du décodage");
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // On démarre le receveur


}

void loop() // Boucle qui s'éxécute à l'infini
{
  if (IrReceiver.decode()) {
      Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); 

      translateIR();
      
      // Envoi commande LED
      IrReceiver.stopTimer(); // arrêt timer car incompatible avec analogWite
      analogWrite(rPin,rBright*dFact);
      analogWrite(gPin,gBright*dFact);
      analogWrite(bPin,bBright*dFact);
      IrReceiver.restartTimer(); // redemarrer timer
      
      IrReceiver.resume(); // Permet de recevoir la valeur suivante
  }
}

I see the above comment and wonder if you can strip down your code to a basic version that only fades the LED on pin D6. That would prove if there is a conflict between the IRremote library and the analogWrite that goes deeper than just the analogWrite itself; the analogWrite timer might already be configured before the analogWrite is used.

I don't have the Nano Every so can't test.

I believe that this is the case. As a receiver, the timer has been reconfigured for an interrupt mode and not a pwm mode. See IRTimer.hpp.

The .stopTimer() and .restartTimer() only disable the interrupt, but do not reconfigure the timer back to a pwm mode.

I think you may need to go to switch to a send mode, but that may not set the timer back to the core pwm mode. I'm not familiar enough with the details of the library.

Thank you for your answers.

The program works when I use D3 (using TCB1). A simplified program (analogWrite(D6,127) works.
I finally found in the documentation that IRremote uses TCB0, stating that “If you use a library that requires the same timer as IRremote, you will encounter a problem, as the timer resource cannot be shared simultaneously by both libraries”. It also says that it's incompatible with analogwrite (requires .stopTimer and .restartTimer to use analogWrite which works with D3, D5, D10).

I guess this is the answer to my problem?

I'll have to learn more about TCB0 management and maybe find another library to manage IR.
Thanks again for your help.
JNoel

I made a small sketch with IRremote.hpp. In the disassembler I saw that the interrupt from TCB0 was used. That means a conflict with PWM at D6, as that also needs TCB0.

Many thanks for your answer.
I finally found in the documentation that IRremote uses TCB0, stating that “If you use a library that requires the same timer as IRremote, you will encounter a problem, as the timer resource cannot be shared simultaneously by both libraries”. It also says that it's incompatible with analogwrite (requires .stopTimer and .restartTimer to use analogWrite which works with D3, D5, D10).
Thanks again for your help.
JNoel

There are a number of topics about IRremote conflicting with other libraries; for AVR boards it would result in linker errors about ISRs. The solution was to use a different timer for one of the libraries.

I'm not familiar with the Nano Every but you can have a look at the IRremote library again and try to find if it can be modified to use a different timer.

You use pin D9 for input of IRRemote. This is a PWM capable pin. If you pick another pin for input you fee D9 for use with PWM — if needed.

Rremote --> D6
bPin --> D9
This is the right solution. No sharing conflicts.
Thank you very much.
JNoël

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.