Reply by Peter Percival June 13, 20192019-06-13
Phil Hobbs wrote:
> On 6/12/19 8:41 AM, Peter Percival wrote: >> Cursitor Doom wrote: >>> On Fri, 31 May 2019 11:48:07 +0100, Terry Pinnell wrote: >>> >>>> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super >>>> Starter kit) and am stepping through its tutorials. In parallel I'm >>>> trying to learn the basics of its C++ based programming language, but >>>> that's proving a struggle. >>> >>> I wouldn't even bother with C++ in this instance. Get yourself a copy of >>> Kernighan & Ritchie's the C Programming Language - the best book ever >>> written on C. > > Agreed.&nbsp; My son taught himself C out of K&R just a few years back, and > liked it very well. > >> >> And Harbison and Steele as number two. >> >> > > H&S was an excellent book, and I used it for several years.&nbsp; However, > time has moved on, and the old-time C libraries are showing their age. I > still used <cstdio>, but stuff like strdup() and realloc()?&nbsp; Really? > > Cheers > > Phil Hobbs >
I confess, I haven't programmed in anger for thirteen years or more, so anything I say is probably well out of date! -- "He who will not reason is a bigot; he who cannot is a fool; he who dares not is a slave." - Sir William Drummond
Reply by Phil Hobbs June 12, 20192019-06-12
On 6/12/19 8:41 AM, Peter Percival wrote:
> Cursitor Doom wrote: >> On Fri, 31 May 2019 11:48:07 +0100, Terry Pinnell wrote: >> >>> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super >>> Starter kit) and am stepping through its tutorials. In parallel I'm >>> trying to learn the basics of its C++ based programming language, but >>> that's proving a struggle. >> >> I wouldn't even bother with C++ in this instance. Get yourself a copy of >> Kernighan & Ritchie's the C Programming Language - the best book ever >> written on C.
Agreed. My son taught himself C out of K&R just a few years back, and liked it very well.
> > And Harbison and Steele as number two. > >
H&S was an excellent book, and I used it for several years. However, time has moved on, and the old-time C libraries are showing their age. I still used <cstdio>, but stuff like strdup() and realloc()? Really? Cheers Phil Hobbs -- Dr Philip C D Hobbs Principal Consultant ElectroOptical Innovations LLC / Hobbs ElectroOptics Optics, Electro-optics, Photonics, Analog Electronics Briarcliff Manor NY 10510 http://electrooptical.net http://hobbs-eo.com
Reply by Peter Percival June 12, 20192019-06-12
Cursitor Doom wrote:
> On Fri, 31 May 2019 11:48:07 +0100, Terry Pinnell wrote: > >> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super >> Starter kit) and am stepping through its tutorials. In parallel I'm >> trying to learn the basics of its C++ based programming language, but >> that's proving a struggle. > > I wouldn't even bother with C++ in this instance. Get yourself a copy of > Kernighan & Ritchie's the C Programming Language - the best book ever > written on C.
And Harbison and Steele as number two. -- "He who will not reason is a bigot; he who cannot is a fool; he who dares not is a slave." - Sir William Drummond
Reply by bitrex June 3, 20192019-06-03
On 6/2/19 11:08 PM, bitrex wrote:
> On 5/31/19 6:48 AM, Terry Pinnell wrote: >> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super >> Starter kit) >> and am stepping through its tutorials. In parallel I'm trying to learn >> the basics of >> its C++ based programming language, but that's proving a struggle. I'm >> impatient to >> use Arduino on my own projects so I will take a 'copy/paste/edit' >> approach. It then >> becomes a matter of finding sketches that cover a particular subject >> and then >> tailoring. >> >> I'd therefore appreciate recommendations on Arduino sketch sources >> that others have >> found useful please. >> >> Terry, East Grinstead, UK >>
<snip> BTW the purpose of the mini-rant isn't to be super-useful advice to a total beginner, but I think it's worth thinking about when beginning any endeavor to consider "where do I want to be in two years time." I think it's worth thinking about how "real code" is written in the 21st century, or should be, and ideally things will go well and one won't want to stay in the sandbox forever. A lot of Arduino-environment code is bad. but the tools are available so it doesn't have to be that way, so I think it's worth thinking about how to be at a place where one is writing _good_ code in two years time simultaneously, code that can earn money, and not just rote-learning the syntax. and I think that also means learning a bit about software _engineering_ practices simultaneously and not just code-writing.
> An advantage of C++ is you can write code to define rule-enforcing data > structures like that to, by design, self-enforce safer further design > decisions. Along the same lines raw data types like "int" should never > be used and passed around to represent something like dollars in a bank > account, or velocity. They should be wrapped in an object that enforces > assumptions like class Dollars, or class Velocity. A function that > computes an output velocity from an input velocity should return a > Velocity and take a Velocity argument e.g. Velocity > calc_new_velocity(Velocity v) not int calc_new_velocity(int v). > > And no, this almost never "bloats the code" if done intelligently the > compiler and optimizer will figure out that in almost all cases it can > compute a velocity under the hood by just manipulating the raw ints like > it would when compiling C. all the boilerplate is mostly for your > benefit so it can warn you if you try to do something stupid.
Reply by bitrex June 3, 20192019-06-03
On 5/31/19 6:48 AM, Terry Pinnell wrote:
> I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super Starter kit) > and am stepping through its tutorials. In parallel I'm trying to learn the basics of > its C++ based programming language, but that's proving a struggle. I'm impatient to > use Arduino on my own projects so I will take a 'copy/paste/edit' approach. It then > becomes a matter of finding sketches that cover a particular subject and then > tailoring. > > I'd therefore appreciate recommendations on Arduino sketch sources that others have > found useful please. > > Terry, East Grinstead, UK >
A "modern C++" feature that would be very helpful for uP based projects is a smart pointer. You can't really do dynamic memory allocation/de-allocation at will on a processor with 2k of RAM. But you still often need to hold and transfer resources around. What's a pointer? A pointer holds the address of a _resource_. The ownership status of a resource must always be well-defined. A "unique pointer" object defines ownership of a resource - the object that holds that unique pointer object, which wraps a dumb pointer, "owns" that resource. Unique pointers cant be copied, only moved. If an object holds a unique pointer it cannot be copied, either, or else two owners would exist. Nuh uh. Sometimes other code needs to hold a reference to a resource. Some logic would like to see what a data buffer contains, but shouldn't "own" the buffer. So there can be an "observer pointer". It can only be used for read-only access to the resource but cannot modify the actual resource's state in any way. The observer container can be both copied and moved. They can be passed to functions, even plain-C functions, taking a const-qualified raw pointer seamlessly but cannot be passed to functions taking a non-const qualified pointer as that would allow write access to the resource. An advantage of C++ is you can write code to define rule-enforcing data structures like that to, by design, self-enforce safer further design decisions. Along the same lines raw data types like "int" should never be used and passed around to represent something like dollars in a bank account, or velocity. They should be wrapped in an object that enforces assumptions like class Dollars, or class Velocity. A function that computes an output velocity from an input velocity should return a Velocity and take a Velocity argument e.g. Velocity calc_new_velocity(Velocity v) not int calc_new_velocity(int v). And no, this almost never "bloats the code" if done intelligently the compiler and optimizer will figure out that in almost all cases it can compute a velocity under the hood by just manipulating the raw ints like it would when compiling C. all the boilerplate is mostly for your benefit so it can warn you if you try to do something stupid.
Reply by Ralph Mowery June 1, 20192019-06-01
In article <m3k4fehhjs1tmpfastpovp5ph515ecfvdo@4ax.com>, 
me@somewhere.invalid says...
> > My current sources apart from tutorial projects are the obvious Google Search, the > Arduino Forum, and the Embedded Systems and Micro controllers section of the All > About Circuits Forum. > > >
I found this most helpful. It is a list of the commands and short explination. Near the end there are some short examples of the commands. https://archive.org/details/arduino_notebook
Reply by Terry Pinnell June 1, 20192019-06-01
"Rodney Pont" <mlist4@infohit.me.uk> wrote:

