How to Port Your Software from Raspberry Pi to Arduino Pro

This article is for technical leaders or managers with an existing prototype based on the Raspberry Pi who need to migrate to a more production-ready platform like Arduino Pro. Individuals about to build their first prototype with Raspberry Pi who would like to craft their firmware to more easily port to an Arduino Pro as their product scales will also find this helpful.

After reading this article, you should feel confident identifying which tier of product growth you are in, understand how the Raspberry Pi and Arduino Pro platforms fit into product development, and have a clear path forward to plan your porting activity.

Why Do We Care? (And Why Should You)

Dojo Five has built its reputation on providing modern firmware development coaching, tools, and training to enable faster speed to market and higher quality firmware, ultimately setting the stage for scalable hardware organizations or organizational change at evolving products companies.

We see projects come in often from companies that have gotten a foothold in a market using a Raspberry Pi based system, but then are overwhelmed by the product scaling process. This article is intended as a strategic guide to help those companies identify common pitfalls and mitigate risks that we have seen in the industry. We believe this knowledge will help your organization make better decisions leading to greater success.

Before We Start…

The Raspberry Pi and Arduino platforms have seen amazing growth and success over the past decade. Both have found their niche, and both have ardent fans who believe strongly in one or the other (and sometimes both!). This is not an article intending to choose a winner. In fact, this article argues that each has their place in the product development lifecycle.

Also, Raspberry Pi and Arduino are sometimes used in one-off art installations, hobbyist projects, and prototypes. If that’s you, just know that this article is more business focused and we make points keeping in mind a product that is destined for sale.

Production Run Sizes

When building hardware products, a variety of product development techniques can be used. When to use each technique often follows the quantity of your intended production run. These can be grouped by orders of magnitude. Check out the following table for the basic idea:

QUANTITY TYPE DESCRIPTION
1-10 One-Off Devices Hand-crafted, labor intensive. Often you can get away with “frankenstein” or “roadkill” devices, with wires in an oversized enclosure.
10-100 Small Hobbyist Projects Typically a small run of bare PCBs and soldering parts on yourself.
100-1,000 Niche Projects Custom enclosure, possibly 3d printed, with custom PCB. Managing NRE is critical. Customer expectations increase.
1,000-10,000 Small Business You have chosen a manufacturing partner who is providing box build services. Customer service will dominate costs if hardware or firmware is buggy.
10,000-100,000 Medium Business Likely chip-down PCB. Cost is beginning to dominate.
100,000-1,000,000+ Large Business Cost optimized, chip-down. Pennies matter. You are likely manufacturing overseas. Large NRE costs. Enterprise-level product.

A company with a scalable product will naturally go through the above product growth stages.

The Raspberry Pi naturally lends itself to the earlier stages, from One-off to the Small hobbyist stage. It is cheap, has a lot of compute, and has a variety of I/O options to support any number of potential sensors and design updates. However, as NRE and support costs begin to dominate the business model, a change is needed to the hardware design to see continued success.

A SOM (System on Module) based design is a solid choice for the mid-market product tiers, from Niche projects to Medium business. This design leverages the commonality of the microprocessor electronics and puts them on a daughter-card, which is then married to a carrier board or peripheral board that is custom to the application. This allows a number of design improvements while avoiding the NRE costs of a full custom design.

Typical Issues with Raspberry Pi at Niche and Small Business Scale

Congratulations! It’s exciting to find success and start thinking about the next step for your product. However, you may be experiencing one of the following issues that is making your original beloved prototyping solution of the Raspberry Pi seem not-so-great:

1. The Raspberry Pi Is Power Hungry

You may have an application that does asset tracking, sensor telemetry, or some kind of remote control or measurement. If your device has a battery, it’s likely that you’re starting to hear complaints about battery life.

2. The Raspberry Pi Runs Hot

