View Full Version : [Discussion] Arduino Uno vs. Raspberry Pi Zero robotics performance

04-07-2016, 05:18 AM
How does execution speed compare between a 16MHz Arduino Uno and a 1 GHz RPi Zero? For instance I read that A/D conversion is max 9kHz for Arduino and loop speed for one io pin write only is about 100kHz. Do you have any good references that compare the speed of running similar code or functions on the RPi and Arduino? I am mainly interested in comparing the speed of robotics type functions.

A more practical question, if you implement the same robotic functions in both, would you notice differences or improvements if using the Pi instead? Things like reading sensor values, simple calculations, moving servo and stepper motors (aside from more complex things like vision and voice recognition).


04-07-2016, 01:52 PM
An Uno uses an 8-bit AVR microcontroller that runs only the sketch you compile with no intermediary (like an OS) required, while the various Pi versions use 32/64-bit ARM requiring an OS and running any, and as many, programs you want. The PiZero has no ADC and requires a complete OS that will likely not have a real-time kernel. The PiZero can control external digital devices easily enough (as long as the logic level is no more than 3.3V) using its hardware serial communication ports (UART, I2C, and SPI), but may not be as responsive with plain digital pin control as the Uno using its hardware PWM and easy pin manipulation. If you are using any USB devices like webcams or commercial lidar units, then the Uno is not an option. If you are wanting to interface to multiple analog or non-UART digital sensors, the Uno is the better choice as it can perform admirably on its own and further act as a USB connected sub-controller for a PiZero. The Uno also runs at 5V, so does not require level-shifting to interface to 5V sensors.

04-07-2016, 06:33 PM
The Raspberry Pi runs several of orders of magnitude more code per millisecond. If you include the GPU, you can add another order of two of magnitude.

However, the problem you're asking about has nothing to do with the execution speed. Instead, there is a built-in limitation to the frequency at which you can read the ADC device. A faster CPU coupled with a slow ADC will just spend more cycles doing nothing, waiting for the ADC to return the value, which is a waste. Although a better OS will let other parts of the program do work while the ADC is busy working -- this is what threads and processes is for.

The Raspberry Pi has different peripherals than the AVR. The serial port can run faster, and has more buffering. The GPIO can toggle really fast, but only if you use a very low-level API; most sample code use wiringPi or Python or even file I/O to the /sys/class/gpio file system, which is slower per-pin, but provides other benefits. Meanwhile, the Raspberry Pi has very few PWM channels, and has no ADC at all.

The difference between a "microcontroller" and a "microprocessor" is typically just that -- the microcontroller has more peripherals (I2C busses, SPI busses, GPIOs, PWM channels, UARTs, etc) and the "microprocessor" focuses more on actual code (math) execution.

If you want an easy-to-program microcontroller that runs faster than the AVR / Arduino Uno, yet has a robust set of peripherals (and also is 5V tolerant) then you can't go wrong with the Teensy 3.2. It's great!
My robot actually uses a Raspberry Pi for vision/camera/configuration/smarts, and a Teensy 3.2 for the low-level device interfaces (UARTs, GPIOs, PWM, ADC, etc.)
The Teensy3.2 has higher-performance devices than the AVR for most things (including three UARTs with deep FIFOS plus USB!) and a faster CPU (the ARM Cortex M4.) It's still less than 1/10th the CPU speed of one core of the Raspberry Pi if you want to use heavy lifting math.