Arduino Uno - Leonardo Incompatibility?

At The Ohio State University we have used Arduino Leonardos since 2018 for teaching engineering students. However, the mini USB and surface mount microcontroller meant that we replaced boards regularly. This semester we "upgraded/downgraded" to Arduino Unos for the more rugged USB and a replaceable DIP microcontroller. However, the sketches we've used successfully for several years don't seem to run properly on the Uno. The sketch would load and run, but become erratic after a few seconds to a few minutes. Resetting the micro did not fix the problem, but reloading the sketch would fix it. Sometimes (often) reloading the sketch would permanently fix the issue, but I am finding a few Unos that still crash. I retried the code on the Leonardos, and they are rock solid as always have been. Yes, we are selecting the correct board in the IDE, and the upload is always labeled as successful. Last week was awful! Veterans Day holiday gives me a little extra time to solve this. This is all very simple, basic code. What's happening???

We have tried several computers -- both Mac and PC -- and the results are similar. I am running a simple "analog voltage in-echo to serial monitor that works just fine for the Leonardo, but does not even put anything to the monitor when attempting the same sketch on Uno.

For this specific case, I am on a Mac, OS 11.6. Arduino 1.8.13.

Leonardo GOOD;
Uno NOTHING displays on monitor.

Please read the first topic "How to get the best from this forum."
You posted quite a numbers of words telling nothing useful to us, complete newbie helpers, regarding Your project.

Leonardo/Micro and UNO use different microcontrollers. The are similar, but not exactly the same.
Without seeing the sketch ( and schematic ), we cannot tell if the differences matter for your sketch.
Please use code tags when postiong the sketch.

Yep , have a look at the specs and data sheets , look at compilation results etc , you should be able to identify the issues…

@cgecik, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project.

The voltage into the Arduino is a 10K potentiometer connected between 5V and Ground Power pins on the Arduino header. The wiper of the pot is connected to one of pins on the Analog In header. (Arbitrarily A1 because students use -- and damage A0). I hope a schematic is not needed of this simple input.

I am running MacOS 11.6, with Arduino 1.8.13. Another Mac I tested is MacOS 10.14.6 with Arduino 1.8.13. I have also tried this experiment with Windows 10, but do not have the information for the "lab computers."

Everything compiles and uploads with no errors, even in verbose mode.

Sample code below illustrates the problem; Arduino specifics are in comments.

Thank you!

/*
  FABE 5160
  Uno vs Leonardo Troubleshooting
  Read an analog input from a 0-5V potentiometer and display the number on the serial monitor
  This count should be between 0 and 1024 for a 0V to 5V input.

  C Gecik
  7 Nov 2020 Rev 0.0
*/

//Declare and initialize all variables and constants

//pin variables
int inputPin = A1; //Vout from a 10K potentiometer connects to an analog input
//The choices here are A0, A1, A2, A3, A4 or A5
int inputValue = 0;  // variable to store the voltage reading from the potentiometer

//constants
int delayTime = 100; //the time in milliseconds between each iteration of the loop which samples and displays

void setup() {
}


void loop() {
  //Read and store analog voltage input
  inputValue = analogRead(inputPin);

  // send to monitor the ADC count
  Serial.print("ADC Count: ");
  Serial.println(inputValue);

  delay(delayTime); //time delay between successive samples
}

/*
  BN: Arduino Leonardo
  VID: 2341
  PID: 8036
  SN: (null)
  Purchased in 2018, used with lots of students
  WORKS!


  BN: Arduino Uno
  VID: 2341
  PID: 0043
  SN: 85033313137351A0E082
  Purchased October 2021, never used successfully
  NOTHING DISPLAYS ON THE SERIAL MONITOR!
*/

You are missing the call to Serial.begin() in setup:
https://www.arduino.cc/reference/en/language/functions/communication/serial/begin/

I recommend this:

Serial.begin(9600);

the reason is that the students must have the baud rate in Serial Monitor set to match the baud rate specified in this line and 9600 is the default baud rate of Serial Monitor.

You will need to keep an eye on that in case they have changed the setting. Due to being a native HID USB device, the baud rate setting doesn't matter on the Leonardo, but the Uno's ATmega328P microcontroller doesn't have this native USB capability so the setting in Serial Monitor or any other serial communication software used on the computer must match the baud rate set in the Serial.begin() call in the sketch that is running on the Uno.

Thank you!

I wonder now if there are other missing details that don't matter to the Leonardo but must be explicitly stated for the Uno.

Yes. Anything to do with the timers can be different on the two processors.

Also look at memory the Leonardo has more SRAM so code could run out of memory on the UNO where as it would not on the Leonardo. Look at the compile output to see how much each is using as a percentage of the total. Running out of memory would cause erratic behaviour like you describe.

I would suggest this has nothing to do with the computer you use to program the two processors.

You are welcome :smiley:

Here is one:
https://www.arduino.cc/en/Reference/Wire

Board I2C / TWI pins
Uno, Ethernet A4 (SDA), A5 (SCL)
Leonardo 2 (SDA), 3 (SCL)

This is a good reason to always use the dedicated I2C bus pins (marked "SDA and SCL") on the boards instead of the other places they are broken out (e.g., A4, A5 on the Uno). The dedicated I2C pins are in the same place on both boards, and on the other boards that use the Uno and Mega style form factors.


Same situation with the SPI library:
https://www.arduino.cc/en/reference/SPI

Arduino / Genuino Board MOSI MISO SCK SS (slave) SS (master) Level
Uno or Duemilanove 11 or ICSP-4 12 or ICSP-1 13 or ICSP-3 10 - 5V
Leonardo ICSP-4 ICSP-1 ICSP-3 - - 5V

The SPI bus is always broken out to the ICSP header on these boards, so as long as you always use those pins then there is no noticeable inconsistency in this respect.

Also the PWM pins are different in a few cases see
PWM Pinout

And the Leonardo has some pins with alternate functions that are not available on the Uno.

Note both the PWM pins and alternate functions on this diagram. It is how I bought the Leonardo outputs to an external socket so the socket positions don't mean anything to you, but if your code uses some of these functions it will not work with a Uno.

That is if you use A6 to A10 that will not work on a Uno.
Likewise if you use Digital pins 18 to 21 that will not work on a Uno. On a Uno the A0 to A3 pins can be used as digital pins 14, 15, 16 & 17.