Shop OBEX P1 Docs P2 Docs Learn Events
Can you program the propeller with Arduino language / IDE? — Parallax Forums

Can you program the propeller with Arduino language / IDE?

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

Comments

  • In my opinion, Spin -- the native language of the Propeller -- is far friendlier than Wiring (the C++ variant used by the Arduino). Spin is clean and elegant, and tied directly to the architecture of the Propeller. It's uses byte codes, so it's not as fast as a compile language, but where speed matters, PASM (Propeller Assembly) language is available and much easier than AVR assembly (IMO).

    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.
    var  
    
      long  bcog                                                    ' background cog #
      long  bcstack[64]                                             ' stack for background cog
                                                                     
      long  millis                                                  ' global milliseconds register
                                                                     
                                                                     
    pri background | t                                              ' launch with cognew()                                         
                                                                     
      millis := 0                                                    
                                                                     
      t := cnt                                                      ' sync loop timer
      repeat                                                         
        waitcnt(t += MS_001)                                        ' run loop every millisecond
        ++millis
    

    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:
    pri background | t                                              ' launch with cognew()                                         
                                                                     
      millis := 0                                                    
                                                                     
      t := cnt                                                      ' sync loop timer
      repeat                                                         
        waitcnt(t += MS_001)                                        ' run loop every millisecond
        ++millis
        refresh_rg_led                                              ' update the R/G LED
        scan_ttl_ins                                                ' re-scan TTL & DMX inputs
        scan_option_ins                                             ' re-scan option pins
    

    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!
  • . Is it possible to run/program the propeller multi-core boards using Arduino 'core' code and language.

    Thanks

    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.

  • I would be interested to hear your reaction in moving from Arduino-land and becoming a Prop-head. I am trying to branch out the other way, mostly driven by the larger memory resources available on the new 32 bit Cortex Arduino-clones (Feather) from Adafruit. My bits will arrive today in fact. I have resisted C and its variants for 40 years, but it is time to learn new tricks, as JonnyMac would say. I miss thinking about independent processes already ...
  • I have not seen or heard of anyone using the Arduino IDE to program the Propeller (sounds like an awful idea :P I really dislike that IDE), so you may well be out of luck there.

    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).
  • David, how difficult is it to utilize the PropWare libs as part of a C program as opposed to C++? I very much like your clear, concise documentation but am not as comfortable with C++ as I am with C. Old dogs, new tricks, all that... :-)

    Mike
  • The Arduino IDE is just a front end for the actual code that is created for any Arduino IDE supported device and is really just a prototyping environment. To do any real development, you would need to step away from the Arduino IDE and learn what is happening in the background with all those libraries that are created for you. Also, from what I have seen, there is no debugging option in the Arduino IDE, so you would really be better off using something like ATMEL Studio, IAR or Keil for development; that is unless you are just working on hobby projects.

    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.
  • pmrobert wrote: »
    David, how difficult is it to utilize the PropWare libs as part of a C program as opposed to C++? I very much like your clear, concise documentation but am not as comfortable with C++ as I am with C. Old dogs, new tricks, all that... :-)

    Mike

    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:
    namespace PropWare {
    
    class Pin {
    
      public:
        Pin (const Mask mask) : m_mask(mask) { }
      
        void set_dir_out () {
          DIRA |= this->m_mask;
        }
    
      private:
        Mask m_mask;
    }
    

    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:
    struct Pin {
      uint32_t;
    }
    
    void <crazy symbol stuff>set_dir_out (Pin *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:
    // PinC.h
    
    typedef struct PinC;
    
    PinC* create_pin(uint32_t mask);
    
    void set_dir_out(PinC *pin);
    
    // PinC.c
    
    #include <PinC.h>
    #include <PropWare/gpio/pin.h>
    
    typedef struct {
      PropWare::Pin *p;
    }
    
    PinC* create_pin(uint32_t mask) {
      PinC *pinC = malloc(sizeof(PinC));
      pinC->p = new Pin((Mask) mask);
      return pinC;
    }
    
    void set_dir_out(PinC *pin) {
      pin->p->set_dir_out();
    }
    

    Still seems like more trouble than it's worth though :/
  • David, that's exactly the motivation I need to spend the effort to become at least comfortably operative in C++. The explanation above w/ sample code and workarounds clearly demonstrates your closing statement "Still seems like more trouble than it's worth though". Well written sir!

    Thank you very much, it is truly appreciated and respected.

    -Mike R...
  • pmrobert wrote: »
    David, that's exactly the motivation I need to spend the effort to become at least comfortably operative in C++. The explanation above w/ sample code and workarounds clearly demonstrates your closing statement "Still seems like more trouble than it's worth though". Well written sir!

    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.
  • Moving to C++ won't be an issue; I'm totally comfortable with Object Pascal/Delphi, Java, etc. A day sitting by the pool working some tutorials will get the 'aha!' switch to click in my brain I'm sure. Perigalacticon, sorry for the threadjack! Back to your regularly scheduled programming... :-)

    Mike R...
  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-12-02 14:58
    If you're comfortable with Pascal, you should try Spin. It's syntactically similar to Pascal - the main syntactic difference is that Spin uses indentation instead of begin/end. It has objects, but they are instantiated at compile time. This usually isn't a problem, since you usually don't need to instantiate new driver objects at runtime, since hardware is usually fixed.
  • 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.

    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.
  • Duane Degn .Is there a way to monitor the input for a PWM signal and copy that signal to the output using(:=). freq. is around 100-1000 htz.

    bbrien.
Sign In or Register to comment.