Ardunio C++ SUCKS!!!!

I started programming back in the early 1970's with Basic. I am not a great programmer but in Basic I can pretty much kind of get the job done. I am aware of modern programming ideas (years ago I did a little home programming in Pascal) like subroutines, reusable code, etc. but C++ seems terrible limiting in its structure for doing the programing easily . There are no subroutine calls. Labels seem to be not doable (no real goto statement... I know that is a no-no). And the Ardunio compiler is very poorly documented as to the required structure.

I got my program to compile but I am not ready for testing as some of the hardware is still in the mail to me. What is missing is a cookbook on the structure of C++ with complete programming templates. Examples don't do it! A list of variable types, functions, etc, is not a guide to making a program. Most of the examples vary in implementation enough to lead to confusion (at least for me). So here was my approach, right or wrong, you tell me.

The main program is in a loop looking for a start switch closure. It then calls a custom function (I guess that is a C++ subroutine??) that looks for one of four detector triggers or a stop switch closure, in a loop. Each detector trigger calls one of two different custom functions to energize and de-enrgize some relays. It then returns to the detection process. It only returns to the startup loop if it finds a stop switch closure in the detection process.

So I have to use custom functions as sub routines. I literally had to design each function by trial and error to get the program to compile. It wanted local variables identified individually for each custom function before it would compile (??). Nothing I read pointed out that requirement. What I needed was a book that explains the structure of programs, the required syntax as used in a program, and some templates to use. I searched the internet, bought and read two books, but in the end it came down to trial and error to get it to compile. I don't even know if it will run, as I need the extra hardware to prove that (???). That testing is next and I expect problems!

I really like the added features of the Ardunio UNO but the programming required sucks. Why would a device meant to teach microcontroller science use such a complex, under documented language like Ardunio C++? I suppose it is the next step beyond the Parallax Basic Stamp and has to be more capable but maybe someone should write a better programming book or offer an optional Basic compiler for it(??). I have helped my grandson with the Parallax stamp and it was fairly easy to program. Why can't the Ardunio community come up with an easier to use compiler?

Does anyone have any thoughts on this? Was it something I did wrong or is there a book I missed finding or is it required that you have a course on C++ to be prepared to use the Ardunio UNO? I am very hesitant to release the Ardunio UNO on my 11 year old grandson when I can not find documentation for what I had to do to get my program to compile. He is competent as a programmer for his age but this Ardunio C++ compiler is tough!

LDBennett

There are no subroutine calls

Hold the front page!
"Kernighan and Ritchie have been pulling the wool over our eyes for the past forty years"

You're going to have to put some meat on your rant (show your code) before anyone takes you seriously.

C++ seems terrible limiting in its structure for doing the programing easily

I guess that accounts for its obscurity and underuse in the real world.

  1. It's Arduino, not "Ardunio'.
  2. Everybody else gets with the programme. Why can't you?

Have you heard of Google? Try looking for C++ tutorial and educate before ranting.

Arduino libraries may not be the bst documented as it depends entirely on mostly amateur programmers to do the right thing, so learn C++ and then read the code. Better still, as you learn, document it for other people so that others don't feel the same frustration.

Granted C/C++ is a difficult language in many ways and it's certainly not easy to learn.

But that's not Arduino's fault, blame it on K&R and those that added to the language over the years. Arduino uses standard C/C++, both languages have been around since God was a boy and they are the de-facto standard for embedded work.

There may well be good cookbooks but I haven't looked, not having the need myself.


Rob

One misconception you have is that you're programming in Arduino C++. It's plain vanilla C++ with some arduino libraries to make life easier when you're using the hardware. In consequence, any of the plethora of C++ tutorials you can find on-line will help you with the basic language issues you're having.

Why can't the Ardunio community come up with an easier to use compiler?

Because it is not an Arduino community compiler is is a standard compiler. In fact the Arduino community has come up with a way of making it very easy.

There are no subroutine calls

Wrong, they are called functions but are just like subroutines.

So I have to use custom functions as sub routines.

So what do you see as the difference?

What is missing is a cookbook on the structure of C++ with complete programming templates.

So buy one! C has been going years there are lots.
Also there is no need to use C++ structures you can stick to C for the stuff you write if you want. I do most of the time.

I admitted that I am no programmer and probably most who buy their Arduino (note I spelled it right this time, stupid Italians!) are not either. They sell the UNO at Radio Shack to kids who have NO experience programming at all.

