Go Down

Topic: Ardunio C++ SUCKS!!!! (Read 10780 times) previous topic - next topic

LDBennett

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

AWOL

#1
Aug 02, 2012, 02:42 pm Last Edit: Aug 02, 2012, 04:02 pm by AWOL Reason: 1
Quote
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.

Quote
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.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Runaway Pancake

1) It's Arduino, not "Ardunio'.
2) Everybody else gets with the programme.  Why can't you?
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

marco_c

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.
Arduino libraries http://arduinocode.codeplex.com
Parola for Arduino http://parola.codeplex.com

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

wildbill

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.

Grumpy_Mike

Quote
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.

Quote
There are no subroutine calls

Wrong, they are called functions but are just like subroutines.
Quote
So I have to use custom functions as sub routines.

So what do you see as the difference?

Quote
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.




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.

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

Tom Carpenter

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
Code: [Select]
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.
http://blog.minibloq.org/
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.
~Tom~

AWOL

#9
Aug 02, 2012, 04:25 pm Last Edit: Aug 02, 2012, 09:42 pm by AWOL Reason: 1
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.

Quote
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.

Quote
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.

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

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

(and yes, I'm an old fart too)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DuaneB

Don't take the bait.

Duane B
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

wanderson


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...
New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

AWOL

#12
Aug 02, 2012, 04:43 pm Last Edit: Aug 02, 2012, 04:51 pm by AWOL Reason: 1
Quote
Don't take the bait.

Who is that directed at?   :smiley-yell:
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty

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

JoeN

#14
Aug 02, 2012, 06:05 pm Last Edit: Aug 02, 2012, 06:09 pm by JoeN Reason: 1
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.


Quote
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 have only come here seeking knowledge. Things they would not teach me of in college.

Go Up