Shop OBEX P1 Docs P2 Docs Learn Events
Best alternative for learning C . — Parallax Forums

Best alternative for learning C .

markustermarkuster Posts: 184
edited 2013-03-10 10:02 in General Discussion
Hi,

I have the BoeBot and I would like to learn C language

Do you know if changing the Basic Stamp by the Propeller and using the Catalina C
is enough to start moving motors, using sensors, etc. . Is this hardware enough to
start learning C. ?

I like a lot the Stamps in Class program and I am looking for the same but C.

It seems that Parallax doesn't have some PDFs like Stamp in Class to learn
C with the BoeBot . Do you know something about ? , Some PDFs about how
can I add the servos , or a sensor will be very good.

Thanks,

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2013-03-05 12:11
    Maybe this will be a start.

    http://learn.parallax.com/PropellerBoeBot

    But it's not C though, so maybe not much help.
  • SRLMSRLM Posts: 5,045
    edited 2013-03-05 12:51
    You're correct: currently, there isn't much in the way of teaching C with the Propeller in mind. I'm sure that PropGCC doesn't have anything*, and I'm pretty sure that Catalina doesn't as well.

    *Parallax is apparently working on some PropGCC based material. It hasn't been released yet, however.

    Your best bet for learning C would be to start on the desktop with GCC, and learn the basic elements. From there, it's more or less the same for the Propeller.
  • markustermarkuster Posts: 184
    edited 2013-03-05 13:51
    Thanks,

    But do you know if Spin is similar to C language.
    Or , people that understand Spin could understand C faster ?


    Thanks.
  • Heater.Heater. Posts: 21,230
    edited 2013-03-05 13:59
    This best way to learn C is via the classic book "The C Programming Language" by Brian Kernighan and Dennis Ritchie. The guys who invented it.
    Having said that, it does not help with the peculiarites of any specific system, like the Prop for example.
    Be sure, Parallax is working very hard on providing such documentation and tutorials for the use of C on the Prop. I'm sure it will be very good but it is early days yet as it is only recently that Paralax has supported C on the Prop.
  • Heater.Heater. Posts: 21,230
    edited 2013-03-05 14:03
    markuster,
    But do you know if Spin is similar to C language.
    Very similar.
    Spin and C are in the same family of block structured languages as Pascal, ALGOL, and many others, once you know one you know them all, give or take some syntactic details.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-05 21:59
    C has loads of tutorial material on the internet for free, but that can be a hazard as it may be C++ or some other ... more complex version.

    Try looking for the original ANSI C written by the founding author, Richie and Kernighan. Though it is not everything you need to know, it is one of the best introductory presentations.

    It is written with Standard I/O in mind. With the Propeller, the i/o pins are NOT the 'Standard i/o' and that is mostly where you will have to adapt C to use on the Propeller. This should not be a big issue. Once you learn to loop and branch and get the timing you want, it all gets very easy.

    I would stick with ANSI C, and avoid C++ at first. The Propeller PropGCC can do both, but C++ requires you to learn a lot more. Learn to walk, before trying to run.

    http://zanasi.chem.unisa.it/download/C.pdf
  • jazzedjazzed Posts: 11,803
    edited 2013-03-06 22:28
    It is written with Standard I/O in mind. With the Propeller, the i/o pins are NOT the 'Standard i/o' and that is mostly where you will have to adapt C to use on the Propeller. This should not be a big issue.

    Yes, it's a semantics problem. Standard IO in C usually refers to standard input/output interfaces such as a serial port or a disk. The IO in a MCU (microcontroller) has some "generic" features associated with pin input/output. GPIO is a common acronym for that (General Purpose Input Output).

    You can learn C on an MCU (microcontroller), but learning it on a PC will be a more rewarding experience because you generally won't use up all of a PC memory - there are exceptions LOL. MCUs tend to have limits that a PC will not have. On the other hand, a PC can't do some specialized things that some MCUs can do.

    Spin has many more operators than C. Also ">=" does not mean the same thing in both languages .... Then there is this thing "->" ....
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-07 01:08
    I believe it was Leonardo Da Vinci asserted that small spaces discipline the mind. C on a microcontroller is such a small space. It is a useful learning experience as it does require a certain amount of discipline that unlimited space would not.

    Large spaces do have their positive attributes as the imagination soars.

    Use both wisely.
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-03-07 08:25
    spin LOOKS a bit like c from the outside, be this is where the similarity ends.

    in use, they are completely different, and the superficial similarities tend to cause confusion.

    c on a PC is very different from c on microcontroller for the reasons described.

    if you want to learn c, best start on a PC and work on that. if you want to use the prop, best start with spin. c on the prop will be a bit further down the road, as you have to go through two learning curves to get there.
  • RickBRickB Posts: 395
    edited 2013-03-07 08:47
    Learn C on a pc first. Here is an excellent, well supported free version.
    http://www.pellesc.de/
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-07 22:07
    ANSI C is available is the fully standard for free on the Apple, Linux, or Windows OSes. Pelles C looks interesting, but not sure it is ANSI C compliant.

    Just look at and search for GCC (which includes ANSI C and optional C++). It really is not so much that the programing language might vary. The guts and glory of C is in the Libraries that handle specific aspects of computing. If the Libraries are non-standard, you have to re-write the code to move over to something else.

    Most of the annoying study is caused when using Microsoft and the Windows environment. Why so?

    GCC was created for Unix/Linux and the Apple OS is a variant, but all three do use the Unix type file system. Microsoft started out by ignoring Unix and had a simpler file system based on CP/M. It has become more Unix-like, but due to competative antagonisms -- it will never be 100% compatible with Unix.

    And Unix was orignially married to C. So if you want C in Windows, and then later want the 'real C'; you are going to have learn the MS way and the Unix way.

    MS feels that it just has to always make its users feel dependent and afraid to stray into free-ware provided by Linux. Alternatively, you can use Ubuntu Linux or even Puppy Linux on a LiveCD to program and compile in true Unix based C on a computer that has only Windows installed. These LiveCDs can be used in a way that never affects your installed OS or hard disk.

    But since PropGCC uses FAT32 files systems, and not Unix/Linux file systems, there may be nothing really gained by learning C in Unix/Linux OS.

    Just don't feel daunted by the idea that the first C you learn on may require later study to be used on whatever is your target device. This is a common situation.


    http://personal.ee.surrey.ac.uk/Personal/R.Bowden/C/dos-gcc/index.htm
  • harpreetsinghharpreetsingh Posts: 4
    edited 2013-03-07 23:51
    Spin and C both Almost same algorithm and structure, and both are very easy to use. you can easily handle if you can interestingly do that......
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-08 01:32
    There are significant advantages to C on the Propeller.

    1. It allows larger memory models and it can use memory differently, more fully than Spin.
    2. It may run a bit faster than Spin code.
    3. The C libraries that do work with the Propeller allow you to acquire knowledge that can be applied to any other device that compiles C.
  • Heater.Heater. Posts: 21,230
    edited 2013-03-08 03:03
    Braino,
    spin LOOKS a bit like c from the outside, be this is where the similarity ends. in use, they are completely different, and the superficial similarities tend to cause confusion.
    We really do see programming languages differently.

    I would put it totally the other way around. Spin is nothing like C to look at. White space block delimiters in stead of curly brackets. The lack of extraneous round brackets, the way local variables are declared, the object "dot" notation, etc etc.

    However conceptually they are very similar. They are both simple sequential block structured languages in style of Algol, Pascal, PL/M and many others of that family. They encapsulate the basic ideas of simple program flow, sequence, selection and iteration. Along with subroutines and local variables. Basically if you know one language in the family all the others are easy to pick up.

    If you were to ask me what is a very different language, one not in that mould, I might say;
    JavaScript: Looks like C, but don't be fooled. With its first class functions (functions as data), lambdas, closures, garbage collection, prototypal inheritance and odd scoping rules it is a lot more of a language than C and enables very different programming styles.

    Lisp, Scheme etc: All of the above but with an unreadable syntax.

    VHDL, Verilog: Massive parallelism on a statement by statement, operator by operator basis.

    Prolog: Rule based. Never did get my head around that,
    c on a PC is very different from c on microcontroller for the reasons described.

    Let's say "may be very different". The language itself is the same. I have programs that run on the Prop or PC without change. There are examples in the propgcc project.

    Of course the environment, libraries etc can be very different. No worries, Spin as a language has none at all.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-09 21:24
    This tutorial is just about the best short introduction to C... written by Kernighan.

    http://www.lysator.liu.se/c/bwk-tutor.html

    If you print it out, it is about 25 pages long and the first 16 pages or so cover all the basics that you can do with a BasicStamp in PBasic. The rest deals will more advanced features.

    I personally find it easiest to first read a short intro such as this, then a longer text.. say 100 to 200 pages; and to finally be willing to explore the big books. Starting out with big books is a huge burden and really counter-productive.

    The ANSI C Manual: 2nd ed. by Richie and Kernighan would be may choice of a 100 to 200 page text.

    I know these books are old... but these are written by the guys that created C and they are much shorter than all the nonsense written today. One really can get up to speed much faster by going back to them.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-03-10 00:58
    Do you know if changing the Basic Stamp by the Propeller and using the Catalina C
    is enough to start moving motors, using sensors, etc. . Is this hardware enough to
    start learning C. ?

    There are not as many drivers for C as there are for Spin. More are being written but there are some gaps. For instance, if you want a servo driver, I'm pretty sure you would find a Spin one in the Obex. But you might not find one so easily for C.

    There is some very clever code that can translate Spin into C and in theory, that would mean the entire Obex would be available in C. But last time I checked it crashed (I think it couldn't handle the \ abort instruction).

    Then there is the way one codes. In Spin, I tend to write code in Spin first, then translate that Spin into Pasm to make it run faster. The process for doing this in C is not quite the same but it is similar.

    The really nice thing about C is that you can add external memory when the program gets too large.

    The challenge (for all of us) is to turn C on the Propeller from something that is advanced, into something that is simpler to use.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-03-10 01:06
    PropGCC and Spin both accomodate drivers entirely in Spin or that are actually written in assembly language (PASM). Not only that, but many of the PASM are optimized to perform faster or more complex tasks.

    So it would seem wisest to start with porting a PASM driver as your first choice from OBEX over to C. The task might be much simpler, as an instertion. And the performance better.

    Besides, even if you want to learn C and ignore SPIN, you are likely to want to learn how to occasionally use PASM with C.

    Of course, you can save your drivers as C libraries and make the changeover complete.
  • KC_RobKC_Rob Posts: 465
    edited 2013-03-10 10:02
    Besides, even if you want to learn C and ignore SPIN, you are likely to want to learn how to occasionally use PASM with C.
    I remain convinced that the Spin/PASM combo is the best, most natural way to get into the Propeller. If the OP wants simply to learn C, then a PC and C compiler would be the better way to do that. (And in any case, PropGCC would almost certainly not be the best place to start out with C.)

    Maybe in future versions of the Propeller, memory, and performance, won't be the obstacles they are now for Spin (regardless of language, insufficient memory in particular is a Prop weakness). Otherwise, Spin is a perfectly fine HLL for learning and doing with the Propeller--and there is a ton of truly free, ready-to-use Spin code already available.
Sign In or Register to comment.