Can you program the propeller with Arduino language / IDE?
perigalacticon
Posts: 5
in Propeller 1
I am a user of Arduino and Arduino IDE (and recently Atmel Studio) of about 2 years. I am interested in the Propeller board for the ability to use its multiple cores in a complex robot I currently control with a ATMega2650 with about 1000 lines of Arduino code.
I like the idea of running separate routines on separate cores simultaneously, because a RTOS looks a bit formidable for me, a non-professional programmer. Is it possible to run/program the propeller multi-core boards using Arduino 'core' code and language, and the Arduino IDE? I have learned some raw C++ AVR coding but prefer Arduino language as it is intuitive/user-friendly.
Thanks
I like the idea of running separate routines on separate cores simultaneously, because a RTOS looks a bit formidable for me, a non-professional programmer. Is it possible to run/program the propeller multi-core boards using Arduino 'core' code and language, and the Arduino IDE? I have learned some raw C++ AVR coding but prefer Arduino language as it is intuitive/user-friendly.
Thanks
Comments
Here's the thing: you're a programmer. It's a good idea to learn new languages because we always learn things in new languages that we find a way to use in our favorite. I really don't like the Arduino language (and I hate the IDE), but I've learned it well enough to help some of my cosplayer friends (and I frequently translate interesting bits of Arduino code to Spin). The one thing I do like about the Arduino is the millis() feature. The Propeller has a background counter, but it runs very fast -- great for short duration events, not so much for long duration. In many of my projects and professional products, I setup a cog to run a loop that is exactly one millisecond. Here's the simplest version of that code.
Now, it may seem silly to use a whole processor to run a 1ms timer, but we can if we have the resources. One millisecond is a very long time in microcontroller terms, so I use that background loop to do other things. For example, here's the top of the background loop for the EFX-TEK HC-8+ controller:
Note that it now calls three methods -- these allow the HC-8+ to manage a bi-color LED (which can be off, red, green, or yellow, and can flash between two colors), scans the TTL and DMX inputs (via two 74x165 shift registers), and scans/debounces four additional inputs. This background works makes the foreground code easier to manage.
You can of course jump right in to C programming for the Propeller -- it's available. Still, I think you would serve yourself well to learn Spin, too.
Have fun!
Each microcontroller or platform has specific syntax and compilers. The ArduinoIDE has "board" files to allow other microcontrollers and boards to work with the ArduinoIDE.
No one has made a propeller chip arduinoIDE board file, that I know.
Like JonnyMac says, just take some time to learn spin, you will see. Its easy. Download the spin ide now--> https://www.parallax.com/downloads/propeller-tool-software-windows
You can take the code for a 'spin' using a propeller emulator. https://sourceforge.net/projects/gear-emu/
I find that the more languages I am exposed to and work with, I find that many are very similar in their overall syntax, and the basic code structure says the same across languages, it seems too.
However, there is a project that was created some time ago (not much active development on it now) that brings some (many) of the core Arduino libraries to the Propeller. The repository is here, though the majority of its commit history was lost when Google shut down Google Code.
There is also PropWare, which I created for Propeller C and C++ developers to make their lives easier. There are two parts to PropWare: a build system and a set of libraries. If you are good at the command line, or willing to learn, then the build system will do a beautiful job of replacing the Arduino IDE for you. I'm a bit biased, but I think it's just the bees knees, the cat's meow, the snake's hips. If the command line seems a bit complicated though, then I would recommend you use Parallax's SimpleIDE for editing/compiling/running. There are instructions on PropWare's website for utilizing its suites of libraries within SimpleIDE (and that includes the above-mentioned libArduino).
Mike
TI has spun it's own Arduino variant called Energia which supports many of its ARM and MSP based boards so that might be a direction Parallax could look at. For me, SimpleIDE for the Propeller is close to what is offered with the Arduino IDE and has a good selection of libraries to pull from as DavidZ mentioned. But, having Propeller support in an Arduino IDE, perhaps a Parallax version of it, would be cool and may attract folks that are looking to continue using such a tool, but my preference would be to have a more robust IDE for the Propeller with a debugging option to step through the code.
I suppose "all you'd need" are header files with matching prototypes for the "functions" that you want to use. That might get complicated. I have no idea what the equivalent C header would look like for something like this:
I suppose you could use nm or the likes to get the symbol names. From there, I'm just guessing but I bet set_dir_out's C prototype would look something like this:
Still don't know what a constructor prototype would look like. I'd certainly be interested to see it! Interesting idea
It would probably be easier to write a C wrapper around the C++ libraries. Something like this:
Still seems like more trouble than it's worth though
Thank you very much, it is truly appreciated and respected.
-Mike R...
Glad you enjoyed it!
Assuming you understand the basic concept of "objects," (calling "methods" on objects, such as pin.set_dir_out()), using an existing C++ library shouldn't be too terribly difficult. You can write the rest of your application C-style of course. Aside from basic object concepts, I think there are only a few C++ specific features that you need to pay attention to in PropWare. I think this is how and why the Arduino libraries are so successful - they stick to reasonably simple C++ concepts that provide users with very straightforward interfaces to program to. PropWare definitely uses a few more complicated concepts, but not all that many. I think namespaces, static functions, and pass-by-reference are probably three of the biggest. The really important part is that you as the user do not have to design C++ code, you only have to use it.
Mike R...
The Propeller is a great microcontroller to use with robots.
Spin is pretty easy to pick up for someone with experience in C. I have a bunch of links to Spin tutorials and other Propeller related links here.
I've used the Propeller in all the robots I've built. I've documented some of my robots here on the Parallax forum (here's a list of most of my Propeller related projects) and I've also documented some of my robots on RobotRebels.org and Hackaday.io.
The multiple processors of the Propeller are really useful in robotic projects since you can dedicate a cog to monitor a specific sensor or to control a specific device.
For example, I've seen lots of Arduino users struggle with monitoring four quadrature encoders while controlling four independent motors. I used a Propeller to monitor the four quadrature encoders and control the four motors on my Mecanum wheeled Rover 5. Besides interfacing with the motors and encoders, the Propeller also monitors the pulses from six RC channels. These multitasking programs are (relatively) easy and fun to write in Spin and PASM.
Not only is the Propeller a very powerful microcontroller, I also think it's a lot of fun to program. I program a variety of processors using a variety of languages but it's always a treat when it's time to write a program on the Propeller using Spin.
bbrien.