By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Forum House Ad Zone

Arduino programming?

All Topics | Latest Posts

Search for:  in Thread Title in  
Malc22/11/2020 17:10:50
113 forum posts
6 photos

For some time now I have been tinkering with the Arduino and have made a couple useable items. However, the stumbling block is always the programming. Up to now I have used sketches found on line or in books etc., but If I want to depart from the copied sketch I come unstuck! I have bought a couple of books which have helped but my poor old brain just doesn't seem to handle Arduino code. I know some of you fellows use the Arduino so I wondered whether you had a recommended system of learning the coding, perhaps you have a background in computer programming in a past life? Is it that difficult to master, or am I just a bit thick??

SillyOldDuffer22/11/2020 17:45:24
10668 forum posts
2415 photos

Having an employer who sends you on expensive courses and provides a senior programmer as mentor certainly helps. So does being paid despite mistakes and having access to a full set of manuals and support services!

However, I suggest you're on the right track. Take code from books, magazines and the internet, try to understand it, and experiment.

Start simple and work up. It takes time to learn idioms and techniques, so don't expect to go from flashing an LED to programming a quadcopter quickly. Work through the examples that come with the Arduino IDE.

Arduino's are programmed in 'C', actually C++, which are both languages with hidden depths. Powerful rather than friendly, so don't assume lack of brain is the problem. Although Arduino hides most of the really hard stuff, its still a steepish learning curve, with plenty of opportunity for bafflement. I wrote my first C program in 1979 and wrote my last professional program in C++ circa 1996. Kept my hand in out of interest ever since and am still learning. C++ is interesting because it both simplifies and over-complicates in my opinion. One minute splashing happily in the kiddie pool, next minute deep cold water and a whirlpool with no sign of rescue,

If you get stuck ask on a forum. Obviously best answers from the Arduino forums and Stack Exchange, but this one does well too on the sort of microcontroller stuff model engineers get stuck on.

Practice, practice, practice, patience, persist. My favourite book on programming suggests new projects should always be started by taking the day off. It works!

Dave

Ady122/11/2020 18:19:37
avatar
6137 forum posts
893 photos

Since 1980 I have only ever come across a single decent learning tool, it was called the Ketman Interpreter and it was for assembly language

The rest of it has always been suck-it-and-see with examples until one day the penny drops

99% of people who are good at programming are rubbish at teaching, the two subjects just seem to be mutually exclusive disciplines that require a different sort of brain to be any good at

Perhaps one subject favours the isolated loner while the other favours the socially empathic?

Coding forums can be pretty horrible places where newcomers are barely tolerated and some of the arguments over irrelevant minutiae can be an eye popping cage fight to the death, it's Lord of the flies with religious mathematicians

So you really have to figure out what works best for you, I'm afraid

Malc22/11/2020 18:43:12
113 forum posts
6 photos

I have had some help on the coding forums but I have also had a few rebukes for not being a genius! Certainly don’t feel as “at home” as I do on here. Thanks for the replies, makes me feel less thick if nothing else.

Nick Clarke 322/11/2020 18:46:31
avatar
1607 forum posts
69 photos
Posted by Malc on 22/11/2020 17:10:50:

I know some of you fellows use the Arduino so I wondered whether you had a recommended system of learning the coding, perhaps you have a background in computer programming in a past life? Is it that difficult to master, or am I just a bit thick??

C and C++ are very terse languages and can be difficult to read - in fact a colleague once said that if you can read and understand uncommented C code a year after you wrote it you are not really trying laugh

I have used Arduinos with secondary school age children and there are a couple of reasonable getting started guides out there, but I suspect you are likely to be already beyond those, however I think you are on the right track reusing code - it is certainly all I have time for nowadays.

Nick Clarke 322/11/2020 18:47:51
avatar
1607 forum posts
69 photos
Posted by SillyOldDuffer on 22/11/2020 17:45:24:

My favourite book on programming suggests new projects should always be started by taking the day off. It works!

Dave

Taking the day off the day after you present your project can be a career saver too! laugh

Bazyle22/11/2020 19:18:49
avatar
6956 forum posts
229 photos

Just reading or trying to take a course is seldom the best way. Too much info comes in but doesn't get used. If you can think of a very simple thing you need doing, then just work on that but starting with your own code not a copy. Gradually build up from that.

For example wire up two switches, a relay, and a LED. Use the relay to turn on a battery radio. The have the switch turn on/off the radio, then add feature to turn off after 2 hours if you didn't, attach switch to shed door so it comes on when you go in. Add another relay for lights, a daylight detector, etc until it is full cnc.

If you are already beyond the simple switch stage try a stepper motor but no cheating using someone else's code even though it is readily available.

Edited By Bazyle on 22/11/2020 19:19:30

