Shop OBEX P1 Docs P2 Docs Learn Events
Spin or C? — Parallax Forums

Spin or C?

ryfoa6ryfoa6 Posts: 7
edited 2012-09-23 01:20 in General Discussion
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

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2012-09-21 18:59
    With an inexpensive bluetooth module it can certainly be used with an Android phone.

    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
  • ryfoa6ryfoa6 Posts: 7
    edited 2012-09-21 19:54
    Can anyone tell me which programming language is easier to learn, spin or c?
  • Ken GraceyKen Gracey Posts: 7,400
    edited 2012-09-21 20:36
    ryfoa6 wrote: »
    Can anyone tell me which programming language is easier to learn, spin or c?

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-09-22 11:45
    Learn both. Now that the Propeller has C and because people want to learn C, it would be silly to say 'no' to it.

    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.
  • potatoheadpotatohead Posts: 10,261
    edited 2012-09-22 12:19
    IMHO, Spin is leaner at first. This can make it easier to learn.

    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.
  • ryfoa6ryfoa6 Posts: 7
    edited 2012-09-22 12:43
    How different is C on the Android then C on the propeller? If I learn C, should I learn C or C++? I was thinking about buying C for dummies. Would that be a good way to start learning C for the Propeller? Or should I find a guide online thats geared towards C on the propeller? Thanks for the help.
  • localrogerlocalroger Posts: 3,452
    edited 2012-09-22 12:53
    Start with Spin. Spin was designed as a teaching language, and once you get comfortable with it you'll find transitioning to C pretty easy. As Ken mentions C requires external memory hardware to work at all and is apt to encounter weird bottlenecks and limitations. Spin has its limits, some of which I don't like, but it is the native language of the Propeller, it's very useful, and it will work on all Propeller hardware no matter what peripheral mix is present.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-22 14:01
    I would suggest learning both Spin and C, but I don't think it matters much which one you start with. You can learn C by downloading a C compiler to your computer and following one of the many tutorials on the internet. Or you could download the SimpleIDE (Simple Integrated Development Environment) and run your programs on the Propeller. The C compiler for the Propeller allows you to run programs from external memory or the Prop's internal memory. The Compact Memory Model (CMM) produces programs that are about the same size as Spin programs.

    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.
  • rod1963rod1963 Posts: 752
    edited 2012-09-22 21:27
    Spin, because that's where the mindshare and code is. You'll get up to speed faster and easier. Let C mature on the Prop, when it goes Gold and you're comfortable with Spin take a look at it. But don't try to learn two languages at once, it will just confuse you. Pick one and master it, that makes learning others easier.

    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-09-23 00:27
    We recently had a long thread about the comparison of C to C++ and the learning curve. C and in particular ANSI C is much simpler to master than C++. Eventually as you see the need, you can move on to further generations of C, but take it easy at first.

    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.
  • Heater.Heater. Posts: 21,230
    edited 2012-09-23 01:20
    ryfoa6,

    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/
Sign In or Register to comment.