Shop OBEX P1 Docs P2 Docs Learn Events
Newb to spin2 — Parallax Forums

Newb to spin2

I thought I would take a break from python coding. I dug out my p2 Edge setup, I installed spintools ide, and now I am completely lost.

It seems that every programming language has a "hello,world" example code. I tried to find a spin2 version, but no luck. So, where do start my spin2 beginners' journey.

Thanks
Ray

Comments

  • JonnyMacJonnyMac Posts: 9,723

    My template program for the P2 is a "Hello, World!"

    Like the P1, the P2 needs a library to talk with a terminal. When the P2 first showed up I wrote an article for Nuts & Volts. While a lot has been added to Spin2 (which is updatable, unlike Spin1 that is etched in the P1 silicon), this article is still valid and will help you get a start.
    -- https://www.nutsvolts.com/magazine/article/an-introduction-to-the-parallax-propeller-2

    In my opinion, Spin2 is simpler and nicer than Spin1. I just spent a month updating an old P1 project that is almost 4000 lines in the main file; I constantly was wishing I had P2 syntax. That said, Spin Tools is a great choice of environment. Marco is very responsive to user inputs and serval suggestions I made while working on that big project made it into the current release, and are making my life easier.

  • RsadeikaRsadeika Posts: 3,901

    Thanks Jon, I will see how far I get with this new stuff.

    Ray

  • RsadeikaRsadeika Posts: 3,901

    First impressions:

    Spin Tools is a very complex IDE. I was expecting a simple Load , Run commands. Maybe Spin Tools should have simple, easy to use version.

    I looked at the program that Jon provided; it is complex to me. I am sure that for Jon it is a very simple example program.

    This is going to take some time to figure out what is going on. I can see why some people would give up on spin2 and go with python. I will give it a good try.

    Ray

  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-02 22:11

    Spin Tools is a very complex IDE. I was expecting a simple Load , Run commands.

    You're kidding, right?

    1 Open (Load) -- or use File / Open...
    2 Run -- or use Tools / Upload to RAM

    Maybe Spin Tools should have simple, easy to use version.

    It is easy now. And if I do say so, it takes a lot of nerve to ask for a "simpler" version of a program you haven't properly tried.

    My acting coach, the late Cliff Osmond, would say to you vis-à-vis your complaints:

    Don't suffer. Solve!
    Don't whine. Win!

    How? Instead of complaining, spend 15 or 20 minutes every day experimenting. In a week or two you'll be very comfortable with Spin Tools -- but only if you put in some effort.

    Spin Tools is created by Marco Maccaferri (a consultant / Propeller developer) for Propeller developers with a lot of input from those developers. He doesn't work for Parallax, and he doesn't charge anything for the tool. Many of us have sent him gifts through his Ko-fi account (https://ko-fi.com/maccasoft).

    If you'll take a breath and give yourself a bit of time with it, you'll appreciate everything that Marco has done. If there's anything to complain about, it's that Parallax didn't create a tool as full-featured as this for the Propeller years ago.

  • bob_g4bbybob_g4bby Posts: 571
    edited 2026-03-04 02:50

    I was in your position just after Christmas just gone, didn't know a thing about Spin2 - had done a little Assembly. Today, I'm pretty comfortable with programming in both - given that I have three essential references open on my other screen:-
    1. Spin2 Language Documentation
    2. Propeller 2 Assembly Language
    3. IRQsoft Propeller 2 Docs Just type an assembly language instruction to jump to a description, or click on the contents list.
    (1) and (2) are available as google docs, but I find them more useful as pdfs with a clickable contents strip down the left hand side (you may have to open that if it isn't showing). See the attached files. I use ctrl-f a lot.

    Why the Assembly Language documents if you want to program in Spin? Because many built-in methods are closely related to PASM instructions and the special hardware they support.

    The hardware manual will be very useful to start with.

    As for example code, the Obex is full of useful stuff. I'm currently using JonnyMac's I2C driver to talk with various external devices hooked onto the P2.

    Your enthusiasm will be boosted if you can 'make lights flash' even if you have nothing connected to the P2. Get going soon with the debug windows you can create with Spin Tools. They are all described in the Spin2 manual + look at some of the code I've been posting - they were all developed in Spin Tools as demos / test sets for the methods I am developing. It helps to see exactly what your code is doing by fitting debug statements - they are so useful, rather than guessing.

    Ask questions, but do post the code you're trying to get going. That way you'll get help pretty quickly.

    Happy "Spinning", bob

  • RsadeikaRsadeika Posts: 3,901

    I was not complaining, I forgot to add in "as compared to SimpleIDE". When spin2 became available, I was hoping that spin2 would be adapted to SimpleIDE, but that did not happen.

    Where is the spin2 commands manual, I looked around and could not find it. I found the P2 manuals, but no spin2 manual.

    I am sure that I will get the hang of using Spin Tools IDE.

    Ray

  • RsadeikaRsadeika Posts: 3,901

    I loaded Jon's example program, and I assume that if you want to run the program you use thye run command. When I do the run, I get "No configured external tools", what is that and how do I get around that.

    Ray

  • RaymanRayman Posts: 16,113

    No, that is for external tools...

    You want to use the icons below the menu, most everything is there...
    The blue play button is to upload to RAM and run.

    I usually do the bug icon which does the same, but with debug enabled...

  • RsadeikaRsadeika Posts: 3,901

    OK, so I got my first little program to compile and run. I am sort of figuring this Spin Tools IDE out.

    '' tet_led.spin2

    CON
    CLK_FREQ = 200_000_000
    MS_001 = CLK_FREQ / 1_000

    'VAR
    ' long stack1

    PUB main()
    dira[56] := 1

    repeat
        pintoggle(38)
        waitms(1000)
    
  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-03 23:29

    With your file open (File / Open... from the menu, or folder icon from the toolbar), press Shift+F10 (or Shift + blue Play button) to run a program that uses terminal output (like my template). Spin Tools has its own compiler (which is always running so you are show errors as they happen), but you may wish to use an external compiler like PNut of FlexProp -- the Run menu allows the use of external tools, but they do require setup.

    As Ray points out, there is a different toolbar icon for the P2 debug windows. For simple strings, P2 debug is easy. For more complex outputs, P2 debug commands can be tricky. You've been warned. In Spin Tools, basic debug information is output to a console pane under the bottom of the edit window. This debug output can also be logged to a file.

    I forgot to add in "as compared to SimpleIDE

    In my opinion, SimpleIDE was developed for schoolchildren; Spin Tools -- which is not difficult after a few minutes exploration -- is a tool for developers. Still, you can make Spin Tools look "easy" by hiding some features. Go into the Preferences dialog and on the General section uncheck "Show object browser" and "Show file browser," and on the Editor section uncheck "Show outline." You'll end up with a display that looks like the attached image.

    1920 x 1040 - 69K
  • RsadeikaRsadeika Posts: 3,901

    I am trying to develop a term session, and I am having problems with the code snippet. When I try to compile it, Spin tools says program error and points to the term line. Not sure what is causing the error. The file is in the same dir as the test_term file.

    Ray

    '' test_term.spin2
    ''

    CON
    CLK_FREQ = 200_000_000
    MS_001 = CLK_FREQ / 1_000

    con {terminal}
    BR_TERM = 230_400

    obj
    term : "jm_fullduplexserial" ''This where it shows the error

    PUB main()
    term.tstart(BR_TERM)

  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-03 22:42

    You probably don't have jm_fullduplexserial.spin2 in the P2 library. I don't use them, but Spin Tools defaults to libraries in its install location:

    Move jm_fullduplexserial.spin2 and jm_nstr.spin2 to the P2 library folder and try again. You should see a blue icon next to the name in the Object Browser (if you have it open -- and this is a good reason on why).

    The blue document icon tells you that the file is in a library folder; a yellow document icon tells you the file is in the project folder (these rules follow Propeller Tool).

    If you want to customize your library location (I use the consolidated Propeller Tool library) you need to point to that folder in the Spin1 and Spin2 sections of the the Preferences dialog.

  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-04 03:25

    I am trying to develop a term session, and I am having problems with the code snippet.

    Before you get going you have to tell the P2 how fast to run. CLK_FREQ is a [user defined] constant. _clkfreq is the directive that actually sets the P2 speed. In my template I create CLK_FREQ so that I don't have to read the system variable clkfreq, and so I can derive MS_001 and US_001 constants for waitct() used in synchronized delays.

    This is why I gave you a template to start with.

  • RossHRossH Posts: 5,716

    Hello @JohnnyMac

    This is why I gave you a template to start with.

    Please don't take this post the wrong way - it is intended as constructive criticism. I understand your template is designed to be of much more general use than just as a simple "Hello, World" program, but it is not really appropriate for this use.

    Offering a novice 1165 lines of "template" in multiple files (for a total size of 37k) just to achieve "Hello, World" is not really a good way to introduce someone to either Spin2 or the Propeller. It is far more likely to make them look elsewhere.

    You do not, for example, need to include any of the C standard library files if someone asks for a C "Hello, World!" program. You simply offer them (for any configuration of any platform that supports C):

    #include <stdio.h>
    void main() {
       printf("Hello, World!\n");
    }
    

    In many modern languages a fully functional "Hello, World" program is a single line of code no more complicated than:

    print "Hello, World!"
    

    (that is actually the complete program in Lua. Python, Go and many other modern languages are not far behind)

    In your template, the bit the novice is actually most interested in - i.e:

    pub main()
    
      setup()
    ' wait_for_terminal(true, 250)                                  ' needed for PST
    
      term.fstr0(@"Hello, World!\r")
    
      repeat
      ' forever
    

    is itself buried in the middle of a file containing over 100 lines of quite arcane code.

    I must admit I have never really studied Spin2 (it is so long since I used Spin at all that I barely even remember Spin1) but surely it is possible for the main() function to appear in a file by itself, clearly named something simple like hello_world.spin2. For example, it could contain just something like:

    obj
      p2 : "p2_default" ' select the platform
      io : "p2_serial" ' select the I/O library
    
    pub main() ' main function
      p2.initialize()
      io.str("Hello, World!")
      io.wait()
    

    Objects such as p2_default or p2_serial should not need to be included. They should exist in any Spin2 installation, with new ones easily created or added for new configurations. But even that aspect is already going way beyond the scope of a simple "Hello, World!" demo, which is intended to demonstrate how to get something executing with a minimum of fuss.

    If this is not currently possible in Spin2, then Spin2 should be modified so that it is possible. I suspect it may already be possible, it just does not seem to be the way that Spin2 or Propeller developers think - because very few of them are novices. And unless this changes, there never will be many novices.

    Ross.

  • maccamacca Posts: 1,010

    @Rsadeika said:
    I am trying to develop a term session, and I am having problems with the code snippet. When I try to compile it, Spin tools says program error and points to the term line. Not sure what is causing the error. The file is in the same dir as the test_term file.

    Other have already written everything about Spin Tools IDE, I would just add that the IDE is more like Propeller Tools rather than SimpleIDE (which was dedicated to the C language) some concepts are taken from it, and includes a set of ready to use examples for both P1 and P2, select File -> Open From the top entries should point to /examples/P1 and /examples/P2 select one and open one of the spin files you find there. Several are dedicated to specific hardware but some could be run without problems, like jm_i2c_devices or jm_i2c_format_strings_demo, both are using jm_fullduplexserial. The default library path, if you haven't changed anything, is set to the included libraries, generally you don't need to do anything to run the examples.

    I don't know why your code has errors, I don't see any error here, however there is a message displayed if you hover the mouse over the error indicator, if it say "object jm_fullduplexserial has errors" open the file to see what errors are there (right-click on the object file name to open it).

    To upload and run the programs to the Propeller, use the Tools menu and one of the "Upload to..." entries, generally you just need the "Upload to RAM with Terminal" to upload, open the terminal and run automatically (or shift + F10 or again shift + blue arrow on the toolbar).

  • RossHRossH Posts: 5,716
    edited 2026-03-05 11:27

    Other have already written everything about Spin Tools IDE, I would just add that the IDE is more like Propeller Tools rather than SimpleIDE (which was dedicated to the C language)

    The IDE used should have no effect on the language. If it does, the problem is with the language, not the IDE.

  • RsadeikaRsadeika Posts: 3,901

    macca discovered the problem, it took me a while to figure out that if you hover the cursor over the problem line, the error is displayed. What I did was go to the obex and find the latest files and now my little code snippet compiles correctly. I try to avoid making comments.

    Ray

  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-05 15:20

    What I did was go to the obex and find the latest files and now my little code snippet compiles correctly.

    That's good news. Now you can have some fun with the P2. BTW, the archive that I sent you in post #2 of this thread has the absolute latest versions of those libraries. Please copy them to your preferred library location. In my case, I still use Propeller Tool a bit (for its block select and paste feature), so I use the Propeller Tool library folder for Spin Tools, and for FlexProp, too.

    Keep in mind that the P2 has many more features than the P1, so go slowly. If you haven't yet, please read that article I pointed; it will help. Finally, I've done lots of presentations for Parallax on the P2. You can find them on the Parallax YouTube channel. Not everything will be current (because Spin2 can be updated), but I think you'll find most of those presentations useful.

  • RsadeikaRsadeika Posts: 3,901
    edited 2026-03-06 19:38

    Below is my rendition of a code simplified "Hello ..." program. I wonder how much of that could be put "under the hood". For this to work you have to have the terminal open. Speaking of "terminal open", is their some code that would open the terminal and print "Hello ...".

    In some ways spin2 is kind of like python with its indentation and dev usage. I still do not care for the indentation stuff.

    All of my code snippets will be open source; I am not looking for any credit.

    Ray

    '' tet_led.spin2
    
    CON
        CLK_FREQ = 200_000_000
        MS_001 = CLK_FREQ / 1_000
        US_001 = CLK_FREQ / 1_000_000
        _clkfreq = CLK_FREQ
    
    con {terminal}
        BR_TERM = 115_200
    
    
    obj
        term : "jm_fullduplexserial"
    
    
    PUB main()
       setup()
       term.tx(term.CLS)
    
       term.fstr0(string("Hello,Ray\r"))
       '' debug("Hello, Ray")
    
        repeat 10
            pintoggle(38)
            waitms(1000)
        '' debug("Goodbye, Ray")
    
    pub setup()
        term.tstart(BR_TERM)
    
  • JonnyMacJonnyMac Posts: 9,723
    edited 2026-03-06 19:00

    It's easier for people to see your code when you use the formatting markers. I do it manually by putting three back-ticks (unshifted ~ key on American keyboards), but you can also paste you code into the post, drag-select all of it, and then click the formatting option from the forum post menu:

    This will preserve indenting which is very important in Spin and Spin2. With proper use of the code format markers your listing should look more like this:

    '' tet_led.spin2
    
    CON
    
      CLK_FREQ = 200_000_000
      MS_001 = CLK_FREQ / 1_000
      US_001 = CLK_FREQ / 1_000_000
    
      _clkfreq = CLK_FREQ
    
    
    con {terminal}
    
      BR_TERM = 115_200
    
    
    obj
    
      term : "jm_fullduplexserial"
    
    
    pub main()
    
      setup()
      term.tx(term.CLS)
    
      term.fstr0(string("Hello,Ray\r"))
    ''debug("Hello, Ray")
    
      repeat 10
        pintoggle(38)
        waitms(1000)
    
    ''debug("Goodbye, Ray")
    
    
    pub setup()
    
      term.tstart(BR_TERM)
    

    Admission: I use my formatting style of two blank lines before a new section and one line after the section header. To me, this makes things easier to read. Whitespace is cheap.

    If you're using Spin Tools, clicking on the blue (Run in RAM) arrow with [Shift] pressed will (re)open the terminal window. You can also use the hotkey [Shift]+[F10].

    All of my code snippets will be open source; I am not looking for any credit.

    Trust me, if you share enough code, somebody will botch it up in the name of "fixing" it and not give themselves credit for the mess! 🤣

  • AribaAriba Posts: 2,696

    @RossH said:
    ...

    #include <stdio.h>
    void main() {
       printf("Hello, World!\n");
    }
    

    ...

    If this is not currently possible in Spin2, then Spin2 should be modified so that it is possible. I suspect it may already be possible, it just does not seem to be the way that Spin2 or Propeller developers think - because very few of them are novices. And unless this changes, there never will be many novices.

    Something like that is possible in Spin2.
    Open the SpinTools, click on 'New' in the File menu, and type in this code:

    con
      _clkfreq = 200_000_000
    
    PUB main()
      debug("Hello World")
    

    Then press Ctrl-D to enable debug output, and press F10 to Load and Run.

    Andy

  • RaymanRayman Posts: 16,113
    edited 2026-03-09 14:01

    #includefor Spin2 would be nice...

    Chip was talked into #define, we should add that to his user wish list...

Sign In or Register to comment.