Arduino programming?

Advert

Arduino programming?

Home Forums General Questions Arduino programming?

Viewing 25 posts - 1 through 25 (of 46 total)
  • Author
    Posts
  • #27782
    Malc
    Participant
      @malc
      Advert
      #509232
      Malc
      Participant
        @malc

        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??

        #509239
        SillyOldDuffer
        Moderator
          @sillyoldduffer

          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

          #509245
          Ady1
          Participant
            @ady1

            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

            #509249
            Malc
            Participant
              @malc

              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.

              #509250
              Nick Clarke 3
              Participant
                @nickclarke3
                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.

                #509251
                Nick Clarke 3
                Participant
                  @nickclarke3
                  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

                  #509258
                  Bazyle
                  Participant
                    @bazyle

                    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

                    #509262
                    Malc
                    Participant
                      @malc

                      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.

                      #509274
                      duncan webster 1
                      Participant
                        @duncanwebster1

                        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.

                        #509279
                        Martin Kyte
                        Participant
                          @martinkyte99762

                          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

                          #509282
                          Malc
                          Participant
                            @malc

                            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.

                            #509285
                            Andy Stopford
                            Participant
                              @andystopford50521

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

                              The C++ Tutorial

                              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.

                              #509299
                              Malc
                              Participant
                                @malc

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

                                #509316
                                Jon Lawes
                                Participant
                                  @jonlawes51698

                                  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.

                                  #509322
                                  Roger Hart
                                  Participant
                                    @rogerhart88496

                                    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.

                                    #509325
                                    Peter Bell
                                    Participant
                                      @peterbell11509

                                      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

                                      #509337
                                      Derek cottiss
                                      Participant
                                        @derekcottiss41883

                                        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

                                        #509371
                                        Malc
                                        Participant
                                          @malc

                                          Actually Roger it is a display that started this recent flurry of programming. I had made a project using a larger 4×7 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!

                                          #509612
                                          Jon Lawes
                                          Participant
                                            @jonlawes51698

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

                                            #509636
                                            Malc
                                            Participant
                                              @malc

                                              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!

                                              #510039
                                              Malc
                                              Participant
                                                @malc

                                                Since my last post on this subject I have had some success with the programming. I have now got the sketch to light all the 4×7 segments in turn and their decimal points. The only trouble is that the sketch is over 200 lines long and I'm sure that there must be a better way of doing this. I have been trying to use arrays to group the "digital write" lines into 0, 1, 2, etc arrays to replace these lines and so shorten the sketch. Am I on the right lines? I will try to post he code here. I think the Arduino forum have grown a little impatient with me so I would be grateful for any suggestions. NB. It seems the post is too long so I will post the sketch in another post.

                                                #510040
                                                Malc
                                                Participant
                                                  @malc

                                                  Code part 1

                                                  // tests a 4×7 seg. disp. with modified blink sketch. displays 0000 1111 2222 3333 etc. with decimal points after all digits.

                                                  #define seg //output pins to 7 segment display
                                                  #define Don 1000 //delay setting the ON time of segments
                                                  #define Doff 250 //delay setting the OFF time of segments

                                                  void setup() {
                                                  // put your setup code here, to run once:
                                                  pinMode(2, OUTPUT); // A segment of display
                                                  pinMode(3, OUTPUT); // B segment of display
                                                  pinMode(4, OUTPUT); // C segment of display
                                                  pinMode(5, OUTPUT); // D segment of display
                                                  pinMode(6, OUTPUT); // E segment of display
                                                  pinMode(7, OUTPUT); // F segment of display
                                                  pinMode(8, OUTPUT); // G segment of display
                                                  pinMode(9, OUTPUT); // Decimal Point segment of display
                                                  pinMode(10, OUTPUT); // D1 cathode of display
                                                  pinMode(11, OUTPUT); // D2 cathode of display
                                                  pinMode(12, OUTPUT); // D3 cathode of display
                                                  pinMode(13, OUTPUT); // D4 cathode of display
                                                  }

                                                  void loop()

                                                  {

                                                  digitalWrite(2, HIGH); // turn the following LEDs (segments) on to display the number 0.
                                                  digitalWrite(3, HIGH);
                                                  digitalWrite(4, HIGH);
                                                  digitalWrite(5, HIGH);
                                                  digitalWrite(6, HIGH);
                                                  digitalWrite(7, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second.

                                                  digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                  digitalWrite(3, LOW);
                                                  digitalWrite(4, LOW);
                                                  digitalWrite(5, LOW);
                                                  digitalWrite(6, LOW);
                                                  digitalWrite(7, LOW);
                                                  digitalWrite(9, LOW);

                                                  //delay(Doff); // wait for a second.

                                                  digitalWrite(3, HIGH); // turn the following LEDs (segnments)on to display the number 1.
                                                  digitalWrite(4, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second

                                                  digitalWrite(3, LOW); //turn the following LEDs (segments)off.
                                                  digitalWrite(4, LOW);
                                                  digitalWrite(9, LOW);

                                                  // delay(Doff); // wait for a second

                                                  digitalWrite(2, HIGH); // turn the following LEDs (segnments)on to display the number 2.
                                                  digitalWrite(3, HIGH);
                                                  digitalWrite(5, HIGH);
                                                  digitalWrite(6, HIGH);
                                                  digitalWrite(8, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second

                                                  digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                  digitalWrite(3, LOW);
                                                  digitalWrite(5, LOW);
                                                  digitalWrite(6, LOW);
                                                  digitalWrite(8, LOW);
                                                  digitalWrite(9, LOW);

                                                  //delay(Doff); // wait for a second

                                                  digitalWrite(2, HIGH); // turn the following LEDs (segnments)on to display the number 3.
                                                  digitalWrite(3, HIGH);
                                                  digitalWrite(4, HIGH);
                                                  digitalWrite(5, HIGH);
                                                  digitalWrite(8, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second

                                                  digitalWrite(2,LOW); //turn the following LEDs (segments)off.
                                                  digitalWrite(3, LOW);
                                                  digitalWrite(4, LOW);
                                                  digitalWrite(5, LOW);
                                                  digitalWrite(8, LOW);
                                                  digitalWrite(9, LOW);

                                                  //delay(Doff); // wait for a second

                                                  digitalWrite(3, HIGH); // turn the following LEDs (segnments)on to display the number 4.
                                                  digitalWrite(4, HIGH);
                                                  digitalWrite(7, HIGH);
                                                  digitalWrite(8, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second

                                                  digitalWrite(3,LOW); //turn the following LEDs (segments)off.
                                                  digitalWrite(4, LOW);
                                                  digitalWrite(7, LOW);
                                                  digitalWrite(8, LOW);
                                                  digitalWrite(9, LOW);

                                                  // delay(Doff); // wait for a second

                                                  digitalWrite(2, HIGH); // turn the following LEDs (segnments)on to display the number 5.
                                                  digitalWrite(4, HIGH);
                                                  digitalWrite(5, HIGH);
                                                  digitalWrite(7, HIGH);
                                                  digitalWrite(8, HIGH);
                                                  digitalWrite(9, HIGH);

                                                  delay(Don); // wait for a second

                                                  #510041
                                                  Malc
                                                  Participant
                                                    @malc

                                                    code part 2

                                                    delay(Don); // wait for a second

                                                    digitalWrite(2,LOW); //turn the following LEDs (segments)off.
                                                    digitalWrite(4, LOW);
                                                    digitalWrite(5, LOW);
                                                    digitalWrite(7, LOW);
                                                    digitalWrite(8, LOW);
                                                    digitalWrite(9, LOW);

                                                    //delay(Doff); // wait for a second

                                                    digitalWrite(2, HIGH); // turn the following LEDs (segments) on to display the number 6.
                                                    digitalWrite(4, HIGH);
                                                    digitalWrite(5, HIGH);
                                                    digitalWrite(6, HIGH);
                                                    digitalWrite(7, HIGH);
                                                    digitalWrite(8, HIGH);
                                                    digitalWrite(9, HIGH);

                                                    delay(Don); // wait for a second

                                                    digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                    digitalWrite(4, LOW);
                                                    digitalWrite(5, LOW);
                                                    digitalWrite(6, LOW);
                                                    digitalWrite(7, LOW);
                                                    digitalWrite(8, LOW);
                                                    digitalWrite(9, LOW);

                                                    //delay(Doff); // wait for a second

                                                    digitalWrite(2, HIGH); // turn the following LEDs (segments) on to display the number 7.
                                                    digitalWrite(3, HIGH);
                                                    digitalWrite(4, HIGH);
                                                    digitalWrite(9, HIGH);

                                                    delay(Don); // wait for a second

                                                    digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                    digitalWrite(3, LOW);
                                                    digitalWrite(4, LOW);
                                                    digitalWrite(9, LOW);

                                                    //delay(Doff); // wait for a second

                                                    digitalWrite(2, HIGH); // turn the following LEDs (segments) on to display the number 8.
                                                    digitalWrite(3, HIGH);
                                                    digitalWrite(4, HIGH);
                                                    digitalWrite(5, HIGH);
                                                    digitalWrite(6, HIGH);
                                                    digitalWrite(7, HIGH);
                                                    digitalWrite(8, HIGH);
                                                    digitalWrite(9, HIGH);

                                                    delay(Don); // wait for a second

                                                    digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                    digitalWrite(3, LOW);
                                                    digitalWrite(4, LOW);
                                                    digitalWrite(5, LOW);
                                                    digitalWrite(6, LOW);
                                                    digitalWrite(7, LOW);
                                                    digitalWrite(8, LOW);
                                                    digitalWrite(9, LOW);

                                                    //delay(Doff); // wait for a second

                                                    digitalWrite(2, HIGH); // turn the following LEDs (segments) on to display the number 9.
                                                    digitalWrite(3, HIGH);
                                                    digitalWrite(4, HIGH);
                                                    digitalWrite(5, HIGH);
                                                    digitalWrite(7, HIGH);
                                                    digitalWrite(8, HIGH);
                                                    digitalWrite(9, HIGH);

                                                    delay(Don); // wait for a second

                                                    digitalWrite(2, LOW); //turn the following LEDs (segments)off.
                                                    digitalWrite(3, LOW);
                                                    digitalWrite(4, LOW);
                                                    digitalWrite(5, LOW);
                                                    digitalWrite(7, LOW);
                                                    digitalWrite(8, LOW);
                                                    digitalWrite(9, LOW);

                                                    //delay(Doff); // wait for a second

                                                    }

                                                    #510043
                                                    Frances IoM
                                                    Participant
                                                      @francesiom58905

                                                      whenever some 40yrs ago I saw code like that I would immediately look at what I then called table driven code – ie a specialised interpreter + a highly compact bit oriented tables

                                                      Edited By Frances IoM on 26/11/2020 17:43:19

                                                    Viewing 25 posts - 1 through 25 (of 46 total)
                                                    • Please log in to reply to this topic. Registering is free and easy using the links on the menu at the top of this page.

                                                    Advert

                                                    Latest Replies

                                                    Home Forums General Questions Topics

                                                    Viewing 25 topics - 1 through 25 (of 25 total)
                                                    Viewing 25 topics - 1 through 25 (of 25 total)

                                                    View full reply list.

                                                    Advert

                                                    Newsletter Sign-up