>On Fri, 31 May 2019 11:48:07 +0100, Terry Pinnell wrote: > >>I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super Starter kit) >>and am stepping through its tutorials. In parallel I'm trying to learn the basics of >>its C++ based programming language, but that's proving a struggle. I'm impatient to >>use Arduino on my own projects so I will take a 'copy/paste/edit' approach. It then >>becomes a matter of finding sketches that cover a particular subject and then >>tailoring. >> >>I'd therefore appreciate recommendations on Arduino sketch sources that others have >>found useful please. > >I found books easier to get on with than on screen things
Me too.
>but I'm an oldie
Me too.
>and a long term programmer.
Not me. I'm currently ploughing through Simon Monk's 'Programming Arduino, 2nd Edition'. Quite readable up to his first complex example, flashing Morse code to the LED from the serial monitor), mainly because of its use of arrays within arrays ;-(
> >Arduino for Dummies is good for getting used to Arduino with worked >examples.
Went straight to your next recommendation as I hope Monk's book and the online tutorials I'm studying will get me to a stage I can benefit from the Margolis.
>Arduino Cookbook published by O'Reilly is also very good and goes into >programming techniques such as loops, decision structures and variable >types.
Looks good, although pretty expensive at &#4294967295;24 (~ $30), but have just ordered.
>I presume those would be useful to a started in programming. It >states the problem (such as You want to send text and data from your >Arduino to your pc) and then shows a solution.
Thanks, appreciated. Terry, East Grinstead, UK
Reply by Terry Pinnell June 1, 20192019-06-01
Tom Gardner <spamjunk@blueyonder.co.uk> wrote:

>On 01/06/19 11:45, Terry Pinnell wrote: >> Unless there's a superbly indexed site I haven't yet found, perhaps that's enough. > >There is such a site, with wonderful indexes. It is >called google, and knowing how to use it effectively >is a key modern skill. > >It isn't difficult; my 10yo quickly mastered it >sufficiently that she demolished my arguments about >why we shouldn't get chickens. Made me proud, and >glad to get them.
That's why it was the first of the three I listed. Terry Pinnell, East Grinstead, UK
Reply by Rodney Pont June 1, 20192019-06-01
On Fri, 31 May 2019 11:48:07 +0100, Terry Pinnell wrote:

>I bought my first Arduino UNO R3 kit two weeks ago (the Elegoo Super Starter kit) >and am stepping through its tutorials. In parallel I'm trying to learn the basics of >its C++ based programming language, but that's proving a struggle. I'm impatient to >use Arduino on my own projects so I will take a 'copy/paste/edit' approach. It then >becomes a matter of finding sketches that cover a particular subject and then >tailoring. > >I'd therefore appreciate recommendations on Arduino sketch sources that others have >found useful please.
I found books easier to get on with than on screen things but I'm an oldie and a long term programmer. Arduino for Dummies is good for getting used to Arduino with worked examples. Arduino Cookbook published by O'Reilly is also very good and goes into programming techniques such as loops, decision structures and variable types. I presume those would be useful to a started in programming. It states the problem (such as You want to send text and data from your Arduino to your pc) and then shows a solution. -- Regards - Rodney Pont The from address exists but is mostly dumped, please send any emails to the address below e-mail rpont (at) gmail (dot) com
Reply by Tom Gardner June 1, 20192019-06-01
On 01/06/19 11:45, Terry Pinnell wrote:
> Unless there's a superbly indexed site I haven't yet found, perhaps that's enough.
There is such a site, with wonderful indexes. It is called google, and knowing how to use it effectively is a key modern skill. It isn't difficult; my 10yo quickly mastered it sufficiently that she demolished my arguments about why we shouldn't get chickens. Made me proud, and glad to get them.