If you’re putting the Raspberry Pi in an enclosure of some kind, you’ll find that ventilation becomes important. There’s a reason that active cooling (fans) and large heatsinks are sold as add-on kits for the Pi. It’s because the device becomes unstable at high temperatures. If your device operates outside, you need additional margin to ensure it operates properly even on the hottest summer day.

3. The Raspberry Pi Is Not Real Time

If your product is flaky, sluggish, slow, or has difficulty keeping up with real time control applications, you will likely need to migrate to a different platform to solve your issues. Without software heroics, the Raspberry Pi is meant to run Linux – and it does it well. It’s just that Linux is difficult to get to run real time for any control loop applications.

4. The Raspberry Pi Takes A Long Time To Boot

Consumers expect their devices to start working the instant they turn on, and are becoming more impatient with each passing day. As you add drivers and peripherals to the Pi, the boot time becomes even longer. If you want to put the device into a deep sleep mode for better battery life, you are waiting for this boot every time it wakes up. You can spend additional dollars to optimize the boot time, and you might get below 10 seconds. Anything less takes increasing amounts of time and money.

5. The Raspberry Pi Takes Work To Secure

Security for any connected device is increasingly important, and in some countries is now regulated by law. Whether regulated or not, your device becomes an instant threat to your business if you don’t have a security strategy. User data can be leaked, devices can be hijacked and used to dive deeper into your customers’ personal networks, and worse. It is possible to secure connected Raspberry Pi devices, but it’s a difficult task, and you need to stay on top of it for the lifetime of your product. This not only includes your application, but the multitude of Linux kernel and associated distro applications that are shipped with it, many of which you probably aren’t even using.

6. What Happens If Your Application Crashes?

Do you even know what happens if (when) your application crashes? After decades of software development, it is still very difficult (impossible?) to write bug-free code. You mitigate it with solutions like watchdog timers, fault handlers, and graceful hardware safe modes. Do you know what your Raspberry Pi application does in this case? What do your users experience? It’s tricky to get this right on the Raspberry Pi.

7. Raspberry Pi OTA Updates Are Big

You did think about how you’re going to update this thing in the field, right? If you only update your application, you are leaving a gaping hole in your security posture since vulnerabilities are discovered all the time in the panoply of utilities shipped with a typical Linux root filesystem. And updating the full system can be many many MBs. Do your customers pay for that data, or do you?

Ok, I Get It, It’s Time To Transition To a SOM (Like Arduino Pro)

Hopefully we’ve convinced you that while you could stick with the Raspberry Pi in your design for 1,000 units and beyond, you probably shouldn’t. A SOM is a great choice for the middle tiers, and the Arduino Pro is a great choice. Its small form factor, large amount of support materials online, industrial temperature rating, low power modes, and short boot times address the issues mentioned above.

But, you say, I already have the software written for the Raspberry Pi. How do I port it to Arduino Pro? I don’t want to rewrite the software from scratch!

Well, there’s good and bad news. Depending on how you have written your code, you will either have an easy port, or a not-so-easy port. On the next page we will cover a few of the stickier points and how to approach your porting activities:

1. Convert Your Logic to C

This one is the biggie. If you wrote your Raspberry Pi code in Python, you can use it on Arduino Pro by installing their MicroPython kernel. However, our recommendation would be to rewrite your logic in C.

I know, I know, that sounds like a huge effort. Just know that your product will be much better situated to port to other platforms in the future. Also, when your product hits it big and you need to hire on help, you’ll have a much easier time finding embedded C contractors or employees than any other language.

C is the de-facto standard in embedded, and is well supported by the Arduino Pro tools. Luckily, the porting is generally straightforward, and there are lots of examples online. There are even some AI-based Python to C converts (although I would definitely double-check the results!!!).

To reiterate, every silicon vendor on the planet provides a C SDK for their chip. Only a select few provide a Python environment. At this point, you’re best served with your logic in C.

2. Remove POSIX References

Linux uses a standard called POSIX which provides a common API for all the niceties that an OS provides, among other things. Use of a filesystem, inter-process communication, and multi-threading in your application all need to be ported to use firmware concepts.

