SPIN
ASKME
Posts: 172
in Propeller 1
With very little experience programming (30+ years ago) I'm attempting to learn SPIN.
Comments
There is a bunch of people here happy to help. I'm not the sharpest tool in the shed when it comes to SPIN, but sometimes I can actually help.
https://www.parallax.com/product/32305
I'm sure Ken would let you check one out of stock.
EDIT: I see that is the same that Tom suggested.
It has been a wonderful road in my quest to learn spin. I dabbled in other languages, but spin just seemed to click and be fun at the same time. Hope .spin will not be forgotten.
BTW: I still consider myself a dabbler in spin, and am vary content with that. But I do take life at a slower pace, and don't try to push anything to extremes.
Put the books aside... books are a waste of valuable time. Pick a project... any project. The only project "requirement" is that it has to be really important to you... compelling. Something you can't stop thinking about. Then announce your project... so that you can't back out.
After that, you are done. Spin will come to you like water flowing off a putting green.
Everything you need is already in the OBEX or hidden cleverly in the forum. If you can't find it, someone will point to it.
Rich
On of the best ways to learn Spin though it to look at other people's code such as the demo programs that are included with the Propeller Tool and the assorted programs found in Obex.
I am guessing you come from the BASIC era and Spin is very BASIC-like though it has some PASCAL and other language elements.
I started with the BS2 which uses PBASIC and found Spin was about 75% similar though some of the commands were different.
I personally find Spin easier to work with and understand than C.
Just be warned though, that Andy's text (PEK) doesn't take much advantage of CONstants which makes programs so much easier to reuse and modify.
Even after looking in the Propeller Manual it took looking at example code before I understood how to use CONstants.
I also personally prefer to declare global VARiables than create them within Methods.
By the way, a Method is what is called a Function, Procedure, or Subroutine in other languages, and an Object is otherwise known as a library.
Also be aware that there are PRIvate and PUBlic Methods. A PRIvate Method works only within an Object while a PUBlic Method can be used by another Method.
There are no global variables in SPIN. A VARiable in Spin is only visible from the object it is defined in. A Spin object is a single file that contains all the objects VAR, CON, PUB, PRI, DAT sections.
The choice of keeping data in an objects instance variables or restricted to the local variables of a method is better not a matter of preference but of functionality. This is also wrong. Or at least not common definitions of the terminology.
A "function" takes parameters and returns a result based on those parameters. It does not depend on anything else but those parameters. No object or global variables. It does not have any "side effects", like changing object or global variables. It is stand alone, not part of any object. See "Functional programming" https://en.wikipedia.org/wiki/Functional_programming
A "procedure" is any bunch of code wrapped up with a name that can be called from many places. It may well use data that is not passed in it's parameters. It is not part of an object.
"subroutine" - see procedure.
A "method" is code that is part of an object. It may well have parameters but the point is it can act on data belonging to a particular instance of that object. Methods in different objects act on different object instance variables. No. A library may well contain a bunch of functions, procedures and objects (classes in the C++ and other worlds). I suspect that there are many libraries one can pull from OBEX tha contain mutiple objects.
I think a lot of people got their start on the Propeller with this document, a good Spin tutorial and reference. Even if you never programmed anything before.
https://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf
http://www.pages.drexel.edu/~hgk22/courses/MEM380_800/WebPM-v1.01.pdf
Are you dissecting working code, changing variable and constant values to see what happens? Play with working code and trying to understand how it works, helps me a lot.
Yeah same with me, every so often have to apply what you've learned from a book, or you just don't retain it, read to be reading.
Erlend
learn.parallax.com/tutorials/projects?tid=16
Click on the drop down and select Propeller- spin language.
I start by checking the data sheets for the components (start with a simple project that does not have complex devices - that's why LEDs are usually the first thing used).
Then write out an outline of what you want it to do and in the sequence and logic it needs. (a sort of pseudo code - e.g "if this, then do that, other wise do something else).
Once you have that use the reference manuals to choose the language elements that do what your pseudo code lays out.
Spin has some shortcut features that make it efficient, but can be confusing to a new user, so keep it simple.
If you feel that you are too novice to try writing your own software then go through the tutorials as written and Andy's propeller education kit book, since he explains each aspect of the programs clearly. Then after you have followed his example in the book make you own modifications to it and see how it works. (change pins, change timing, etc.) Don't just skim read his programs, make sure that you understand what each is doing and how it does it. If there is a line that is not clear ask a question.
If you are more into electronics experimentation using software as a tool, Jon Titus wrote "Experiments for the Propeller Quickstart" available as a free pdf here: learn.parallax.com/tutorials/language/spin/experiments-propeller-quickstart
Using a programming language to do real control and measurement can help make it easier to understand how the language works.
Tom
My approach to learning a new programming language for a long time now is:
1) Find the minimum program that runs and does something.
In many languages on PC's and such that is traditionally something that print's "Hello world!". For languages targeting micro-controllers it can be something that flashes an LED. The "blinky" program.
2) With that in place you know your tools work. The compiler and loader.
So now you can play with it. Try to understand some new language feature, from the book or tutorial. Modify your working "blinky" program to do that. If it breaks never mind. Go back and try again.
In fact, breaking a program in various ways deliberately is a good move. Then you get used to what the error messages the compiler spits out mean.
Slowly, slowly you get the hang of what you can do with the language.
Then it's time to start to think about what tasks you actually want to do....
So yes "it's like learning to speak a New Language." Because it is learning a new language. Slowly, slowly, trial and error.
spin-code-examples-for-the-beginner-public-version