Arduino/Adafruit IR Library Discrepancies - Help?

Thread Starter

Ryan Jones

Joined Aug 27, 2016
35
Hey, me again!

I am using an Adafruit Circuit Playground Classic (and it's library) to detect motion with the built in accelerometer. I am attempting to create a motion activated "universal remote control," basically, have the Circuit Playground emit IR codes.

I have code written which works with the Circuit Playground and sends details to the serial monitor when I move my hand in whichever position. I know that my IR commands work because I have tested them on an Uno. However, when added to the Circuit Playground, I yield no results. I believe this has to do with discrepancies in the active timer of the Circuit Playground Library and IRRemote Library. I have tried changing pin assignments but no luck. Any suggestions?
 

Thread Starter

Ryan Jones

Joined Aug 27, 2016
35
Code:
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Bike Glove - Hand Position Detection
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>
#include <IRremote.h>

IRsend irsend;

#define THRESHOLD_UP        6   // threshold for hand up test
#define THRESHOLD_DOWN     6   // threshold for right turn
#define THRESHOLD_RIGHT     -6   // threshold for left turn
#define THRESHOLD_LEFT   -6

bool leftButtonPressed;
bool rightButtonPressed;

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600);
  CircuitPlayground.begin();
}

///////////////////////////////////////////////////////////////////////////////
void loop() {

  leftButtonPressed = CircuitPlayground.leftButton();
  rightButtonPressed = CircuitPlayground.rightButton();

  if (leftButtonPressed) {
    Serial.println("Select");
    irsend.sendNEC(0x57E354AB, 32);
    delay(100);
  }

  if (rightButtonPressed) {
    Serial.println("ON");
  }

  // check for hand up or down
  if (CircuitPlayground.motionZ() > THRESHOLD_UP) {

    Serial.println("Stationary");

  } else {

    // check for right turn
    if (CircuitPlayground.motionX() > THRESHOLD_DOWN) {
      down();

      // check for left turn
    } else if (CircuitPlayground.motionX() < THRESHOLD_RIGHT) {
      up();


      // check for left turn
    } else if (CircuitPlayground.motionY() < THRESHOLD_RIGHT) {
      right();

      // check for left turn
    } else if (CircuitPlayground.motionY() > THRESHOLD_DOWN) {
      left();


    }
  }

  delay(100);
}

void down() {

  Serial.println("Volume Down");
  irsend.sendNEC(0x57E3CC33, 32);
  delay(100);
 

}

void up() {

  Serial.println("Volume Up");
  irsend.sendNEC(0x57E39867, 32);
  delay(100);

}

void right() {

  Serial.println("Channel Up(Right)");
  irsend.sendNEC(0x57E3B44B, 32);
  delay(100);

}

void left() {

  Serial.println("Channel Down(Left)");
  irsend.sendNEC(0x57E37887, 32);
  delay(100);

}
 
Hey, me again!

I am using an Adafruit Circuit Playground Classic (and it's library) to detect motion with the built in accelerometer. I am attempting to create a motion activated "universal remote control," basically, have the Circuit Playground emit IR codes.

I have code written which works with the Circuit Playground and sends details to the serial monitor when I move my hand in whichever position. I know that my IR commands work because I have tested them on an Uno. However, when added to the Circuit Playground, I yield no results. I believe this has to do with discrepancies in the active timer of the Circuit Playground Library and IRRemote Library. I have tried changing pin assignments but no luck. Any suggestions?
I don't know, but I strongly suspect that the circuit playground library is disabling interrupts (related to using the neopixels) and interrupts are required to manage the timing in the IR library.

If you look at the IR library Git Hub page, you see:

"IR does not work right when I use Neopixels (aka WS2811/WS2812/WS2812B)
Whether you use the Adafruit Neopixel lib, or FastLED, interrupts get disabled on many lower end CPUs like the basic arduinos. In turn, this stops the IR interrupt handler from running when it needs to. There are some solutions to this on some processors, see this page from Marc MERLIN"

Also, there is a thread on the Adafruit support forum related to the issue, How to use Neopixel + IRremote Arduino libraries.

If this is the problem, you might be able to program your way around this, but it is hard to tell.

Have you considered trying to get hold of the Circuit Playground Express board that contains an IR receiver and transmitter?
 

Thread Starter

Ryan Jones

Joined Aug 27, 2016
35
@Raymond Genovese

Thank you, Raymond! You are always a great help.

Digi-key has supplied us with this product for our next project, and while I don't think it would be a big deal to trade it out for an Express, it seems to be out of stock on Adafruit and Amazon. Unfortunately we have a deadline to meet.

Those links seem great and I believe they should help. @Sensacell made a great point, I do need to confirm this with an oscilloscope. Thank you both! I will keep you updated.
 
Top