Spin or C?
ryfoa6
Posts: 7
I'm new to Microcontrollers. I recently purchased an Arduino Mega 2560 and a Parallax P8X32A QuickStart Propeller. I read online that the Propeller can be programmed in Spin or the C programming language. Since the Arduino uses C, should I learn C instead of Spin so that I can write programs for both Microcontrollers? Can the Propeller be used with Android devices like the Arduino can? That's the reason why I bought an Arduino Microcontroller so I can make projects like starting my car with my Android phone.
Comments
Here's an Instructable I wrote a while back. It even employs the Quickstart.
http://www.instructables.com/id/How-to-use-Bluetooth-with-your-Propeller/
As for Spin or C. I've been programming in Spin for the last six years, so it's a language I'm comfortable with, however you may find it easier for jumping back and forth between products to use C.
Jeff
For me, it's been Spin. Syntax-light and super well-supported. But let me take the thread a tad sideways towards the integration of the language with our architecture. Multicore is the future - it'll allow you to compartmentalize complex programs into nice little objects that live in their own processors and objects.
You can assemble some impressive projects with the current Spin library (obex.parallax.com). And this can be done without stacking other physical hardware on the Propeller (i.e., coprocessors designed to make certain things possible). For example, shown below is a video I just uploaded to YouTube for you (welcome to the forums, BTW ryfoa6!). It might be just a little robot and not the next greatest commercial product, but it's an example of how you can integrate objects from others in a very high level in Spin. This robot is XBee-controlled from Parallax Serial Terminal (start/stop robot, choose which song to play), reads/plays a WAV file from SD card, runs three servo motors (with speed ramping) and a Ping))) sensor - all seamlessly. The top Propeller program is written in Spin and is probably no more than a hundred lines. What makes the project possible is that the hard work is done by others, in Spin. I was able to grab JonnyMac's WAV player which has simple commands like wav.start(file number) and Andy Lindsay's servo objects that manage all the pulse widths. I'm working on a complete post of the whole project.
This can also be done in C on the Propeller, but the wav file programs haven't been written in C yet. They will be, in due course. Our C resources are just now maturing through our Education department. Between Simple IDE and the GCC compiler you'll have lots of support showing up on learn.parallax.com. There's over 20 pages of C projects that we're about to publish as soon as the team gives the go-ahead. All efforts you invest in C with the Propeller will be particularly useful for Propeller 2, our next chip which also has a more suitable architecture for C (and a compiler from the same GCC code base).
Start at Learn.parallax.com (C and Spin) and look at the Propeller Education Kit examples (Spin) too. I admit I'm still a C noob, and several forum members have told me to buy the K&R book. I'm learning C now, one bit at a time.
On the other hand, SPIN is very useful and handy for small projects and has a lot of users that can support you. C on the Arduino or the Propeller is not the same as C on a desktop computer. Both have different approaches due to what the silicon provides. So you will be learning not only about C, but contrasting information about the Propeller and the AVR chips. At first, that might be a bit demanding.
But as Ken points out, multi-processors are likely the way of the future. What you learn is likely to allow you to grow into that future.
The important thing is that you start programming. Pick one of them, and if you feel yourself kind of lost, punt for a time, and go to the other one to see whether or not it doesn't get you going.
Once you are programming and starting to really grow in that area you will find learning other languages much easier. It's the first one that is really tough because all the foundation concepts are in play. Subsequent ones do have their own new foundation concepts, but there is a lot of shared ground too, which helps considerably.
If, on the off chance you struggle with both, start asking a whole lot of questions here. Again, it's important that you start programming, not so much what you are programming in. Stay fixated on that so you get yourself over the hump.
Spin is the native language of the Prop, and it contains a Spin interpreter in it's ROM. So Spin is a good choice also. The Object Exchange (OBEX) contains a lot of useful Spin code that has been posted by other Prop users. Either way, you'll get lots of support from the forum.
And Ken is right multiprocessing is the future. Just saw today that Freescale has a quad core PPC chip - really scary complex in a 1200 BGA package.
One advantage with C is that the documentation is short and has been around for a long time. Take a look at 'The C Programing Manual, 2nd Ed' by Kernighan and Ritche. It is easy to find in the public library and as a 2nd hand text.
In any event, starting with SPIN will allow you to do more while you learn. With microcontroller, there are many chips that one needs to learn to use that an Android doesn't directly use. So you are going to have a very different focus about what is useful in Android C than in the Propeller or the Arduino. Android doesn't usually support motor control or sensors and such.
If you are new to micro contollers and hardly know what a program is then I would strongly suggest starting out with Spin. It's a very simple language to kick of with so you don't have to deal with a lot of things that are not directly related to learning programming concepts and can add a layer of confusion for beginners. It also as the huge benifit of a very simple programming tool, the Prop Tool. Just type your code in there and hit run. No complicated steps to think about. On top of that the Propeller manula explains Spin very well, there are a lot of ready made code objects you can use in our programs that "just work" (See Paralallax Object Exchange, OBEX) and an ocean of help in Spin programming is available here on the forum.
Whils Spin is simple to understand and use it is surprisingly powerful and useful.
If, despite the above, you really want to start off with C then be aware that the Arduino is not using C but C++. C++ is a huge and complex language that could take years to master. But the Arduino guys have carefull documented only the "easy" and most useful parts in their manuals, tutorials and examples and they have hidden a lot of mesy detail in the Arudino IDE.
I would normally suggest that anyone wanting to learn C should start out making programs on their PC first as that is a much quicker, edit, compile, run cycle whist experimenting and you can follow along the examples in books or on line more easily. Then take what you have learned to your micro-controller.
You will need a book, this is the classic http://cm.bell-labs.com/cm/cs/cbook/
On Windows you can start programming in C with code:blocks which uses the GCC compiler as used for the Propeller.
http://www.codeblocks.org/