Arduino code sources?

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

Reply to
Terry Pinnell
Loading thread data ...

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.

--
This message may be freely reproduced without limit or charge only via  
the Usenet protocol. Reproduction in whole or part through other  
 Click to see the full signature
Reply to
Cursitor Doom

sure if you just want to program AVR mcus

not if you want to use Arduino sketches in the Arduino IDE most of that is a subset of C++

Reply to
Lasse Langwadt Christensen

I know the compiler is C++, but all the code everyone was writing seemed to be simply C.

--
 Thanks, 
    - Win
Reply to
Winfield Hill

I played with an arduino years ago... (with my son.) But I don't know much... you might try asking at the stack exchange

formatting link

George H.

Reply to
George Herold

Which is a real shame considering the avr-gcc compiler is fully C++11 standard compliant (you don't get most of the niceties or templates of the STL, though) but you almost never see people doing "real" C++, which the Arduino environment compiles just fine:

template class MyCompressionPolicy {}

//partial specialization for uint16_t

template class MyCompressionPolicy {} public: static const uint8_t* compress(const InputType& input_data) { // data compression logic etc. return compressed_data_buf_; }

private: static uint8_t compressed_data_buf_[BufSize] = new uint8_t[BufSize]; };

//further specializations follow ... ... //

//"typedef" but able to be template-ted

template using compressor_128_policy_t = MyCompressionPolicy;

//serial port wrapper with user-defined data compression policy

template class SerialWrapper { public: SerialWrapper(const InterfaceType& interface, const char* port, uint32_t baud) : interface_(&interface) { interface_->setup(port, baud); }

~SerialWrapper() { if (interface_) { interface_->flush(); interface_->close(); } }

// hardware interface wrappers can't be copied

SerialWrapper(const SerialWrapper&) = delete; SerialWrapper& operator=(const SerialWrapper) = delete; SerialWrapper(SerialWrapper&&) = default; SerialWrapper& operator=(SerialWrapper&&) = default;

//compress data on the fly during the write out using the user-defined //compression policy plug-in

template bool write(const InputType& data) { enum { WRITE_FAIL, WRITE_SUCCESS }; if (!interface_) return WRITE_FAIL;

auto result = interface_->write(DataCompressionPolicy::compress(data)); return result ? WRITE_SUCCESS : WRITE_FAIL; }

private: InterfaceType* interface_ = nullptr; };

Reply to
bitrex

whoops change that ;)

Reply to
bitrex

but many of the libraries are c++

Reply to
Lasse Langwadt Christensen

Best place to start looking is the library search function from the IDE itself, Sketch -> Include Libraries -> Manage Libraries or control + shift + I.

From there you can search for libraries covering a lot of common embedded hardware devices and software tasks. Most will have links to a repository of the source code for how they're implemented (some are more complicated than others.)

Reply to
bitrex

The repos for most libraries will also contain example code to show how they should be used in practice.

Reply to
bitrex

Thanks, I'll start there.

Terry, East Grinstead, UK

Reply to
Terry Pinnell

You may want to start here:

formatting link

Here is another place that shows how to hook up many of the sensors.

formatting link
Arduino.html

There are lots of people on youtube that have done many things with the Arduino. I have been playing with them for about 2 years. The language is simple, but I am not a programmer. I do it like I do the game of chess. I know how each piece moves on the board, but playing someone that has a basic understanding of the game will beat me in a very short time. I can make simple changes to other's programs but that is it.

Reply to
Ralph Mowery

I don't know much about the Arduino environment, but their boards are handy for working with the AVR 8-bit chips. If you are climbing the learning curves for both C/C++ and embedded development at the same time, you have some challenging work ahead.

C++ is a moving target, especially these days. Many people who learned it

20 years ago would barely recognize the C++ code now being written under the "Modern C++" rubric. Fortunately it's still true that you only need to use the C++ features you want to use, along with the converse (you only want to use the features you actually need.)

The advice to start with K&R C is OK as far as it goes, but it's akin to telling an electronics novice to start with vacuum tubes. I have to believe that there are better tutorials by now that start you out with a good C++ foundation. It is safe to say the best C++ tutorials will not be found on Arduino sites, but on desktop platforms. If you run Windows, look for some introductory lessons with the "community edition" of MS Visual Studio. There will be tons. If you run Linux or a related OS you will want to start with tutorials that use GCC.

