The Detroit Post
Tuesday, 19 October, 2021

Rust For Arduino

author
Brent Mccoy
• Sunday, 27 December, 2020
• 10 min read

When getting into the programming world to develop my Arduino projects, the last thing I heard was from RUST. One of the advantages of RUST is that it has memory efficiency and does not require garbage collection of data space at runtime, which seems to be of benefit for the kind of projects I was into and led me to think of the possibilities to program Arduino with RUST.

(Source: makezine.com)

Contents

Yes, you can program Arduino with RUST and enjoy its benefits of memory-safety, concurrency, reliability, and speed for your projects. You’ll enjoy creating exciting projects with Arduino, once you know the basics of RUST.

Nowadays, due to its accessible prices and open source philosophy, Arduino gives access and an opportunity to many people around the world (from students to established engineers) for experimenting, explore new frontiers and even showcase base ideas, gadgets, and useful projects. But, let’s dive deep into what is the relationship of Rust with Arduino, without bringing too much tech, of course.

While RUST is not the name you often hear even if you are into reading some tech-papers or news articles, it is a powerful language. The advantage of RUST is that it has memory efficiency and does not require garbage collection of data space at runtime.

The incredible user-friendly environment and easy to understand error throwing messages of Rust make life easier. Another feature that RUST brings is that it is an excellent language for embedded systems, which means it can quickly and efficiently work with other hardware devices and tech-architectures.

With this main feature and philosophy on which RUST was built in 2006 by Gray don Hear, and when Mozilla officially announced it in 2010, it offers speed, concurrency, and safety. From a safety perspective, it means that it doesn’t leave a lot of footprints.

garden diy decor crafts decorations whimsical metal cheap projects decoration easy backyard upcycled fairy party painted thenavagepatch gardens spray project
(Source: www.pinterest.com)

The safety and reliability of RUST, plus aesthetics, flexibility, and security of Arduino, asked for such a relationship between these two. With this relationship, the future of robotics and technical projects is something the RUST team can be a part of.

Why the Basic Features of RUST Offer Bright Future for Embedded Programming? These types of nuisances occurred due to random memory allocation of C and C++ languages.

With RUST landing in the programming world, developers can feel free to try new grounds of features and functionalities. RUST keeps track of this ownership; in other words, it knows that you’re the owner of this code or instructions.

Meaning if you’re working on a robot with Arduino as the microcontroller and using RUST, you can have peace of mind about the safety of your project, because only you can use this code of instructions and no one can steal it form you. The answer is a big yes, you should learn Rust as soon as possible as it holds the future of robotics.

You’ll enjoy creating exciting projects with Arduino, once you know the basics of Rust. As a project-maker or even Arduino -lover, learning Rust now would prove to be a very significant and timely decision.

tool bottle capper press drill makezine
(Source: makezine.com)

I am Francis, a passionate physician, and entrepreneur who loves helping people to find high-quality products, services, and info that bring them solutions. At the time of writing this, about a month ago, the rust AVR fork was merged upstream.

This means that you can now compile Rust programs for the AVR microcontroller board by just running cargo +nightly build, providing a.cargo/config.Tom for your target (avr-unknown-unknown). I have always been fascinated with the idea of using code to manipulate and affect physical objects.

This is probably going to be a series of blog posts on my adventures with Rust on Arduino and maybe ESP8266 and discovery F3 in the future. Target audience : This post is written with beginner to intermediate folks in mind who want a head start with embedded systems in Rust with Arduino.

Once you have gone through this post, you may want to go through the basics on embedded rust book. We'll take a whirlwind tour on how to run Rust on the Arduino UNO, which is probably the most widely known and used development board in the hobbyist embedded domain.

The Arduino UNO is based on the ATmega328P, which is an 8-bit microcontroller falling under the family AVR. AVR is a family of micro-controllers developed since 1996 by Armed, which was later acquired by Microchip technology.

clock combo colored brightly tachometer tach related cars saab thetruthaboutcars greden murilee phil martin courtesy
(Source: www.thetruthaboutcars.com)

If you want to read more about that, head over here: AVR- Rust book For this we'll need to switch to the nightly tool chain as some dependent crates use unstable features to make all of this happen.

The above command overrides the tool chain of choice for only our current directory to be nightly. The Arduino hardcore package contains utilities such as argued which is a tool to upload and manipulate ROM and EEPROM contents of microcontrollers using the in-system programming technique.

I am on an arch Linux distro (endeavor OS) where Pac-Man is our package manager. We'll also need to add build metadata for cargo for the AVR target.

We are in an embedded environment which doesn't have functionalities that the standard library crate of Rust depends on such as heap allocation APIs, threads, network APIs etc. We then add use statements to bring the required items in scope from the dependent crates.

In the standard library panicking has a defined behavior: it unwinds the stack of the panicking thread, unless the user opted for aborting the program on panics. In programs without standard library, however, the panicking behavior is left undefined.

traffic light lights signals stand collectible signal crouse hinds way tl
(Source: www.pinterest.com)

