Beginners start here ! - Mark II

With reference to lastchancename's "beginners start here!" topic:

Newbies: go and do a C++ tutorial.

So many newbie posts here are by people who clearly can't program C++ and who are copy-and-pasting code until it looks right. You can't learn C++ by example. Well, I suppose you can, but you won't get far and you'll always be wondering "how come it doesn't work when I put a semicolon there?"

There are plenty of them on the web:

And almost any of them will do for the kind of programming that you will do on an arduino. Learn about:

  • primitive types (char, byte, int, long, unsigned, float)
  • operators and operator precedence
  • bit-fiddling operators << <<< >> | & ^ ~, and how numbers are made out of bits
  • variables, especially variable scope
  • control structures: if(), while(), for(), switch() and what braces and semicolons mean
  • functions
  • arrays and pointers

You can go on to structs and classes if you like. But if your code isn't compiling, then you don't need someone on this board to tell you where to put the semicolon, you need to do a C++ tutorial, ok?

There are some caveats:

  • we tend not to use the String class and dynamic memory allocation in a micro controller.
  • Serial instead of stdout and stdin
  • setup() and loop() rather than main()

You do often see on this board C++ programmers using techniques that aren't suitable for the limited amount of space on an Arduino, and sure - they have stuff they need to un-learn.

But for people with questions like "how do I make array?" or who write repeating blocks of code rather than use loops and functions (the giveaway being "my sketch is too long to post"), people who are new to programming altogether or only experienced with scripting languages (php, basic) or Excel macros: please learn the basics of the C++ language.

It won't take long, and it's worthwhile.

Please make the link clickable! We beat up on newbies for not bothering to do that. You've been around long enough to know better.

All good advice, but if people won't even read this before posting a programming question I don't have great hopes of them following any other advice.

It is difficult to put yourself in the position of a new Arduino user with no programming experience. When I first got an Arduino I had never written a single line of C let alone C++ but I had written programs in BASIC, 6502 and Z80 assembler and even MUMPS (yes, it is a real programming language) so I was aware of the basic programming structures such as conditionals, for loops, functions etc. and the need for variables of different types (no data types in MUMPS though !) with different scopes.

I think that it is a shame that BASIC gets such a bad press, and it is too late to do anything about it, but if it had not been extended beyond being a Beginners language it might have still fulfilled its original purpose of being a stepping stone to more powerful, structured and ultimately OOP programming languages, but who starts with BASIC these days ?

All good stuff if the newbie's objective is to learn programming and not just regard programming as a necessary evil in achieving the goal of getting a couple of Leds to blink, a robot to lift its arm or a school homework assignment finished with the minimum of effort.

UKHeliBob:
...but who starts with BASIC these days ?

When I left teaching programming in the Computer Technology department, we used C# as the intro language, then Java (mainly because of web development) and finally C++. The Computer Science department majors learned assembler and then C. At one time, we used Visual Basic, but its tarnished reputation...deserved or not...poo-pooed it into oblivion.

econjack:
When I left teaching programming in the Computer Technology department, we used C# as the intro language, then Java (mainly because of web development) and finally C++. The Computer Science department majors learned assembler and then C. At one time, we used Visual Basic, but its tarnished reputation...deserved or not...poo-pooed it into oblivion.

I come from an Enterprise management position. REAL C++ programmers do not use Arduino. The dudes that are off porting new hardware cores to the Arduino are the C++ champions; many, many users can use and enjoy Arduino as a hobby and never even know that C++ exists under the framework.

The whole conversation yesterday and again about learning to program in C++ is absolutely insane to my thinking ...

This is just absolutely wrong:

So many newbie posts here are by people who clearly can't program C++ and who are copy-and-pasting code until it looks right. You can't learn C++ by example. Well, I suppose you can, but you won't get far and you'll always be wondering "how come it doesn't work when I put a semicolon there?"

Let's see how many folks we can scare off from a rewarding Arduino hobby. Let me make this perfectly clear, if you are even half-serious about doing common Arduino projects, there is no reason that you must go and take a course in C++.

Will a course in C++ make your Arduino hobby more fulfilling? Absolutely.

Will knowledge in any programming language make your Arduino hobby more fulfilling? Absolutely.

Do I need to be a EE to wire up a LED to an Arduino and blink it? Absolutely not.

Would it help if I understand Ohm's Law which states E=I*R? Absolutely.

Newbies:
This is my opinion and will certainly not reflect many in the forum. So be it...
You can be good at Arduino without knowing much more than the commands given here in the Arduino Reference Section.

You will be expected to study a bit and to run a few examples from the Examples Pages.

