Connect with us

i want to learn to code but.....

Discussion in 'Microcontrollers, Programming and IoT' started by nikki81, Aug 18, 2012.

  1. nikki81

    nikki81

    36
    0
    Jul 16, 2012
    ive been wanting to learn to code for years but never had the time but just been given the size 11 boot from work so ive a bit of time now.

    what it the best most universal easy to learn language for microchip pics and arduino ?
     
  2. CocaCola

    CocaCola

    3,635
    5
    Apr 7, 2012
    In today's world a C flavor is going to be your best bet...

    Learning Assembly is also a real strong benefit, but you will find C has pretty much become the industry standard language... Assembly will give you the ability to optimize and write a lot tighter and streamlined code, a strong selling point if you have the skill...

    You might find that learning BASIC is easier to get going and generally faster to learn, and once you learn any of the languages it's just a matter of devoting yourself to learn another, the logic and flow you learn when coding any language is pretty much identical, so that ports right over, it's just a matter of learning the new language syntax and little quirks...
     
  3. nikki81

    nikki81

    36
    0
    Jul 16, 2012
    should i learn c or c++ ?
     
  4. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    c is standard, most micro controllers use c as do older games. c++ is advanced and changes around things so try using c first then adapting to c++ later.

    there are forums to help you I used one for a while until I realised my brain was not that good at computer coding. I did make some basic programs like "hello world" and one that drew a square with a ball in it that I could move using arrow keys.

    The big issue is compiling, there are so many programs out there. and each have its use, arduino compiles for arduino only and you cannot use it to make the next first person shooter. PIC has its own too.
    depending on what you intend to use it for I would reccomend getting that compiler to start. also if you want to get into computer or app development then you have to get their compiler which usually needs a registration of some sort
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    To be perfectly frank, C is a pain in the bum, and C++ is a bigger pain.

    Neither are languages for beginners. People who say they are are either not programmers, or have not been exposed to a wide range of languages. There is so much you can do wrong and even the best compilers can't (or won't) catch it. It can lead to very poor practices.

    For beginners I wish I could advise something better.

    However, commercially, C is the go.

    I would recommend that you find a skilled programmer to review what you write. They will understand where you've made subtle mistakes or done things in a way that is fragile or prone to unexpected failure.

    Assembler is an even bigger pain again. Leave that alone for a while.
     
  6. CocaCola

    CocaCola

    3,635
    5
    Apr 7, 2012
    Steve I fully agree, and the reason my C and assembly is still rough around the corners... I can limp by if I have to with both but I will shy away from both in an instant if given choice... But there is little argument that C is the best choice in todays market, followed by assembly if optimization is priority...

    BASIC and PASCAL are a lot easier to learn but you won't find even 1/10 the cross platform compatibility... Plenty good for the hobbyist though if you pick a compiler and chip series that has readily available compilers for those languages...

    BTW not my compiler of choice, but I have used it to some degree and overall the compilers from www.mikroe.com are very competitively priced and are very decent... With them you get BASIC, PASCAL and C options across multiple chip manufactures giving you a ton of flexibility to hop around for a reasonable cost, and with little to no change of your preferred language...

    Also Arduinio is C, so if you want want to use the Ardunio software platform you are kinda stuck... You can of course still use other languages and load them on the AVR with a little work, but that really negates the whole Arduino concept...

    On thing to note, generally the more you pay for a compiler suite the more it will flag your coding errors before or when you compile... This initial investment can pay off in getting you disciplined to the syntax of the language you are working with vs struggling for hours looking for an open or close bracket you might have missed...
     
    Last edited: Aug 19, 2012
  7. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    as a s/w engineer who can't design a board from scratch as a hobby my next project with a embedded microprocessor is likely to be with arduino. I just like the idea of being able to connect it up to a peripheral (such as NFC or Bluetooth) without needing to make custom hardware for it.
     
  8. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    I REALLY like basic cos it is BASIC. I still get confused with C on a daily basis, and I can interpret what a program does, or what a fault could be, but don't ever ask me to give you the right coding cos I still get stuck on library references and other little things. I really like basic and if given the choice would use it in a heart beat.

    the big difference is though is that basic is just that. I have not delved into C too much but all the coders I talk to say it can do alot more than BASIC and I think that is application oriented not microprocessor oriented.
     
  9. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    Having played with the PIC16F628 in assembler and JAL (Just Another Language) and the Arduino Uno in C, I must say that the languages are easy enough but the PIC was a pig. I could not get the comparator to work even after months of trying. Trying to read the PIC datasheet, and trying to configure the pins for the correct input and output I found so difficult that it motivated me to dive into electronics to find dedicated components to do the job.

    JAL is relatively simple and is compatible with most PICs. Arduino is a pleasure after the PIC, since Arduino comes with its library of routines. Also the Arduino allows analog input which the 16f628 did not - and analog is very necessary.

    Is there a small, cheap PIC out there which is easy to get to do ones will?

    If you are wanting to learn on your own I suggest the Arduino is much easier to work with to produce predictable results. This means you are stuck with C. I have never programed in C before, but find it easy enough to modify the routines written in C which come with Arduino.
     
  10. CocaCola

    CocaCola

    3,635
    5
    Apr 7, 2012
    It's not that hard just a few lines of code, you must have been missing something very basic or not understanding the datasheet...

    The Arduinio compiler does have a bunch of libraries, like most libraries they can be bloated pretty badly vs coding it proper for your needs... But, that isn't to say that other compilers don't have libraries, many do even the JAL compiler you pointed out... The Mikroe compilers I suggested above have a vast variety of built in libraries that come with the compiler, as well as many other fan built ones that can be found in the forums... The same can be said for other compilers...

    I believe what you are actually comparing is your experience with the Arduino IDE vs the JAL IDE, and yes the Arduino IDE is a clean and user friendly interface, that has pros and cons attached to it though...

    Yeah, but there are 100s of other PIC chips you could/should have chosen one with an ADC if that is what you needed... You should chose the micro for the job, not force the job onto a micro...

    Comparing a PIC16F628A to an Atmega32 (on the Ardunio) is of course going to be lopsided they are not comparable or even in the same league chips... You should be at least comparing the PIC18 series with a closer pin count to level the playing ground... And when you do that you will see that neither has a real advantage in the end, they offer differences that can make or break a particular design depending upon you needs...

    Again pick the chip for the design, don't force the design upon the chip...

    Do what? There are plenty of cheap PIC chips that do all sorts of stuff... I have done A LOT of projects with the PIC12F683 it's a cheap 8 pin work horse...The PIC16F88 also gets a lot of use by me, as does the PIC16F628, as well as many other bigger, newer and better PIC chips... I choose the chip for the application, and sometimes you have to flip companies and use an AVR or PIC (or whatever) to take advantage of something one or the other has that will make the project smoother...

    I'm not sure I follow that, I get predictable results all the time with my PIC chips, it's more a matter of knowing your hardware and software... If you limit yourself to one chip and one platform of course you can wrap your head around the results quicker, but in the same instance you are tying your hands and limiting your options...
     
  11. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    I agree 100%

    Go to the microchip web site. they have a tool which allows you to select a chip based on the features you need.
     
  12. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    I agree totally with everything that CocaCola wrote, especially the above.

    Let us assume that Nikki81 is about to buy just one micro and its programmer. He should start with the question, "what do I ultimately want to do with it?". IMO it is better to start with something easy that can do almost anything you want (including analog input) like the Arduino, than struggle like I did for a year with the PIC, first trying to understand the datasheet, then the registers.

    In an hour after acquiring my Uno, I could do more than in a year's worth of frustration with the PIC. I am sure that if you learn to program the PIC at university, with help at hand, you may have a wonderful experience. But, if you have limited experience at reading electronic datasheets (like I do), then you need a chip which manages all the registers and timers for you.

    I am a bit of a masochist, so I did enjoy all the pain which the PIC inflicted on me.

    But as to Nikki81's original question, I don't think there is just one universal language to control both PIC and Arduino. And my experience is that it is not the langage ultimately which is going to give you grief - its the environment around the chip.
     
  13. CocaCola

    CocaCola

    3,635
    5
    Apr 7, 2012
    You make it sound as if the Ardunio is the only thing that can do "almost anything you want" this is so far from false it's not even close... You really need to stop comparing your experience with a single low end PIC to a complete developer system using a higher end chip more feature packed chip, it's Apples to Oranges... A more fair comparison would be something like the AT90S2313 to the PIC16F628A, and yes the AT90S2313 is an obsolete chip, so maybe a stripped down ATtiny chip successor like ATtiny2313, that comparison is more Apples to Apples... There are plenty of PICs that support analog input, you simply chose a stripped down low cost chip that didn't support that option, but there are $1 PIC chips that do have analog input...

    I'm 100% self taught and the PIC has been a wonderful experience since day one, if it wasn't I wouldn't still be using it as my primary go to micro... I learned both the PIC and AVR at the same time way back when... Atmel's reoccurring chips shortages (even back then) is what initially leaned me even more towards the PIC... I was developing product and couldn't wait months for supplies to return or pay excess for the chips... PIC also offers me more flexibility in tailoring the chip to the design as their offerings far surpass any other manufacture... Sure I have had a few WTF moments and I still get them but that would have happened regardless of the platform I chose...

    The chip is not handling it, the compiler is, and the reason it's able to handle it in the case of the Arduino is because the focus is on limit chip architecture that is can preset for you since there is only a few options available... The Arduino is tailored to hiding stuff from the newbie, this certainly has it's advantages early on, but can/will come back to bite you in a big way once or if you progress beyond the Arduino... Once you familiarize yourself with any chip it's honestly painless to configure manually anyway, and it can be automated just like it is with the Arduino using the same type of includes if you choose...

    Sure there is any of the common higher languages are mostly universal... The only difference is minor chip specific definitions and sorts, 90% or more of the program itself is universal... That is why I specifically linked to Mikroe compilers since they are all made by the same company jumping from chip manufacture to chip manufacture is as painless as it's going to get since the language syntax remains the same and the only adjustment is the hardware architecture specifics... I port stuff all the time between PIC and AVR and the reverse... Once you have a decent grasp of the language and chip architecture you use it's nearly painless... IMO it's akin to a regional dialect of a spoken language, mostly the same but with slight twist, some of those regional quirks might catch you off guard initially but it's not the same as learning a completely different language...
     
    Last edited: Aug 20, 2012
  14. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    I agree with everything coca cola has said, the only reason I use arduino is my soldering is crap and there is a larger community to ask advice from.
    every single micro has its ups and downs. very few micros have the same pin layout.
    you NEED to choose the right micro for the job.
    and I agree 100% (only cos 110% is not possible yet) with coca colas response to programming. C language is used on most micros and yes you can use alternatives. C language has a standard which has to be adhered to no matter what, or else it cannot be called C. pin layouts and certain ways of doing things are written in different ways BUT they HAVE to follow the C language standard when it says it is supported for C.
     
  15. GreenGiant

    GreenGiant

    830
    6
    Feb 9, 2012
    I started with assembly and couldnt grasp it at all, granted the teacher sucked, but still

    I moved to Visual Basic after that, and being a visual interface that you see definite changes with made it a lot easier to pick up, after getting proficient in that I went to C++ which was a little more difficult but having the basis of visual basic helped a lot with organization and program flow

    That is all that I have really used as far as programming, I have a lot of experience with Arduino, and some with AHDL (not something that you would need, and you would spend a LOT of time learning it) C++ helped a lot with Arduino programming
     
  16. foTONICS

    foTONICS

    332
    9
    Sep 30, 2011
    I self taught myself assembly so I could learn how to use PIC's. Although it has a steep learning curve, once you learn the layout of the registers and the specific micro's abilities. I feel that assembly on a whole makes you understand the inner workings of a micro WAAAAY better than an arduino. I actually prefer coding in assembly since it allows me to very precisely control what's going on
     
  17. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    I learned assembler back in the 80's on the ZX81. Learning PIC assembler was no great stretch.
     
  18. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,214
    2,695
    Jan 21, 2010
    I learned assembler on a DEC-10. Then on a 6502, then a PDP-11, then an 8088, then I looked at 68xxx assembler.

    PIC assembler still looks like chicken scratching to me :eek:

    Having said that, I've never really had the desire to seriously program them in assembler. The idea of a Harvard architecture machine is just too awful :D
     
  19. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    After programming assembler on a number of different MCU families for over 30 years, I've added C to the list for microcontroller programming the last 3-4 years. The one thing I've found during this time is that the problem is mostly never related to the program language, but the bloody IDE each of the suppliers adhere to. That is the big hurdle in the race for me. To get to the innards of the IDE is a real pain wherever you don't want it :D

    If you want to start in microcontrollers, you need to go down into the hardware and the datasheet, to get some real life action, in addition to the programming language itself. You need to understand what is happening in the hardware based on what your program does. Thinking and understand what is happening in the time domain is also important, at least when your program is getting up to speed.

    I would recommend C as the programming language to start with, and a good dedicated library package for the chip you want to use.

    To train in the actual syntax of the C programming language I would have downloaded a free compiler and run som exercises on the PC, just to get into the syntax.
    Get a good beginners book on C, and start learning.

    Most IDEs I've seen have tutorials and examples, and forums for users. Use all extensively, and have a great time.

    TOK ;)
     
  20. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    The programming language is not my weak link either. It's reading Datasheet - a terrible language for beginners.

    And all datasheets seem to be written by the same guy. He does not get my vote for a Pulitzer Prize. He uses abbreviations like Vcc, Vss and "weak internal pullup" which I don't use at the dinner table. The man seems to write it as if he were late for something (maybe writing the next datasheet), cramming as much info on one page as he can get, without so much as one attempt at humor or explanation. Reminds me of some of my teachers. When they fire him one of these days, I am going to apply for the job of Datasheet Writer.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-