Program language doesn't make sense! Book to learn?

I've been working through a couple of beginners' project books. One is John Boxall's book. The other came with a beginners' kit I bought. I can follow the schematics okay, but the programming is kicking my ass. I understand basically what's happening...very basically. I'm having issues with understanding when punctuation is used and how. Even after inputting this code into the IDE, it's not clicking. Is there a book you guys would recommend that would teach me the language? I've never programmed anything before. I need this book to break it down Barney-style.

It would be easier for us to explain if you could quote the part of the code you don't understand.
For starters you can just start by going to youtube and search, there is a lot of beginners guides and tutorial videos teaching you.

I didn't think about YouTube tutorials. I'll definitely look into that. It's not one particular section of code I'm having trouble with, though. It's that going through these projects, I'm just copying the examples. I'm not picking up on it. After inputting one line, I can't really guess what the next one will say. I thought going through the examples would basically teach me, but it's not making much sense to me.

There are a bazillion books on C programming out there. To limit you search, try searching for programming books for C and specifically the Arduino family of processors. I am biased, but read the reviews for Beginning C for Arduino by Purdum. You can read reviews on the book at Amazon.com. If you click on the cover, you can read the Table of Contents, select a topic, and read a few pages from the book. That and the reviews might help you decide if it suits your way of learning.

I'll check it out. Thanks!

I second econjack's suggestion. Beginning C for Arduino works like a textbook - there are chapter quizzes and each chapter builds on the previous one. You will need to step away from the project you are currently working on and learn in 'baby-steps'. You will come out of it a stronger programmer.

Books are a bit more time consuming than a youtube lesson, but with a book you determine the pace, not the video maker.

I could see you are very new to programming. So it will be better you start the basics of C programming. Any good beginners C book will help you. Once you learn the basics of C then you can move on to Arduino programs.

Beginners C book will teach you.

  • Syntax of C program
  • Variable decleration and scopes
  • Conditional statements
  • Functions

Then mixing all the above. Once you do that you will be very comfortable to deal with Arduino.

When I started I can understand programming very well but Electronics was totally new to me :slight_smile:

sarouje:
I could see you are very new to programming. So it will be better you start the basics of C programming. Any good beginners C book will help you. Once you learn the basics of C then you can move on to Arduino programs.

Beginners C book will teach you.

  • Syntax of C program
  • Variable decleration and scopes
  • Conditional statements
  • Functions

Then mixing all the above. Once you do that you will be very comfortable to deal with Arduino.

When I started I can understand programming very well but Electronics was totally new to me :slight_smile:

I disagree Sony. Unless the OP has a system available so that programs can be compiled and run, the reading will be very abstract. Even with a compiler, editor and computer, the programs will likely rely on standard libraries, and standard I/O, which are not needed in an Arduino program.

Purdum's book does cover all of the topics you mentioned, in fact, it is a book for beginners that uses Arduino as a platform, instead of the more commonly assumed, unix (or unix-ish) shell that most other beginners books assume the reader has. Other than that, it is similar to other beginning C books.

