IR code works on UNO not Nano; many segmentation tests performed. Help please.

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);
}
}

See the funny italics in your code? You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing or review.

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower right corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

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.

What was the result of that?

One thing to check is the clock speed on your Nano. Some are 8 MHz to run on 3.3V instead of 5V. To run at 16 MHz you are supposed to use 3.8V or higher. Code compiled for a 16 MHz UNO can be uploaded to an 8 MHz Nano and it will run a half speed. That would make the IR receiver timing way off. Look at the ceramic resonator which will typically say 16 or 8. Look at the regulator which will typically say 33 or 5 or 50.

Thanks for the (good) idea re: clock and power. It is 5V 16Mhz - all good there. Almost wish it weren't since i'd have a lead :slight_smile:

I guess we need to see the wiring of the UNO which does work and the Nano which doesn't.

aarg:
What was the result of that?

I have not had time to try this yet. Also, as noted, a little leery of having two power supplies hooked together. Is this config normal and OK? Just seems like bad practice to have tow low impedance sources essentially in a fistfight....they wont be identical voltages by definition - one will be 4.7 the other 5.0....

Any BTDT? Stay posted...

itsjustme:
I have not had time to try this yet. Also, as noted, a little leery of having two power supplies hooked together.

If you are worried, take an old USB cable and cut the RED wire (+5V). Then there will be no power from the USB cable.

johnwasser:
I guess we need to see the wiring of the UNO which does work and the Nano which doesn't.

Identical pin for pin. I mean i can make a schematic and take a pic and post, but its kinda pointless.
IR to Nano = +5 tp pin 27, GND to pin 29, SIgnal to Pin 7
IR to UNO = +5 to pin "5V", Ground tyo pin "GND" next to 5V, Signal to pin #2
As noted also tried alternate digital input pins

The processors are the same in the Uno and Nano unless the Nano is counterfeit. I haven't seen reports of counterfeit Nanos, only Pro Minis. So it has to be something else that's different between the two. Is it the same IR receiver? Is there a link to the receiver? If it's two different receivers, have you tried swapping them?

The 4.7V "5V" output on the Nano is because it's powered from USB through a Schottky diode. If you connect a regulated 5V supply to the 5V pin, in theory it should provide all the power and USB should be protected by the diode, which would be reverse biased. But there shouldn't be any difference in performance between 4.7V and 5V. But you might check to see if there's any sag or bad ripple on the 5V pin when you're receiving an IR signal.

It's a puzzler. If you have a scope at hand, you might look at the output of the IR receiver on both, and make sure it's the same in response to the same input.

johnwasser:
I guess we need to see the wiring of the UNO which does work and the Nano which doesn't.

Well, i'm trying to attach a j[peg with the diagram and picture of hookup. I placed it on my desktop, its < 2MB, browsed with the button below, it appears to be selected but there is no "upload" and when i preview i dont see the pic. We shall see if it appears below....

edit: clearly preview lies :frowning:

ShermanP:
Is it the same IR receiver?

The 4.7V "5V" output on the Nano is because it's powered from USB through a Schottky diode.

Same Reciever. I swap the setups.
Thanks for the clarification on 4.7V sounds like that is not my problem. It was a long shot.
Nano is not "genuino" but is a known brand (named above i forget) - its amazon's choice FWIW

When you select the board type in the Arduino IDE, with the Nano you have 3 options with different processor and boot loader types. Which do you choose ?

The two sketch attempts you have listed have different baud rates for their Serial.begin statements (115200 and 9600) . Which have you selected in the serial monitor ?

6v6gt:
When you select the board type in the Arduino IDE, with the Nano you have 3 options with different processor and boot loader types. Which do you choose ?

The two sketch attempts you have listed have different baud rates for their Serial.begin statements (115200 and 9600) . Which have you selected in the serial monitor ?

Remember that many sketches work, so this is very unlikely to be the issue. All problems have to do with receiving codes on input digital pins -- not running code or communicating with the serial monitor.
But i'll akswer your questions anyway. I choose Nano, Mega328P (because that's what the chip is) and new bootloader. TYhe old bootloader fails in all cases.
I set the serial monitor and serial rate (in sketch) to the same rate of course. Depends on the sketch and whether i choose to over-ride. In all cases they match, which ought to be obvious since that works in all cases.
Greatly appreciate people's willingness to help. I really ant to focus everyone's thoughts ont he area where its broken, which is acquiring codes on pin 7 or 2, whichever is specified and connected. All the other functions of the sketch appear to work. Compiles, uploads, send proper initial message to serial monitor. THEN it breaks down....but only on the Nano.
TIA as always,
G

