

programming question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

programming question

by skygunner58203 on Sun Jul 28, 2019 12:33 pm

So, I'm trying to build the Guardian Robot from the site. I have everything printed, I've got most of my parts. The one thing I don't have is the trinket. Now, I can probably pick one up at work on friday, but I've been putting it off (mostly due to laziness). I DO, however, have sparkfun 5v pro micro board. Its the one with the 32u4 chip. Its about the size of the trinket, maybe slightly larger, and would fit. How would I go about converting the project code to run on the pro micro? I'm a complete noob when it comes to coding, btw.

Posts: 1
Joined: Tue Apr 03, 2018 5:11 pm

Re: programming question

by adafruit_support_mike on Sun Jul 28, 2019 12:58 pm

Most of the code should port over directly. The 32u4 is a more powerful microcontroller than the Trinket’s ATtiny85, so you’re moving to an easier platform.

The general process of porting code from one microcontroller (or language) to another starts with reading the existing code and trying to understand what it does. Things written in terms of the core language, like math expressions, usually transfer directly.

Things like register setting usually mean the programmer was trying to do something using features of the original chip. That code usually won’t work on a new platform, so you have to figure out what it’s doing and then look for a way to do the same thing on the new platform.

If the code is well organized, the platform-specific parts will be isolated, and the rest of the code will use wrapper functions around the low-level stuff.

There’s a term called ‘programming in the large’ that describes the way code is arranged. Ideally, you write low-level functions that perform the most hardware-specific operations, and wrap them in descriptive names. The next layer of functions are written using those, and perform more complex operations. They also have descriptive names, which you can use in the next layer up. The idea is to replace as much of the basic language syntax with functions and variables you’ve created, and which describe what the code is doing. When you work that way, writing the code becomes a process of creating a language to describe the problem you’re trying to solve.

In general, the high-level stuff you’ve defined is easy to port to any other platform. The low-level parts are the ones that break. That’s not such a bad problem if all the low-level and breakable stuff lives inside functions you’ve defined though. The low-level parts should perform well-defined operations that are fairly easy to understand. One you get those working, the higher-level code inherits the new working version.

Posts: 61107
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.