Malc22/11/2020 19:31:59
113 forum posts
6 photos

Hi Bazyle, that’s the path I am on at the moment, though less complicated than your example. Good to know I’m going in the right direction at least.

duncan webster22/11/2020 20:30:36
5307 forum posts
83 photos

This is the book that got me going, but I did have some limited C experience to start

evil genius

It is a series of increasingly complex projects, I find the best way is to make one to the words and music, then play around with to to make it do something else

I'd offer to lend it to you, but the return postage would be nearly as much as buying it.

Martin Kyte22/11/2020 20:47:19
avatar
3445 forum posts
62 photos

I assume you started with looking at things from the Arduino end. I would suggest you start with getting a C Manual and starting there. That and looking at anything listed as an introduction to C programming online. You need to understand C first and the add the object oriented enhancement of C++ if you want to.

regards Martin

Malc22/11/2020 21:03:27
113 forum posts
6 photos

Duncan, thanks for that, I will look into that book, sounds interesting.

Martin, I did actually get an introductory book on programming C but found it too deep for me.

Andy Stopford22/11/2020 21:15:35
241 forum posts
35 photos

For a general introduction to C++, This is pretty good:

https://www.learncpp.com/

Note though that the Arduino uses a special sub-set of C++, and some things are missing, like the ability to find out the type of a variable, which is a pity because this can be a very confusing aspect of microcontroller programming.

Malc22/11/2020 22:05:54
113 forum posts
6 photos

Andy, have just had a quick look a that, very interesting, certainly worth a look. Many thanks to all for the suggestions advice etc.

Jon Lawes23/11/2020 01:43:36
avatar
1078 forum posts

I write the program I intend to make in block diagram format first, with things that are repeated often as one block that you then call on every time its needed. Then I write the blocks (translating them from plain english into Arduino) and drop them into the text.

Make good notes. If you make a line do something, write a remark next to it to tell you what it is doing it for. It will help in the debugging.

Roger Hart23/11/2020 08:27:30
157 forum posts
31 photos

Much good advice here. Start small, the diagnostic led is a very very useful tool. Crib and copy, there is almost always something close to your needs out there. The Arduino tool is very useful, learn how to use its diagnostics - the serial monitor tool lets you print stuff from inside your programme. A simple 'got to here' message will help a lot.

Slowly and by small steps move from 'what works' to something new. One pitfall is displays, they often require a library to work. I bought a cheap display only to find the standard Arduino library would not drive it. But a bit of hunting around on the web found the necessary.

Simple program fragments are your friend and good comments are also your friend.

Peter Bell23/11/2020 08:51:40
399 forum posts
167 photos

Malc, I'm in the same boat really but about 2 years in front! Thanks to help from this forum I've made good progress but original thinking on sketches is always a problem for me.

I found that "Programming Arduino" getting started with sketches and "Next Steps" both by Simon Monk were a great help but perhaps you are further on from that, they include examples to play with as well as descriptions of the sketches.

I found it useful if I could add lcd and serial prints to sketches to see what was happening but certainly plenty of Arduino around, parts and knowledge once you can manage the IDE.

Peter

Derek cottiss23/11/2020 09:45:43
36 forum posts
2 photos

i have a project that a guy was doing the coding on but has become less than reliable .I can handle the mechanical manufacture side but cant or dont (too lazy maybe) have a clue with the programing . So if anyone fancies a chalenge please get in touch

Malc23/11/2020 12:15:38
113 forum posts
6 photos

Actually Roger it is a display that started this recent flurry of programming. I had made a project using a larger 4x7 segment display and an off shoot of that was finding a sketch online for testing these displays. It didnt use a shift register and looked quite simple. To cut a long story short it worked except that it did not light up the decimal points of the display. Several of the Arduino forum fellas queried the library and I tried installing different ones and many other dodges but no luck. The opinion on the forum was that I would be better scrapping the sketch and starting afresh taking small steps and testing them out as I went - much along the lines many of you chaps have suggested. So that is what I am doing at the moment. Thanks again to all for your inputs, much appreciated!

Jon Lawes24/11/2020 15:40:37
avatar
1078 forum posts

I use the HD44780 displays, cheap to buy and you can pack a lot of info into them.

Malc24/11/2020 17:17:28
113 forum posts
6 photos

I have successfully used LCD displays in the past, but wanted a larger 7 segment display for the clock project. It’s the failing eyesight you know!

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Sign up to our Newsletter

Sign up to our newsletter and get a free digital issue.

You can unsubscribe at anytime. View our privacy policy at www.mortons.co.uk/privacy

Latest Forum Posts
Support Our Partners
cowells
Sarik
MERIDIENNE EXHIBITIONS LTD
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.

Click THIS LINK for full contact details.

For subscription issues please see THIS LINK.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest

 

Donate

donate