I don't know the difference between C and C++. I just want to get my project (a one time thing!) going. Why must the complier be in C or C++ or any higher level, very capable language at all. If it is to be a learning experience why not offer a complier in a much simpler to use language rather than one that requires a course in C or C++ to use. There are 11 year old kids out there who want to use them, not just programmers with tons of experience. The syntax and form are a mystery in the details unless you are a C programmer, I guess.

Instead of mocking me, how about someone recommending a book that explains it all better, provides templates for easy use, or does something to avoid having to take a college level programming course in C or C++. Us old farts and the young kids don't have the advantage of knowing ten different programming languages or even the industry standard C.

The books that were NOT very helpful were the Massimo Banzi book "Getting started with Arduino" and the Simon Monk book "Programming Arduino..Getting Started with Sketches". ("Sketches"??? What happen to "Programs"). Both cover the basics but do not delineate the details. When I attempt to follow the form of the examples they don't compile for my program. The http://www.arduino.cc page has the same problem for me and the examples are not consistent in their form, at least as I see them. They are not bad books or tutorials but do not offer detailed templates that I believe are understandable by me or a 11 year old kid.

OK, so I'm whining but my guess is that many a new-to-programming Arduino UNO user is put off by the complexity of the programming language chosen for the compiler.There should at least be an optional easier complier using basic or one of its simple derivatives. C or C++ seems to be a "Programmers' language". I worked with them long enough to know they love to invent words and phrases that only they can comprehend (kind of keep it in the family mentality). As an engineer that designed electronic hardware that went to Venus, protected our armies from mortars and artillery, maintained radar systems in the F-14, and many other project over 30+ years, I am not stupid. I do not want to have to take a C programming language course to program a simple UNO for one task. Whatever happened to KISS (Keep It Simple, Stupid).

Now that I've insulted everyone I'm sure no one will guide me to the book I and my grandson need to use the Arduino UNO. Oh well.

LDBennett

Google Cplusplus tutorial, there are hundreds of sites.

This is the main website for C++ and has a great tutorial page.
http://www.cplusplus.com/doc/tutorial/

All I can say is if you want complex, try looking at the assember:
This is an example

00001d80 <main>:
    1d80:	11 24       	eor	r1, r1
    1d82:	84 b7       	in	r24, 0x34	; 52
    1d84:	14 be       	out	0x34, r1	; 52
    1d86:	81 ff       	sbrs	r24, 1
    1d88:	28 d1       	rcall	.+592    	; 0x1fda <appStart>
    1d8a:	85 e0       	ldi	r24, 0x05	; 5
    1d8c:	8e bd       	out	0x2e, r24	; 46
    1d8e:	8e e0       	ldi	r24, 0x0E	; 14
    1d90:	10 d1       	rcall	.+544    	; 0x1fb2 <watchdogConfig>
    1d92:	ba 9a       	sbi	0x17, 2	; 23
    1d94:	c2 9a       	sbi	0x18, 2	; 24
    1d96:	b9 9a       	sbi	0x17, 1	; 23
    1d98:	86 e0       	ldi	r24, 0x06	; 6
    1d9a:	28 e1       	ldi	r18, 0x18	; 24
    1d9c:	3e ef       	ldi	r19, 0xFE	; 254
    1d9e:	91 e0       	ldi	r25, 0x01	; 1
    1da0:	3d bd       	out	0x2d, r19	; 45
    1da2:	2c bd       	out	0x2c, r18	; 44
    1da4:	9b b9       	out	0x0b, r25	; 11
    1da6:	58 9b       	sbis	0x0b, 0	; 11
    1da8:	fe cf       	rjmp	.-4      	; 0x1da6 <main+0x26>
    1daa:	b2 9a       	sbi	0x16, 2	; 22
    1dac:	a8 95       	wdr
    1dae:	81 50       	subi	r24, 0x01	; 1
    1db0:	b9 f7       	brne	.-18     	; 0x1da0 <main+0x20>
    1db2:	ee 24       	eor	r14, r14
    1db4:	ff 24       	eor	r15, r15

C++ allows you to not have to do this, but rather have a much easier to understand layout. Its not simple by any means, but there is little way around that.

A good place to start might be a graphical programming method.

Is an arduino compatible graphical interface. It allows you to build programs by dragging in blocks, and then shows you what the C++ for your program is. Alternatively you could try something like Flowcode which is another graphical programming language.