Then we have our main function annotated with the entry attribute macro from the Arduino _UNO crate. To blink the LED, we only need a few lines of code and set the relevant pin high or low.

Most microcontrollers, if not all, contain pins that allow the device to both read and write digital values to external circuits. A port is a group of pins representing a standard interface.

We need access to the pin in our code in order to manipulate the LED, i.e., set it high or low. Examples of peripherals would be your timers, counters, serial port etc.

An embedded processor interacts with a peripheral device through a set of control and status registers. DDR register determines if pins on a specific port are inputs or outputs.

I still need to do a bit more reading to fully understand DDR registers. Next, we go into a loop {} and call stutter_blink function providing a mutable reference to our LED instance and number of times (25) that we want to blink.

sandblaster pot pressure diy homemade tools blaster sand nozzle knoba blasting sandblast own glass crushed projects nozzles pots tungsten propane
(Source: knoba.wordpress.com)

We create a range (0.times) followed by calling map so that we can progressively delay the LED toggle by a noticeable amount. We could have definitely done this using a for loop and that would be more readable, but I wanted to demonstrate that we can use all the high level APIs and abstractions from Rust.

Let's create a script at the root directory named flash.sh that does cargo build followed by flashing it our UNO: I have several embedded hobby projects in plan, I will be writing about them in future as they progress.

If you want to follow the latest in development in Rust embedded space, follow the embedded rust working group At the time of writing this, about a month ago, the rust AVR fork was merged upstream.

This means that you can now compile Rust programs for the AVR microcontroller board by just running cargo +nightly build, providing a.cargo/config.Tom for your target (avr-unknown-unknown). I have always been fascinated with the idea of using code to manipulate and affect physical objects.

This is probably going to be a series of blog posts on my adventures with Rust on Arduino and maybe ESP8266 and discovery F3 in the future. Target audience : This post is written with beginner to intermediate folks in mind who want a head start with embedded systems in Rust with Arduino.

axe head why hang instructables know flies
(Source: www.instructables.com)

Once you have gone through this post, you may want to go through the basics on embedded rust book. We'll take a whirlwind tour on how to run Rust on the Arduino UNO, which is probably the most widely known and used development board in the hobbyist embedded domain.

The Arduino UNO is based on the ATmega328P, which is an 8-bit microcontroller falling under the family AVR. AVR is a family of micro-controllers developed since 1996 by Armed, which was later acquired by Microchip technology.

If you want to read more about that, head over here: AVR- Rust book For this we'll need to switch to the nightly tool chain as some dependent crates use unstable features to make all of this happen.

The above command overrides the tool chain of choice for only our current directory to be nightly. The Arduino hardcore package contains utilities such as argued which is a tool to upload and manipulate ROM and EEPROM contents of microcontrollers using the in-system programming technique.

We then add use statements to bring the required items in scope from the dependent crates. In programs without standard library, however, the panicking behavior is left undefined.

n6qw transceiver radio brew transceivers ham filter projects transmitter pete juliano receiver kit
(Source: www.qsotoday.com)

Then we have our main function annotated with the entry attribute macro from the Arduino _UNO crate. To blink the LED, we only need a few lines of code and set the relevant pin high or low.

Most microcontrollers, if not all, contain pins that allow the device to both read and write digital values to external circuits. We need access to the pin in our code in order to manipulate the LED, i.e., set it high or low.

An embedded processor interacts with a peripheral device through a set of control and status registers. DDR register determines if pins on a specific port are inputs or outputs.

I still need to do a bit more reading to fully understand DDR registers. Next, we go into a loop {} and call stutter_blink function providing a mutable reference to our LED instance and number of times (25) that we want to blink.

We create a range (0.times) followed by calling map so that we can progressively delay the LED toggle by a noticeable amount. We could have definitely done this using a for loop and that would be more readable, but I wanted to demonstrate that we can use all the high level APIs and abstractions from Rust.

paint lawnmower job flaming
(Source: www.instructables.com)

Other Articles You Might Be Interested In

01: Tng Real Estate Long Beach
02: Tng Real Estate Long Beach Ca
03: Tnt Real Estate Bakersfield
04: Occidental Real Estate Wichita
05: Oceanfront Real Estate San Diego
06: Oceanfront Restaurants Virginia Beach Va
07: Oceanside Real Estate Jacksonville Beach Fl
08: Ocean City New Jersey Real Estate For Sale
09: Xperience Real Estate Austin Tx
10: Dhr Real Estate San Antonio
Sources
1 dhrrealestate.com - https://dhrrealestate.com/
2 dhrp.us - https://dhrp.us/
3 www.yellowpages.com - https://www.yellowpages.com/san-antonio-tx/mip/dhr-real-estate-460682659
4 www.mynd.co - https://www.mynd.co/
5 www.ccmcnet.com - http://www.ccmcnet.com/
6 www.costar.com - https://www.costar.com/about/contact
7 ctot.com - https://ctot.com/
8 www.uiw.edu - https://www.uiw.edu/about/index.html
9 www.alamo.edu - https://www.alamo.edu/sac/admissions-aid/