Luckily, this is easy with the use of the vast libraries available for Arduino Pro devices. If your device is running mBed (like the Portenta H7), you have a full RTOS available to you. Or you can bring a third-party library like protothreads.

This blog post on the Digikey portal provides some examples on how to do this: https://www.digikey.com/en/maker/tutorials/2022/how-to-write- multi-threaded-arduino-programs#:~:text=Using%20the%20 Arduino%20IDE%20and,up%20multi%2Dthreading%20can%20achieve

If your application had been writing to the filesystem, a small adjustment is needed to bring in a flash file system like SerialFlash, which has APIs very similar to those you may have been using in the Linux world: https://github.com/PaulStoffregen/SerialFlash

3. Update Your Drivers

The last two items were the meat of the changes you’ll need to make. It gets much easier from here. Arduino has a vast library of drivers for all sorts of sensors and peripherals that can be easy to bring into your firmware. Search for the drivers on Arduino’s site, which currently lists almost 7,000.

Take an inventory of which drivers, peripherals, and sensors you need to support and search for the driver availability. Odds are it is available.

4. Startup Code Just Goes Away

On Raspberry Pi and Linux, your application was probably started by bashrc, crontab, or systemd startup scripts. Any one of these requires you to familiarize yourself with the intricacies of Linux administration, or blindly follow a blog post and cross your fingers they know what they’re talking about. If it doesn’t work, your device appears to be a brick.

On a bare metal / RTOS device, your application just loads. You start a thread, or you write your main() code, and it just loads. You’re done.

5. OTA is Solved

Arduino Pro has an OTA solution that is fast, small, and secure: https://docs.arduino.cc/tutorials/portenta-h7-lite-connected/over-the-air-update/

If you don’t want to be locked into the Arduino Pro ecosystem, there are many other OTA providers that provide solid OTA solutions which can be easily integrated into your system. While the amount of data used by these solutions may differ depending on technologies used, it certainly is not as big as a full Linux system, so it won’t break the data budget.

Also, please don’t roll your own OTA solution. Grab a solution that is battle tested. The worst day in any hardware product company’s life is the one where you roll out an update that bricks your devices.

6. Power Management

Managing power in an RTOS or bare metal environment is much easier than in Linux. You know exactly what is running, who is using what devices, and you can manage each resource individually. This is how the pro’s get battery life that’s 10x the competition.

Double check that the drivers you are using support power management, read up on how your RTOS manages power, and get a tool like Nordic’s PPK or the Joulescope to measure your power accurately.

Key Takeaways

  • The Raspberry Pi is a great platform for prototyping, but it has several limitations when it comes to scaling up to production.
  • Arduino Pro is a great alternative to the Raspberry Pi for production devices. It has a smaller form factor, larger amount of support materials online, industrial temperature rating, low power modes, and short boot times.
  • Porting code from Raspberry Pi to Arduino Pro does require work, but it is possible with some careful planning and execution.
  • Awareness of the various platform needs as your product scales allows you to build your application firmware in a way that will reduce your total cost of ownership.

In Summary

In summary, the Raspberry Pi is a great platform for prototyping and small run products, but there are a multitude of reasons to graduate to a SOM like the Arduino Pro when you get to a serious quantity of devices. The transition does take some work, but it reduces risk in many areas, provides the features and functionality that customers expect, and ultimately sets your business up for scalable success in the future.

Dojo Five can help you with your porting needs. We have senior firmware engineers ready to help on your project and our EmbedOps platform that brings turn-key DevOps practices into the embedded space. We bring modern tools, techniques, best practices, and leading-edge innovations in firmware to our customers, helping them build successful products and happy clients. Need help? Have questions? Give us a call or contact us directly.

Sign up to get our content updates!

Unlock the full potential of your embedded projects with our expert insights! Dive into our comprehensive resources to stay ahead in firmware development. Subscribe now to get the latest best practices and guides delivered straight to your inbox.

Sign Up for Updates