You will be expected to be realistic; you are not going to program the next Mars Lander on your Arduino. It will not happen.

You need to not expect the forum to help you do your homework - BUT, many professors these days allow students to use the online forums like an "Open Book", so please state in your inquiry that your need is education related but the prof is OK with consulting from the forum. Just be certain that your solution is vetted by you/team and that you all understand the results. Also, not all answers provided in the forum is correct ... yes, you can get wrong answers here!

Copy & Paste is a way of life. Try and make an effort to understand what you are doing, however. Just like surgery on a human being, just having the right number of parts stitched together may create Frankenstein's Monster and not that cute little project you are building for your kids.

Arduino's scope is significantly wider these days than in the beginning; so, be understanding when you are asking questions about Arduino and HTML programming ... not everyone is up on the integration required of the IoT technologies. Said another way, do not expect to complete a project based solely on forum input, it will not happen.

You must help the forum answer your question(s). Describe your project, source of any framework code, and expectations. Articulate as best you can what you are trying to achieve and what is not working as you expect. Do not write a novel.

Summary: as a newbie with Arduino, your climb is uphill. It is suggested that you read through and familiarize yourself with the Arduino Reference section under the "Learning" drop-down. It is requirement that you work through a few of the Tutorials. All in all, about a day's work on your part will make your entrance into Arduino a much smoother ride.

There are lots of good online resources. Just a few:
https://www.arduino.cc/en/Tutorial/HomePage

https://learn.adafruit.com/category/learn-arduino

https://learn.sparkfun.com/tutorials/what-is-an-arduino

Ray

REAL C++ programmers do not use Arduino.

That seems a bit harsh. I've taught and used C++ for almost two decades and am doing quite a bit of Arduino coding since I retired. I do think it is possible to simply learn C and enjoy working with the Arduino family. Many compatibles (e.g., Teensy 3.6) have enough horsepower to do some significant things. As to C++, I think it helps to know it since most of the supporting Arduino libraries are written in C++. Also, knowing the basics of OOP can help you to write better C code, too.

econjack:
That seems a bit harsh.

Ah, if one is truly wanting to do C++ and cool things, there are off in the microcomputer camp and not the microcontroller... I'm beyond amazed what the microcontrollers such as the ESP8266 can do, but while fun to play with, they are not true computers... not toys, but something that is a stepping stone to something that is yet to be developed.

Is that not the way these little bits of sand go? The architects will only stop when Moore's Law ceases to function. Then they take little grains of sand and pile them on top of larger grains of sand and off we go again!

Arduino is a good hobby platform. I'm retired and my hobby needs are fulfilled by the 32-bit devices such as STM32 and ESP32'ish and that difficult to corner technology from Cypress called PSoC (fun but I hate the IDE.)

The OrangePi, r-Pi and those boards are far more interesting than any Arduino, IMO. But, I still play around with the 8-bitters from time to time. Again, I'm retired, so I have the time to pull out the Saleae and the Rigol and piddle around with I2C or SPI and such.... but, I rarely really carry a project beyond the lab - the exception being the GPS+ESP8266 (Tardis Time) which is now the UDP transmitter for numerous digital clocks all through the house.

afterthought ...

As to C++, I think it helps to know it since most of the supporting Arduino libraries are written in C++. Also, knowing the basics of OOP can help you to write better C code, too.

Absolutely...
But most newbies to Arduino are not writing libraries! (Thank goodness.) Personally, while libraries were are the blood that fuel the Arduino, IMO, they are also the bain of many beginners.
Long ago I started encapsulating 3rd party libraries into my sketch folder and I felt empowered to "fix" many of these darn things to my liking! Since they are now encapsulated, I can optimize each for the sketch I am working on at the time. Screw "reuse" ... it is a term way overused!

Ray

mrburnette:
Ah, if one is truly wanting to do C++ and cool things, there are off in the microcomputer camp and not the microcontroller... I'm beyond amazed what the microcontrollers such as the ESP8266 can do, but while fun to play with, they are not true computers... not toys, but something that is a stepping stone to something that is yet to be developed.

Agreed, yet "cool things" are in the eye of the beholder and the tasks to be done. My hobby is amateur radio and the computing demands for useful add-ons is not very demanding. Also, more and more people are taking portable equipment to mountain tops (e.g., Summits On The Air) or islands (Islands On The Air) and the add-ons must be fairly small and light weight and a laptop is too heavy. Building an electronic Morse code keyers, antenna analyzers, software defined radios can be nicely done with a simple microcontroller and I find it kinda "cool".

Building an electronic Morse code keyers, antenna analyzers, software defined radios can be nicely done with a simple microcontroller and I find it kinda "cool".

:grinning:

Ray