27 The UNO: Special Considerations

The 8 bit Arduino UNO is often thought of as the Arduino, however it is starting to look dated for those whose first experience comes with a more powerful processor like the 32 bit M0 you find on the Itsy Bitsy and other boards. Here are some special details to consider if you need your code to run on an UNO:

Tiny Memory

With only 2K for variables and 32K for code, you will very quickly run out of space and crash, especially if you want to use libraries to support SD cards or displays. Watch out and heed the warnings at compile time.

Smaller Variable Storage Sizes

Because the memory is so small, the UNO compiler uses smaller data space as a default for all types. Integer types are stored in 2 bytes, 16 bits, while all floating point values are stored as 32 bit single precision, even if declared as doubles. Your floating point arithmetic will be imprecise and you will need to use the ‘long‘ modifier if you want 32 bit integers. You can check the size of any variable using sizeof().

  • use unsigned long timeNow = micros(); to get a variable large enough to count the full range of over 4 billion microseconds.
  • use long int sum = 0; for averaging if you want to sum more than about 30 analogRead() values without overflowing.

No Formatted Printing

If you like Serial.printf() to provide formatted output, you will be annoyed to go back to a sequence of  Serial.print() calls for one thing at a time.

Serial Speeds Must Match

The USB interface on the UNO is not smart enough to auto synch. This means you need something like Serial.begin(115200); in your setup() code and the speed has to match with the setting on the serial monitor.

ADC Resolution Fixed at 10 bits

All of the UNO analog inputs read with a 10 bit resolution (0-1023), compared to 12 bit or higher with newer processors. The analogReadResolution(bits) function is not available to scale input values to higher resolution on the UNO.

 

License

Icon for the Creative Commons Attribution-ShareAlike 4.0 International License

Rick's Measurement for Mechatronics Notes Copyright © 2019 by Rick Sellens is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License, except where otherwise noted.

Share This Book