Is this a pin confliction or not?

Hi,
My IR sensors working well, I added a OLED work well.
as long as added: #include <RH_ASK.h> // Radiohead Library the OLED start failed. why?
I set the reset pin of OLED as -1 still not work.
Thank for help.
Adam

#define DECODE_SONY
#include <Arduino.h>

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
////// Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

#include <RH_ASK.h> // Radiohead Library

#define IR_RECEIVE_PIN      2 // To be compatible with interrupt example, pin 2 is chosen here.
#define IR_SEND_PIN         3
#define TONE_PIN            4
#define APPLICATION_PIN     5
#define ALTERNATIVE_IR_FEEDBACK_LED_PIN 6 // E.g. used for examples which use LED_BUILDIN for example output.
#define _IR_TIMING_TEST_PIN  7

#include <IRremote.hpp>

int LED1 = 8;
int LED2 = 9;

void setup() {
  Serial.begin(115200);
  // Just to know which program is running on my Arduino
  Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

  /*
     Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition
  */
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);

  Serial.print(F("Ready to receive IR signals of protocols: "));
  printActiveIRProtocols(&Serial);
  Serial.print(F("at pin "));
  Serial.println(IR_RECEIVE_PIN);

  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  display.display();
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(4, 0);
  display.println("ADAMDIY");
  display.display();
  display.setTextSize(1);
  display.setCursor(4, 20);
  display.println("Hello world!");
  display.display();
  
}

void loop() {
  /*
     Check if received data is available and if yes, try to decode it.
     Decoded result is in the IrReceiver.decodedIRData structure.

     E.g. command is in IrReceiver.decodedIRData.command
     address is in command is in IrReceiver.decodedIRData.address
     and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
  */
  if (IrReceiver.decode()) {

    // Print a short summary of received data
    IrReceiver.printIRResultShort(&Serial);
    if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
      // We have an unknown protocol here, print more info
      IrReceiver.printIRResultRawFormatted(&Serial, true);
    }
    Serial.println();

    /*
       !!!Important!!! Enable receiving of the next value,
       since receiving has stopped after the end of the current received data packet.
    */
    IrReceiver.resume(); // Enable receiving of the next value

    /*
       Finally, check the received data and perform actions according to the received command
    */
    // if (IrReceiver.decodedIRData.command == 0x10) {

    if (IrReceiver.decodedIRData.command == 0x34) {
      // do something
      digitalWrite(LED1, HIGH);
    } else if (IrReceiver.decodedIRData.command == 0x80) {
      // do something else
      digitalWrite(LED2, HIGH);
    }
    /////////////////////////////////////////////////////////
   display.display();
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(4, 0);
  display.println("ADAMDIY");
  display.display();
  display.setTextSize(1);
  display.setCursor(4, 20);
  display.println("Hello world!");
  display.display();
    /////////////////////////////////////////////////////
  }
}

The RadioHead library uses a lot of memory. It should be used with Arduino Zero or a MKR board or other board that have enough memory. If I remember it well, the RadioHead in ASK mode allocates memory that is not even used. The (outdated but still working) VirtualWire library uses less memory.
The RadioHead in ASK mode uses three pins. If you don't use all three pins, you better set them yourself to unused pins. If you don't set those pins, then the RadioHead library assigns them to certain default pins:

rxPin = 11
txPin = 12
pttPin = 10

The Adafruit library for OLED uses a lot of memory. Sometimes it will fit in a Arduino Uno.

I don't know the IRremote library, I assume that it is a normal library that does not use enormous amounts of memory.

Those libraries together will not work in Arduino Uno. So I assume that you have a Arduino Uno or Nano. Am I right ?

1 Like

Thank you Koepel.

I agree with you it is the library issue, the RadioHead not only used memory, it almost occupied all pins on UNO, yes I used a UNO now.

How about the <VirtualWire.h>?

You're on a rough road. Both the IR and the ASK drivers use hardware timers. At least, you have to make sure they're using different timers.

1 Like

The VirtualWire works on a Uno, but might not work with your project.

When using VirtualWire, the library takes care of the protocol and the receiver and transmitter only use pulses. To do that, the VirtualWire takes over the complete Uno.

If the IRremote does the same, they might get in the way of each other. Even if you use different interrupts, they might influence each other making them work less reliable.

1 Like

Both ways, use timer based interrupts to super-sample the RX inputs. So it's true, the timing is liable to be disturbed if two such drivers are running, since interrupts are disabled when an ISR is running. But, the delays might not crash the input completely, just affect the performance. It would take some trials to see.

1 Like

Thanks.
Actually I don't know how to figure out which Library used which timer.

The usual way. Read the documentation. :frowning:

1 Like

Thanks.
If the hardware is a problem, can a MEGA2560 solve it?

No.

1 Like

Thanks.
any other library recommend please.

It's not a library problem. It's a microprocessor resource/capability problem.

2 Likes

Last year, I proposed an idea for a common super-sampling driver, to allow multiple apps such as IR, ASK, etc., to synchronize and share a timer. It was shot down. But if I really needed to do it, that is how I would solve the issue. Problem is, each library is almost created in a vacuum, nobody thinks much about interoperability with other libraries...

3 Likes

Thank you aarg.
you said the truth. there are so many library conflicts.
It would be a great help if you have done your super-sampling driver!
at least should have some standards or rules to guide the libraries.

Thanks all.
here is asking before doing, how about Bluetooth library ? doea it conflict with RC or not? I mean get rid of OLED, and use Bluetooth control the module by phone?

Bluetooth is better, but you need a Serial port.
The Arduino Leonardo and Arduino Mega have spare hardware Serial port(s).

The Uno can run a SoftwareSerial, but that causes the same problem. The SoftwareSerial does the protocol and timing in software and it needs the whole Arduino Uno for that.

1 Like

Thank you Koepel.
If BT better, I'll use a MEGA2560 and test it.

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