Hello,
Thank you in advance and I apologize for a long and complex first post. I have already done a lot of testing and experimentation to rule in and out potential causes of my problem, and will note them below.
I am very new to Arduino and not at all familiar. Everything is a learning curve. However, I am an experienced (and old) EE.
I am working with some generic (Lifkin) Nanos that I bought and have socketed on the evaluation PCBs I designed for my main project. Essentially the Nano will act as a controller to receive IR remote codes and manipulate digital pins based on those codes.
I began by loading simple programs like Blink and “print ASCII table” to prove that the boards worked, and to teach myself how to use the IDE and upload sketches. With some issues, I got there. Both work fine, and ASCII shows that the Nano communicates with the serial monitor well. I used both an UNO and two of the Nanos to test these – no issues.
I plan to use the IRRemote library by Ken Sherriff. Its pretty simple to use. However, I am having stubborn problems getting it to work correctly on the NANOs. To rule out my own errors, I am beginning with the Author’s sample code (Below). But it cannot be the code since it works on the UNO anyway. The sample code and library load and work on UNO. It compiles and uploads on the NANOs as well, without errors. But it does not actually work. Basically, the program scans for codes, and when it gets one prints it to the serial monitor. 95% of the time it does nothing. 5% of the time it does something weird, like print one random code continuously (like overnight if I let it).
One helpful person suggested it was a problem with the library and suggested a different one “RIRemoteControl” from the library manager. So I did the same thing, with it’s sample code. Same result – worked perfectly on the UNO, flaky at best on the Nano. The sample code is also below, but again, logically ruled out since it works on the UNO.
I can only conclude that there is a problem with the Nano reading the digital input pin. I have tried several pins – 2, 7,6 with similar results.
In frustration I did some good old analog sleuthing. My power source is, of course, the PC connected for the upload and serial monitor, via USB. The power according to Mr, Fluke, is 4.7V, not 5. Seems close enough, btu it is not 5V. Could this possibly be the cause?
Anyway, I need some help here from the collective wisdom. Again I rule out the code and libraries since they work on UNO. I rule out the uploader, serial interface and basic Nano processing since blink and ASCII work on both UNO and Nanos. I rule out simple device failure since two Nanos exhibit the same behavior. I have tried the old bootloader and changing processor codes, but these fail out of the gate.
I can plug this into my evaluation board, which has a superb custom regulator at 5.0V to eliminate any issue of power supply. The only issue is that I then have TWO 5V sources connected to the regulated supply leads – the PC and my own regulator. IN my eval it shares power with many other 5V functions.
Connections:
3-pin IR receiver connected to +5V (pin 4) Ground (pin 2) and input (pin 2 or 7 depending on the sketch used)
Help! And TIA
Sample code for Ken Sherriff’s library:
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
pinMode(RECV_PIN, INPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop(){
if (irrecv.decode(&results)){
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
Sample Code for the other suggested IR library:
/*
* IRsend: IRRemoteControlDemo - demonstrates receiving/sending IR codes.
* Created by Cristiano Borges - STI - Fatesg
* August, 2017
*/
#include "IRRemoteControl.h"
IRRecv irRecv;
IRSend irSend;
const int IR_RECV_PIN = 2;
const int MAX_IR_BUFFER_LENGTH = 650;
unsigned int irBuffer[MAX_IR_BUFFER_LENGTH];
int currentIrBufferLength = 0;
const int FREQ_KHZ = 40;
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
irRecv.start(IR_RECV_PIN, irBuffer, MAX_IR_BUFFER_LENGTH, currentIrBufferLength);
}
void loop() {
Serial.println(F("Press the remote control button now - only once"));
delay(5000);
if (currentIrBufferLength > 0) {
irRecv.stop(IR_RECV_PIN);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println();
Serial.print(F("Code: "));
for (int i = 0; i < currentIrBufferLength; i++) {
if (i > 0) {
Serial.print(F(", "));
}
Serial.print(irBuffer[i]);
}
Serial.println();
Serial.println(F("Sending the code..."));
delay(5000);
irSend.sendRaw(irBuffer, currentIrBufferLength, FREQ_KHZ, false);
Serial.println(F("Code sent!"));
Serial.println();
digitalWrite(LED_BUILTIN, LOW);
irRecv.start(IR_RECV_PIN, irBuffer, MAX_IR_BUFFER_LENGTH, currentIrBufferLength);
}
}