If you are patient with it, you can get to know C. For part of my Uni course, the 70 of us were given an arduino and told to make something, with very little instruction, and many had no prior knowledge of C or C++. If you would like I can send you a copy of the notes we were given which may help.

Really, you have to define "simple".
COBOL is really simple, and easy to read, but is verbose and not suited to microcontrollers or their applications.
APL is compact and simple, but illegible and gobbles memory for the matrices it operates on.
BASIC is ...well, I'll leave you to look up what Dijkstra said about BASIC.
FORTRAN is a bit like BASIC, and apart from legacy, not sure if it used much.
Other popular languages look a lot like, or were based on, C.

And don't underestimate the capacity of the eleven year old brain to absorb knowledge, but please don't transfer your prejudices to it.

Why must the complier be in C or C++ or any higher level,

Because you only want to learn one language, not dozens of assembly languages.
That's the big step forward K&R instigated.

The syntax and form are a mystery in the details unless you are a C programmer

I don't speak Spanish, but I do speak French, so the form and syntax are not a complete mystery.

"Sketches"??? What happen to "Programs"

They're obviously not programs, because programs have a "main".

(and yes, I'm an old fart too)

Don't take the bait.

Duane B

LDBennett:
I admitted that I am no programmer and probably most who buy their Arduino (note I spelled it right this time, stupid Italians!) are not either. They sell the UNO at Radio Shack to kids who have NO experience programming at all.

Considering that the Arduino is targeted to kids and artists (hardly left brain thinkers) who have used it in massive numbers your rant is both wrong and rather tiresome...

Don't take the bait.

Who is that directed at? :stuck_out_tongue_closed_eyes:

I moved to the arduino platform mostly because it forced me to learn to use C/C++ in my hardware projects. It is for many reasons the best high level programming language to use for micro-controllers. However it does have a steeper learning curve and require more initial effort then some other languages perhaps. Probably the simplest language one might start with is the Basic language. The PICAXE folks make nice inexpensive modules and standalone chips that utilize the basic language, includes a bootloader and can be very easy to get started. However a lot of the knowledge you will learn will not be directly transferable to other brands and models of controllers if you wish to grow with the hobby. C/C++ is the defacto 'standard' for most micro-controller boards these days. Anyway the PICAXE and their forum (friendly folks there) may be a better path for you if you don't or can't crack the start-up effort needed for C/C++ as used in the arduino platform.

http://www.picaxe.com/

Good luck;
Lefty

The basic problem is that to keep cost and power requirements low, we are working on an 8 bit controller here with a small amount of static RAM and a small amount of program space. The language needs to take that into account. It can't produce 100K files for a Hello World application like a Windows compiler does. The only good language choices are assembler, C, and C++. And they are difficult languages compared to writing in Visual Basic for sure. You have to think out exactly what is going to happen in terms of bytes in memory for every array and string function that you do, otherwise you will overrun a buffer and have a hard-to-troubleshoot bug, especially since the development environment doesn't even have a debugger. But what you get for learning that is the ability to work on very inexpensive microcontroller systems and it is rewarding. And I disagree with you about examples, examples are the most powerful way to learn. If you read a reference about arrays that is all you learn about. A good example puts dozens of techniques together and shows you how they work for a real application.

Grumpy_Mike:

Why can't the Ardunio community come up with an easier to use compiler?

Because it is not an Arduino community compiler is is a standard compiler. In fact the Arduino community has come up with a way of making it very easy.

I couldn't agree with this more. I mean, to get the Arduino system to work all I had to do was plug it into my USB, let the computer get the driver for it, download the software, run the software, open the blink sketch, and click Compile and Upload. I don't know any other system this easy. Once you can read and write the pins, you can read and write the world.

I happen to agree that it sucks -- but it's what we have Complaining is futile. Complain more any and you will never be assimilated. Then you'll be sorry!

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

Search for similar.

Look for the Element 14 Web site if you want some more esoteric stuff.

I do not aspire to become a crackerjack C or C++ programmer. I just want to make my little project work. I'll probably never do another one but I want my grandson to move this way so I have to kind of get up to speed so I don't tell him anything that is incorrect. I down loaded the C++ Tutorial suggested and I'll go through it. Today I'd be at a loss to tell him how to generate any program (sorry SKETCH) with certainty. I got mine to compile but that means nothing. I'm awaiting hardware to test it on.

I understand the limited resources inside the UNO and the need for a language that is not too verbose. And I appreciate this compiler might allow a gifted person to do marvelous things. It is the documentation that I had at hand that was so limiting and the totally different approach to programming (than Basic for example) that left me hanging. I could not find examples that were anywhere close to what I wanted to do. I could not even find an explanation of how to use custom functions (to make the equivalent of subroutines) and I did search the Internet for specific examples. Different examples did the same thing in different ways and apparently my added complexity did not allow the easier way. I just wanted the rules for what was required at a minimum and I could not find them in either of the books I had or in the Internet searches I did (I really didn't know exactly what to search for). Somehow complex custom functions (subroutines in old-speak) seem key and they were not covered...What is with that?

Anyway, I'm still of the opinion (and it may change after reading the tutorial) that some programmers have made the task of programming the UNO particularly complex because they can. In my dealings with programmers over many decades I have found this to be true. I have sat through many programming design reviews and left completetly lost, mostly because of the complexity and their need to invent their own words and language.

Thanks to those who did offer help. Regardless that I am so negative about this Arduino compiler, I do appreciate those that offered help. On to the tutorial...hope it helps!

LDBennett

LDBennett:
Somehow complex custom functions (subroutines in old-speak) seem key and they were not covered...What is with that?

Instead of re-inventing the wheel with tutorials on common C/C++ features, why not leave that to the millions of articles already out there? It sounds like what you're trying to accomplish is very specific, in which case, I'm not sure why you would get mad about there not being an example of it already. That's the nature, of well, life. If that's not the case, try broadening your search to C/C++ examples instead of just Arduino examples.

Anyway, I'm still of the opinion (and it may change after reading the tutorial) that some programmers have made the task of programming the UNO particularly complex because they can.

It's obvious then, that you haven't looked at developing with standard AVR tools, PICs, or other microcontroller systems.

LDBennett:
Anyway, I'm still of the opinion (and it may change after reading the tutorial) that some programmers have made the task of programming the UNO particularly complex because they can. In my dealings with programmers over many decades I have found this to be true. I have sat through many programming design reviews and left completetly lost, mostly because of the complexity and their need to invent their own words and language.

Different professions make use of specialized vocabularies for a reason--precisely conveying the mean of complex or specialized ideas. Talked with a doctor recently? However, I reiterate my original point. The Arduino has been used by thousands of artists, beginners, and children to implement a wide variety of projects. People who are not programmers... The Arduino environment is about as simple a programming environment as possible for a general purpose microcontroller, it doesn't require programming knowledge/experience. It does require a willingness to learn. If you want to actually learn, I would suggest starting with one of the books such as Massimo's...

Internet information is of unknown quality. That combined with your stated desire to implement a specific project (which may not be within your capabilities) are likely the source of your frustration. Learn the basics first.

Regardless that I am so negative about this Arduino compiler

It has already been noted that it is not "this Arduino" compiler, it is a bog-standard gcc compiler.
Please, get this one straight.

In my dealings with programmers over many decades I have found this to be true. I have sat through many programming design reviews and left completetly lost, mostly because of the complexity and their need to invent their own words and language.

I too hate jargon, but all disciplines have it for very good reasons. Should we call programs/sketches "knitting patterns" or "recipes", because, honestly, I cannot think of a closer analogy in everyday language or experience.

Believe me, I have programmed tens of different families of processors and architectures, and not one compares to the power or relative immediacy of the Arduino. You're bare-metal programming (unlike BASIC) using a single language (unlike assembler) on cheap hardware (unlike just about anything) using free tools. How much better can it get?

the totally different approach to programming (than Basic for example) that left me hanging

This I simply do not accept. Programming is setting out a process in a logical fashion, the language is largely irrelevant. It is as easy to write good code in BASIC as it is to write crap in C. It is the approach to programming, not the language, that is the difference.

I'm awaiting hardware to test it on.

And there, I would suggest, is the nub of your problem.

I learned to program in BASIC.
We wrote out our programs, typed them into a teletype and punched them to paper tape.
Then, we combined all the tape for the class onto a single tape, someone got on the bus to the local university, handed over the tape and went home.
Next day, someone else picked up the printouts and brought them back to school.

College wasn't much better, with maybe four batch runs a day if you got up early and worked late.

How long is a cycle on the Arduino?