Last summer, I was working with students in a microprocessor course (I wasn't teaching it, but I was an available resource for the students.) The biggest problem students had was understanding that Arduino (as well as Microchip PIC boards, which for some reason the instructor preferred) uses the (familiar to us) setup() and loop() structure. Many of the students tried using their own loops, and began their program with a main() function. Merely learning about the overall structure of an Arduino program was a great revelation, and they were then able to make progress.

My point in this is that if the desire is to learn to program a microprocessor, getting lessons that compile and run on an Arduino from the get-go is the easiest and fastest way to move forward.

I agree with you Chris. I suggested to read a beginner C book is only to get comfortable with Syntax of the language. As OP mentioned he had difficulty to understand where to put semi colon. I havent read Purdum's book, if it covers syntax then it's more than enough.

Google "C++ tutorial". There are plenty of resources on the net for simply learning C++ by itself. You don't need to do the whole thing, either - the first few lessons in whatever tutorial you read will cover the basics of the language, which is where you are having trouble.

The tutorials mainly deal with "C running on a regular computer" - they will use System.out instead of Serial, and they don't have a setup/loop arrangement. But that isn't important for what you are having trouble with, although you will need a compiler if you want to do the examples. Install XCode if you are on the mac. Any linux distro will already have one. Don't know about windows.

Put the work in, do a tutorial. Any of these will do:

http://www.cplusplus.com/doc/tutorial/

http://www.learncpp.com/

Thanks for all the input. I've downloaded Purdum's book. And I've also found YouTube tutorials. From the looks of it, I should be good with the more Arduino-based book rather than one that deals with what the language does outside of that platform. If it doesn't address syntax in a way that makes sense, I'll find a beginner C book to learn some more.

Thanks!

Another vote for Prudum's book "Beginning C for Arduino" - I have the second edition. Chapter 2 starts out with defining statements, functions etc. and showing the syntax. It also does a good job of showing how to use the help function in the IDE for the online reference.

I've never seen the Beginning C for Arduino book but I like the idea!

Much of Standard* C/C++ won't run on the Arduino... The basic syntax & structure are the same but the details are different. For example, the first program you learn in almost any programming language is "Hello World!" (which simply displays "Hello World!" on the screen). Of course, the Arduino doesn't come with a screen. C/C++ also expects a keyboard and disk storage. With the Arduino the "Blink LED" example is equivalent to "Hello World!"

I'm having issues with understanding when punctuation is used and how.

A book should help, as will practice. Every programming language is different and the compiler is "picky". You'll learn a lot by making mistakes! :slight_smile: A misspelling will cause an error, a missing semicolon or missing/misplaced curly bracket will cause an error. And, it's easy to confuse the compiler and it can give you misleading information. I had a misplaced curly bracket once and the compiler reported hundreds of errors...

When I was learning C & C++ (from books) I typed-in all of the example programs by hand so that I had to pay attention to the details.

When writing your own programs start with a "shell" or something like the Blink LED example, then write one or two lines at at time, test-compiling and test-running as you go. This is a little tricky and it takes some practice because the compiler has to see a "complete program". For example, if you delete the last half of a program, you will get errors when you compile. Of course, professional programmers write more than one or two lines at a time, but they are usually working on larger programs and nobody writes the whole program before trying it.

And, it's very helpful to send variable-values or other messages out to the Serial Monitor so you can "see" what your program is doing , and if it's working so-far, before it's done.

There are two types of bugs/errors - Syntax errors will be reported by the compiler. Logical errors won't be caught by the compiler but the program won't do what you expect.

I've never programmed anything before.

Although many Arduino programs are "easy", and the Arduino is a good-easy way to learn, in general, programming is difficult! Not everybody is good at it, and it's "different" from any other subject/discipline. Professional programmers make mistakes every day... In any other profession you'd be fired for making so many mistakes!

The two most important concepts in programming are conditional execution (if statements, etc.) and loops (doing something over-and-over, usually until some condition is reached).

  • There are ANSI/ISO C and C++ language standards.

Two things to be aware of in the C language that WILL bite you (ask me how I know :o ) - statements are terminated with a semicolon. The way you normally write a conditional statement is along the lines of
"if (this == that) { do some things}". the statements between the curly braces get executed. The common mistake is to put a semicolon after the "if (this == that) ;" which terminates the statement and the stuff following in the curly braces gets executed each time through because they are no longer part of the "if" conditional. The other common mistake is also in the conditional where you write "if (x = 5)" for example. What you are trying to do is test for 5, but what it really does is set x=5 which is then true. The double "==" tests the value while the single "=" assigns the value. (and both are "correct" statements and will compile without error!).

another 'gotcha' is MOST programming languages is:

= means assignment

ie: var x = 2;

== means conditional check

ie: if( x == 2){ //execute if true, if x equals 2};

dont feel bad! I have a web programming background.. (spoiled)... and I still have difficulty with the data types what is best to use when/why...etc

C/C++ was never designed as a teaching language. It is very close to the machine. Lots of things are for efficiency and not ease of use. Some languages, like Basic and Pascal were explicitly designed for this purpose, and can also be useful.

The Arduino (eg UNO here ) is also a strange beast even to seasoned programmers who have not worked at such a low level before. 2K of memory, no Operating System, Interrupts, the setup()/loop() paradigm etc. You can't (or shouldn't) use the object oriented features (except maybe creating one instance of class in a library) or recursion etc. because all that has an unpredictable runtime resource usage.

However, I'd say this, that once you have understood the Arduino graphical user interface of the development environment and are in a position to write a few line of code, load that onto an Arduino, and get a led to light, you can then, in simple steps, progress on to more complicated things. You should soon get a grasp of what a variable is, how program steps are sequenced, how to perform selection and how to repeat blocks of code. Important is to work with a few basic constructs, a very small but useful subset of the language, (say "if/the/else" or "for" ) and understand those instead of attempting to learn the huge number of features the language supports.

You guys are awesome! I'm loving all the feedback!