One advantage there is that the Arduino toolchain that you will be working with is GCC-based, so if you become familiar with GCC early on, those lessons will apply at more than just the core language level. Arduino itself won't expose you directly to GCC, but you will eventually leave that particular nest.

-- john, KE5FX

Reply to
John Miles, KE5FX

There are heaps of sites around courtesy of mr google :-) Try as a starter.

Reply to
Rheilly Phoull

Here's a very place to start. Start at Lesson 1:

formatting link

Reply to
sdy

On a sunny day (Fri, 31 May 2019 17:02:54 -0700 (PDT)) it happened "John Miles, KE5FX" wrote in :

That is complete bullox The Cplushplush I have seen for 'duinos is total insane. Cplushplush is a crime against humanity.

Learning it is going back to the stone age making stone tools. I do not use 'duinos and never will, just because of that Cplushplush.

For a bit more you have a Raspberry Pi with Linux and gcc and can program in C or any other language, For single tasking computing stuff I use PICs, programmed in asm. PICs with PIC asm is much easier and more logical than Cplushplush, faster, and takes less space. Cplushplush is a crime against humanity.

I once needed a driver for some chip, 'duino had one in Cplushplush that consisted of 3 source files IIRC. I rewrote it in C in less than 40 lines,., and run it on a Raspberry.

The basic flaw with that seeplushplush is that it claims to look at things from on 'object oriented' POV.

Unfortunately for those users computers just are sequential operating machines. So their brains get damaged doing the silly switch from reality all the time. And all that Cplushplush syntax is way to much typing work. It is about as stupid as programming in Linux as non-root and using sudo at the start of any instructions. Cpluplush is unreadable crap and should be forbidden by law and those that still use it banned to a deserted island on an other planet in an other solar system in an other galaxy in an other universe ruled by string theory.

I Have Spoken.

Reply to
Jan Panteltje

It's a language for writing code that is extensible/modifiable/understandable by other people than oneself, which is a requirement for most real-world development projects.

Reply to
bitrex

On a sunny day (Sat, 1 Jun 2019 01:11:55 -0400) it happened bitrex wrote in :

No it is not, it is a crime against humanity. there is a REASON why Linus has forbidden the use of seeplushplush in the kernel.

Teaching people to understand reality from the wrong POV is leading to bloated crap for software. Qt, MS widows... the list is probably endless.

There is this other thread, about what was it 'counter intuitive something', and somebody pointed to (oh yes gravity) 'gravitons'. OK, but that comes - or is related to string theory. Last night I was making spaghetti, and once cooked you can bend those strings in any form you like well and then I just realized this morning that that is what string theory IS. Some mathemagician looked at spaghetti and realized that with those strings you can make any form you want, even 'branes' (not brains).. repeat last sentence many times over.,. Anyways, I have an other model that actually does predict and explain observed phenomena, unlike string theory that fold any way you like... Anyways, as long as you can get away with that string^H^H^H^H^H^H plushplush stuff is like getting away with some crime against humanity, just do not do it to kids that are learning! Else the world will be one worse. Explain to them how a processor works, and then teach them asm, hey I started coding in binary, and then move on to some higher language (maybe BASIC) and C as an interface to the hardware. Many object(ional) oriented languages came, and went again, large IT projects failed, it is big business to sell bloated un-understandable crap. That is one problem with the capitalist system. But do not do it to newcomers in computing!

Reply to
Jan Panteltje

If someone is just getting started, it amounts to pedagogic malpractice to tell them to learn anything else. The world still runs on C, and someone who has learned C++ will be equipped to write better code than someone who has not even if they never use 99% of the language. The only question is where they should be looking for lessons.

Probably not here, would be my guess.

It's just another AVR board, irrespective of your personal prejudices. If you have an 8-bit nail to pound, Arduinos make a good 8-bit hammer. You can program them in C, or Forth, or Brainfuck if that's your thing.

-- john, KE5FX

Reply to
John Miles, KE5FX

What you gain on the swings you lose on the roundabouts.

While I am certainly no fan of C++ (e.g. see the C++ FQA), one advantage of the Arduino class machines is that you are programming against bare silicon.

Having an operating system in a hard real-time system can be a real impediment and a steep learning curve.

Reply to
Tom Gardner

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.