Shop Learn
SPIN talking points — Parallax Forums

SPIN talking points

This is NOT intended to be a “blood-in-the-water” thread starter. Far from it. But today I was hit with a question from an educator that I bungled rather badly. Here it is: “Why would we teach SPIN? What does it do better than any of the other languages?”. And I had nothing to say, because I’m just not a SPIN programmer. So I confessed my ignorance promptly, and said I’d put out a call to some forumistas who use it and absolutely love it.

Help me here, lads. I need some talking points.

Btw: The context related to teaching robotics on the P2.


  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2021-03-02 00:46

    If you want to use a "language", then use the one that is best for you. If you want to use the Propeller, then use the language that is best for you and the Propeller.

    Educators teach languages, although in general, just one language with the assumption that it will be something like a PC that you will be using it with. What we are doing is more Electronics Engineering than Computer Science or IT etc. Embedded systems normally have to run 24/7 without rebooting. Think of traffic lights, think of pacemakers, think of aircraft, and even cars because if the MCU (yes, microcontroller) hiccups even once during high revs it can cause a lot of damage. The list goes on and on while PCs have thousands of times the resources but nowhere near the realtime control and reliability of their humble MCU cousins.

    EDIT: Just saw your btw - yes robotics - we choose an MCU to control that robot not based just on what we prefer but on what gets the job done. The same likewise with the language. If you program in Python on the PC, can you program in Python on the MCU and get the job done and have it run fast enough and reliably?

    “French is the language of love, Italian is the language of music, German is the language of war, English is the language of business, Spanish is the language of prayer etc"

  • Spin is weird.

    What I really like about it and what really drives up the educational aspect is that it is easy to see all the involved code. There are no hidden libraries, just the code you put in.
    Also being able to just do assembler-style data definitions in DAT sections is great.
    On the other hand, most languages have a few warts, yet Spin is a wart that somehow is executable. Any code that'd use a struct in C turns into absolute brap when you write it in Spin. The end in a repeat loop always being inclusive is pretty annoying. Somehow Spin1 and Spin2's operator sets are both obnoxious in their own way. Half the features you want are only in flexspin (preprocessor, access to nested objects, object pointers...) .

    I don't think Spin is really a good language for teaching programming in general, but it is an excellent language to teach low-level microcontroller things to someone who already knows the basics programming.

    As for actual applications, it has some where it shines and some where it just falls apart. See the thing about structs above

  • Cluso99Cluso99 Posts: 18,017
    edited 2021-03-02 02:05

    Here's my modern take on it.

    • A simple high level language to program multicore microcontrollers (micro), namely the Parallax P1 and P2 8-core micros
    • Designed for programming micros, not microcomputers or PC's
    • A modern indented language very much like python
    • Simple and easy to learn
    • Users can get running with just a line or two of code
    • Does not require massive library support like C
    • Has methods to directly control the I/O pins and peripherals on the micro
    • Has methods to directly launch and interact with other cores on the micro
    • Can run interpreted or compiled
    • Can use assembler objects that implement specific functions that make the hardware more versatile and may interface to other hardware to simplify access
    • Supports easy debugging (Chip needs to add to this)
    • Makes it easy to write and mix assembler if desired
    • Teaches the fundamentals of programming micros
  • Dave HeinDave Hein Posts: 6,347
    edited 2021-03-02 03:58

    @JRoark , it is useful to program in Spin on the P1. The chip boots up running the Spin interpreter, so it is essential to know some Spin just to get going on the P1. The Spin language for the P1 is a very compact language that one can learn in a few hours or days. Spin on the P1 can be mastered within a month. Compiled Spin bytecodes produces compact code which works well with the limited amount of RAM available on the P1.

    On the P2, there are fewer reasons to use Spin versus other languages that are available. The Spin2 language that was developed for the P2 has introduced some of the operators and features that are in C and C++. In my view, Spin2 implements a subset of C++. This makes it a more powerful language than Spin1. Since the P2 has 500K of RAM, there is less need for a compact interpreted version of Spin2. Given all of this, I would say it would be better to teach a beginner one of the standard languages instead of Spin2. Eric's FlexProp supports C with a subset of C++. It integrates PASM code almost as well as Spin2 does. So I would recommend FlexProp with C as a teaching tool for the P2.

    And finally, if neither a P1 or a P2 is being used, then there is little reason to consider Spin. It is possible to run Spin on other platforms by using FlexProp to convert it to C/C++, but I don't see much motivation for running Spin on other platforms.

  • Mike GreenMike Green Posts: 23,047
    edited 2021-03-03 03:08

    Spin was developed as a "high-level programming language" for the P1. It compiles into a very compact bytecode form that is normally interpreted (very efficiently) by an interpreter built into the P1's ROM. It "follows in the footsteps" of PL360. Where Spin is partially derived from Python, PL360 was derived from Algol and provided a very efficient, yet easy to understand and use "high-level programming language" for the instruction set of the IBM 360 series of computers. Note: The compiler and an operating system for the IBM 360 were both written in PL360.

    As Dave Hein mentioned, Spin is less useful on the P2 where a variety of programming languages are available in addition to an extended Spin (Spin2) and the P2's resources (memory and speed) are so much greater.

  • lardomlardom Posts: 1,659

    I like Spin because the Propeller makes my projects less expensive. In many cases I can write my own device drivers for multiple devices. Also, don't overlook the benefit of a very active, helpful forum. This forum made the difference for me because in the beginning I got stuck a lot!

  • Many thanks to each of you for giving me this feedback! I knew I could get what I needed here. Discussion (with all of these talking points duly printed) will be had tomorrow.

  • bob_g4bbybob_g4bby Posts: 257
    edited 2021-04-30 13:54

    A concise reason might be:-
    Spin is a simple language, well suited for use in schools and colleges, with which to introduce the principles of modern computer programming with minimal syntactical clutter. Those same principles can be applied to any of the very similar computer languages a pupil will encounter during their career, most of which haven't been 'invented' yet.

    Let's face it, the programming scene is just like the fashion clothes trade, constantly reinventing itself. We still put trousers on one leg at a time, though, whatever the current shape. There will always be something like FOR .. NEXT and IF .. THEN .. ELSE in there somewhere.

  • I'm not too crazy about the language itself, but what I DO like is taking the through hole version of the propeller chip, soldering them to bread boards and getting a very powerful processor up and running. That part is ridiculously simple, and it's cheaper if you make them yourself. I've spent far more more buying things to attach to my home made boards than I ever spent making the boards themselves. Not counting shipping charges, A home made board can be had for less than 20 dollars. That helps, the way I tend to do things with Propellers that I probably shouldn't. For example, on of my current projects involves using a propeller that on power up, activated by a door switch, keys a transmitter, then shuts down and does nothing. The design is easier because timing is not an issue and you don't need a crystal. I almost feel bad using a little computer, more powerful than the one to put a man on the moon, for such a simple task, but it's an excuse to build a board.

  • PublisonPublison Posts: 12,206

    Welcome to the forums! Look forward to see your projects.

  • msrobotsmsrobots Posts: 3,486

    @Dan_Joyce , welcome to the forum, be careful it is quite addictive...



  • SuracSurac Posts: 174
    edited 2021-05-01 07:49

    Spin is quite dangerous too. You get first results quite fast.
    But if you like to write some complicated codes or drivers spin is not helpful.
    There is no way of writing something like a struct or type. Most of the time you
    must juggle around variable contends. It introduces some concepts to hide
    the lack of multicore primitives like queues and signals. It is a mix of different
    programming languages. I for myself have invested about a week and came to the
    conclusion that i will not invest more time in Spin.
    If you have a look around here in the forum most drivers are PASM and a little
    stub of Spin. Also Spin consumes Precius LUT and COG ram.

    So, the choice is yours, but nevertheless you must learn PASM to understand device drivers.
    P2 has no hardwired IO, which makes ist very flexible but also very hand to start with.
    P2 also uses "fantasy" namens for most of its parts (COG, HUB, SMARTPIN, EGGBEATER) and so on.
    Spin is also some of this "fantasy" aproach

  • bob_g4bbybob_g4bby Posts: 257
    edited 2021-05-01 16:56

    The original question about Spin came from an educator : Why should I teach Spin? Well, to get a whole class-full of youngsters to take any interest in programming at all requires a lot of 'sugar'. Spin is no better nor worse than many of the simpler languages. However, the hardware, software and teachers notes that come bundled with Spin promise flashing lights, bloopy noises and moving parts to really tickle kids' inventive spark. In contrast, teaching with a P.C. and a Python installation is a non-starter, deadly dull.
    What Parallax does is the equivalent of my dad coming home from work with a bag full of switches, lamps and batteries when I was about nine. It was fun to muck about with. It started my whole career as it turned out.

  • yetiyeti Posts: 792

    @bob_g4bby said:
    The original question about Spin came from an educator : Why should I teach Spin?

    Why should I not teach Spin?
    Even after a decade with occasionally (some times even much more) using Spin I've problems with it. Probably you have to use it near to daily to not need a cheat sheet like "Propeller Chip Quick Reference".

    It is a nice chip, but Spin is too weird and the whole Propeller eco system is far too expensive. With MicroPython on 1€..5€ modules, you are far more mainstream and the probability that the taught knowledge is easily apply-able to every day technology (Python on PC, Python on IoToys) is much bigger.

    I like the P1, but I don't think it is the right choice for the 1st contact to MCUs and coding.

  • If I was teaching a course such as the mechatronics seen Wednesday I would teach spin if the chosen mcu was a P1 or P2. Made for the prop, dead simple to learn. Also PASM. Why put having to learn a generic general purpose language in the way of learning the concepts for which you paid for the course, a point made the other day as well.

    Since the first pre-cube dweller wrote the first program in xxxxx, that and every programmer since has said "Why the 7734 did the creator of that language do that, that's not how I would do that". Rather than say that, it appears to me that Chip just decided to just do it his own way and created spin in answer to his own "Why....".

    So now we see spin and say "Why the 7734 did Chip do that?" Personally, I like spin and the ease of dropping PASM in where I need it. Pointless to argue like a bunch of cannon lawyers, use what gets your job done right!

  • yetiyeti Posts: 792
    edited 2021-05-22 06:41

    I'd prefer some of the line noise Chip used as operators being good old readable function calls instead. Then I would be able to use Spin after a break without digging out the "Quick Reference" first. Sure that's not a problem if you spin every day, but some of us have a life with other languages and CPUs too.

    So I'd prefer to trade needing some more keypresses for more readability and easier memorisation.

    Especially I don't think teaching such a deviating syntax really is helpful for beginners, it only will increase frustration with other languages.

  • bob_g4bbybob_g4bby Posts: 257
    edited 2021-05-22 19:25

    If teaching on Propeller doesn't suit, what other platforms would provide that 'fun' factor to engage kids in what can be a very dry topic? Like many of us, I've bought several ESP8266 and ESP32 modules to find out about 'internet of things'. There are many ways of programming these wifi based controllers: The most polished system to my eyes appeared to be the Annex Basic.
    1. Basic language is as basic as it gets, very simple syntax, which really matters for first contact, not to mention the teacher who may have had little prior programming experience.
    2. The website has excellent documentation
    3. Programming is via web pages on the pupils' phone or other wifi connected device, so that makes a change from being told 'put your phone away'.
    4. The modules are 0.1' pitch so breadboard mountable
    5. Controlling 'stuff' happens very quickly, so lots of +ve feedback
    6. The modules are cheap as chips as are other 0.1" pitch compatible breakout boards on ebay, many with drivers already built into the language.
    Like Peter Jakacki said, it's making stuff happen with engineering, not just programming. All sorts of subjects can be woven in to the theme.

  • bob_g4bbybob_g4bby Posts: 257
    edited 2021-05-22 19:35

    Is it fair to say that the higher in education you go, then perhaps the more industry focussed a course that includes computer programming becomes? People enrolling for a degree course tend to pick their college, based on the industries it specialises in, to best match their initial career.

  • yetiyeti Posts: 792

    Using FlexBASIC or FlexCC on the Propeller (P1 or P2) would fit teaching much better, but then you'd need a Propeller2 for each pupil as the LMM code is much bigger than classic Spin on it. On Propeller1, you soon hit memory problems if some pupils really get infected by the coding virus and want to explore some more complex (in code size) things.

    If every pupil can get a P2 board, ok.

    The Propellers are nice chips, but I just have a problem with Spin in the 1st contact context.

  • SuracSurac Posts: 174
    edited 2021-05-23 10:07

    I would love to use the P2 in commercial products. I have already suggested it to 4 of my customers, but the technicians there think different.
    3 of 4 are very interested in the P2 architecture but shy the undeveloped documentation and are insure about the way to program and debug the chip.
    For one company it is too expensive.

    Spin was not even considered by 4 of 4 because of different reasons.
    For 2 of them only C is a Option, but commercial tool support is zero
    One says the the syntax is „funny“
    And one asked for a „standard“ library

    I really like the P2 hardware, but without a change Tools and documents it will not pay my bill

    Ps. Sure I can start making this changes, but I think parallax is the company that needs to tell us there plans for the P2

Sign In or Register to comment.