Are you sure you are connecting to input pin 2 or pin 7? The nano had a ground and reset between the RX/TX pins (D1 and D0) and D2.

In your picture you are connected to input pin 4 (D4)

Can you please attempt another image, or set of images? It was a nice gesture to post #10 but it doesn't show the sensor. It's also hard to see the breadboard and Arduino connections.

I asked about the baud rate because of this statement:
"95% of the time it does nothing. 5% of the time it does something weird, like print one random code continuously"

Just to clear that up, you should add a Serial.print statement to your setup() say Serial.println( "starting...") ; .

What IR source are you using to test the IR receiver / Nano combination ?

What is that IR receiver module you are using ? The diagram which appears near nano lying on its side seems to show that the centre pin is +5v. It is clearly not then a standard like the Vishay e.g. TSOP4838 where the centre pin is ground.

It is not very clear, but the orange wire to the Nano appears to go to pin D4. Not either D2 or D7 which you have mentioned previously. The other 2 wires appear to be power.

You can test the function of your IR receiver without an Arduino. The following simple circuit shows how:

Edit:

Crossed with @aarg

keys.JPG

keys.JPG

david_2018:
Are you sure you are connecting to input pin 2 or pin 7? The nano had a ground and reset pin the RX/TX pins (D1 and D2) and D2.

In your picture you are connected to input pin 4 (D4)

Let's be clear. I am connected to D4. But that is Pin 7. The pins are numbered 1-15 up one side and 16-30 back down the opposite side. Pin 2 is RX. Pin 7 is D4. I use, depending on the sketch (in order to keep tthe author's conventions) pin 2 or 7. The authors are the library authors (Ken Sherriff and Christiano Borge).

The first 7 pins on my nanon are TX, RX, Reset, Ground (signal), D2, D3, D4, . . .

That is where you are wrong. Pin 7 in your sketch is marked D7 in white on the silkscreen of the Nano.
It is NOT an integrated circuit type numbering system.

6v6gt:
I asked about the baud rate because of this statement:
"95% of the time it does nothing. 5% of the time it does something weird, like print one random code continuously"

Just to clear that up, you should add a Serial.print statement to your setup() say Serial.println( "starting...") ; .

What IR source are you using to test the IR receiver / Nano combination ?

What is that IR receiver module you are using ? The diagram which appears near nano lying on its side seems to show that the centre pin is +5v. It is clearly not then a standard like the Vishay e.g. TSOP4838 where the centre pin is ground.

It is not very clear, but the orange wire to the Nano appears to go to pin D4. Not either D2 or D7 which you have mentioned previously. The other 2 wires appear to be power.

You can test the function of your IR receiver without an Arduino. The following simple circuit shows how:

Edit:

Crossed with @aarg

keys.JPG

I'll try to get a better pic later. But the diagram really says it all.

Let's begin with the reminder that when i swap in an UNO it all works perfectly. So the wiring ought to be fine. Sensors don't work with Gnd and +5 reversed :slight_smile:

I did nto say i was using D2 or D7. I said Pin 2 and Pin 7. Specifically "RX" or "D4" but I also tested others. It is connected to D4 in the pic.

On discrete IR devices the center pin is GND. On the PCB mounted modules center pin is +5 VCC. This is consistent.
The IR sources are many different remote controls - all of which work great with the UNO connected.

What else did you ask...? Ah yes, Serial rate. Always consistent and - go back to my original post -- proven fine since it works with programs such as "print ASCII table" and the initial serial monitor communications on these sketches works - it only fails when it demands receive pin input.
It bears repeating although i laid this all out in my original question above - the code in question is not mine - on purpose. It is KNOWN proven code. To eliminate any errors on my part i am starting with the demo code from the two IR library authors. Their code, their pin choices, their serial port speed demands. Not mine.

And, yet again, it works fine if a substitute an UNO into the setup without any other changes.

Once this works I'll upload MY code. This is a Nano compatibility question and issue.