Announcement

Collapse
No announcement yet.

Arduino code learning

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Originally posted by kosacid View Post
    so with a lcd once it is initialised is there any delays at sending info to it, buttons are easy you can just add a delay() to them just to debounce them but i know what you mean your limited
    even with one delay my program fails, at this rate im going to using my raspberry pi lol
    Short delays are not problem. Although i am constantly trying to avoid use of the "delay()" wherever is possible.
    Joop calculated roughly the remained time:


    "...// The remaining routines are where extra processing gets done. It is critical
    // that all processing is complete before the next TCNT2 interrupt occurs, which
    // depends on the TX pulse rate, TX pulse width, and sampling time. If the pulse
    // rate = 600Hz, pulse width = 100us, and max sampling time = 35us then the
    // processing time available is 1667us - 100us - 35us = 1532us. With a 16MHz
    // clock we have an instruction cycle of 0.0625us, so there is time for 24512 code
    // instructions, including calls and returns
    ..."

    So it's a ~20 000 tics time frame, within the rest of code can be written without any fears.
    Hopefully quite enough for all the "jingle&bells" one decent PI may have.
    But there is another risk; since two timers are involved. Giving only third timer to freely play with it.
    Buttons are desirable. But polling must be done in a smart fashion. I am examining several options now.

    Comment


    • #32
      Originally posted by 6666 View Post
      Ivconic what are the polarities of the waveform pulses that you are applying to the gates of Q3 and Q4 ? is it just battery ground and plus 5 volts
      Yes. I picked Barracuda for the simplicity and because i had one spare laying in a drawer...

      Comment


      • #33
        There is a interesting idea which i saw somewhere on the Internet, about use of several buttons.
        For example; 5 buttons can be wired together in a series with resistors;

        Gnd-button1-1k resistor-button2-1k resistor-button3-1k resistor-button4-1k resistor-button5-Analogue Input.

        Press on each button will result with different value at Analogue Input. Scaled to 8-bit value still giving ~50 range for a button, quite enough to avoid any error.
        I tried that in a separate code and it is working just fine. But i done it in a loop, which is not applicable in current "Barracuda" code.
        It must be done out of loop and tied to interrupt routine. The similar fashion as it was A3 reading done.
        Current loop is usable only for outputs without returning any value.
        This is obvious example of the tradeoffs present at this kind of approach.
        Huge advantage is in using only one analogue input for 5 buttons.
        ...
        Just for illustration, here is the idea of buttons in series, i tested it and it is working correct:
        (disregard the exact values, those are dependable of resistor values and can be trimmed easily to any range width)


        Code:
        #include <Wire.h> 
        #include <LiquidCrystal_I2C.h>
        LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
        int a=0;
        oid setup()
        {
          lcd.begin(16,2);
          pinMode(A2, INPUT_PULLUP); 
        } 
         
        int readButtons(int pin)
        {
          int b,c = 0;
          c=analogRead(A2); 
          if (c>1000)
        {
            b=0; 
        }   
            else
            if (c>10 && c<20)
        {
            b=1;
        }     
            else
            if (c<100 && c>65)
        {
            b=2; 
        }       
            else
            if (c>110 && c<130)
        {
            b=3; 
        }         
            else
            if (c>160 && c<170)
        {
             b=4; 
        }           
             else
             if (c>200 && c<210)
        {
             b=5; 
        }
        return b;
        }
         
        void loop()
        {
          a=readButtons(5);
          lcd.clear();
          if (a==0) 
          {
              lcd.setCursor(0,0);
              lcd.print("Press a button");
              delay(50);
          }   
            else
            if (a>0) 
            {
              lcd.setCursor(0,1);
              lcd.print("Pressed button ");
              lcd.print(a);
            }
          delay(100); 
        }

        Comment


        • #34
          well i have a nano so ill try it just scanning the signal the uno doing the rest

          Comment


          • #35
            Originally posted by ivconic View Post
            Yes i think Linux deals much easier with DFU peripherals than Windows.
            But i solved this just 15 minutes ago! Hurrrrraaahh!
            After 3 days of numerous attempts i solved it! And solution is actually very simple and easy!
            NOTHING... and i mean; NOTHING what's written on the Internet on most tagged links is not working at all to me here!
            Must be that i had rare "luck" to obtain pretty exotic module, not documented at all and out of any standards (Murphy again...).
            And that's why i had so much troubles, because when i read various hints and tips about how is done by somebody else; nothing works the same here.
            So i was pretty much confused all the time.
            Here is the simplest possible solution;
            1) Pull up resistor at PA12 is mistaken obviously, must be 1K5 instead 10K.
            2) Use micro USB on the module and connect it to pc.
            3) Download this and unzip it to "c:\Program Files (x86)\Arduino\hardware\" ; https://github.com/rogerclarkmelbourne/Arduino_STM32
            4) Open Arduino IDE, choose "Board: Maple (Rev 3)"
            and that's about all the pain you'll have!
            Now... last important thing is; once you click on "upload" and it starts compiling; just as it will start uploading: press button on module once and release it.
            IDE will recognize it in a moment and it will flash it successfully in no time!
            ...
            The best part is:
            once flashed; code will start running at once. You don't need to replace jumpers at all! Jumper will stay in initial "0" position all the time!
            ...
            So it will work smooth and nice even without enumeration, just as proper Arduino IDE board config is chosen.
            So now i can write my own sketches and codes and flash them straight into chip without any painful acrobatics at all!
            Sweeeeeet!
            Untill now I experimented same troubles you speak about with blue pill on my Linux PC. Then I starting to follow your tips, but without success:
            1) changed wrong resistor;
            2) connected the module to the PC via its micro USB;
            3) installed Arduino_STM32
            4) on Arduino IDE choosed board: Maple (Rev 3), (on IDE "port" is grey: disabled);
            Then pressed reset button during sketch compiling an uploading and...
            the IDE confirm loading satus but after some seconds write: "dfu-util: No DFU capable USB device available".
            If I don't press the reset button the IDE does not show "loading.." message thus really in some way the board is recognized on USB!
            All is functioning if I use an external UART adapter.
            I don't understand....

            Comment


            • #36
              Is this any good to you ? http://www.wifi4things.com/stm32f103...-ide-on-linux/

              Comment


              • #37
                For those who want more speed from arduino read this. http://stackabuse.com/speeding-up-arduino/ . it just explains why its slow and shows how a couple examples of how to speed it up by using proper c programming instead of the arduino ice language which is basicly c for non programer

                Comment


                • #38
                  And if you need even more speed try overclocking http://garagelab.com/profiles/blogs/...verclock-30mhz

                  Comment


                  • #39
                    Originally posted by Altair View Post
                    Untill now I experimented same troubles you speak about with blue pill on my Linux PC. Then I starting to follow your tips, but without success:
                    1) changed wrong resistor;
                    2) connected the module to the PC via its micro USB;
                    3) installed Arduino_STM32
                    4) on Arduino IDE choosed board: Maple (Rev 3), (on IDE "port" is grey: disabled);
                    Then pressed reset button during sketch compiling an uploading and...
                    the IDE confirm loading satus but after some seconds write: "dfu-util: No DFU capable USB device available".
                    If I don't press the reset button the IDE does not show "loading.." message thus really in some way the board is recognized on USB!
                    All is functioning if I use an external UART adapter.
                    I don't understand....
                    Now you know how i felt several days, until discovered the method that works for me.
                    I had read dozen forums and pages explaining lot of tips and methods, none worked for me.
                    I guess there are several reasons, but most probable is that those "blue pill" boards are not the same, despite they looks the same.
                    Have you tried to re-jump the jumper and see?
                    At my setup i don't need to move it. Works as explained.
                    Also you can try board options other than "Maple (Rev.3)" in IDE.
                    Most certainly you will make it work, only you have to try other options.
                    I can't tell nothing about Linux, because i don't use Linux.

                    Comment


                    • #40
                      Originally posted by c_batchelar View Post
                      For those who want more speed from arduino read this. http://stackabuse.com/speeding-up-arduino/ . it just explains why its slow and shows how a couple examples of how to speed it up by using proper c programming instead of the arduino ice language which is basicly c for non programer
                      That's very interesting link! Thanks!
                      Yes Arduino is very nice platform for novices, to make first simple steps in a world of programming and not being totally scared from a start!
                      I like it, but in time it becomes obvious that it is having lot of limits for more advanced programming and more serious tasks.

                      Comment


                      • #41
                        Originally posted by macross View Post
                        And if you need even more speed try overclocking http://garagelab.com/profiles/blogs/...verclock-30mhz
                        It is interesting.
                        But most certainly it will affect overall power drain.
                        What we want here (metal detectors, portable devices, battery operated) is as possible reduced overall power drain.

                        Comment


                        • #42
                          Originally posted by homefire View Post

                          Thank homefire,
                          this is an interesting link but I already use blue pill board with external UART; that site does not speak about use the board with it's native USB interface.

                          Comment


                          • #43
                            Now i am "brave" enough to make a mess with DSO138 !
                            So i did!
                            I downloaded all the firmware versions from a site.
                            And using Demonstrator GUI and uart connection i flashed each one of those, one by one.
                            From "xxx036" version up to "xxx61" version.
                            Every step went very well, no problems at all.
                            Each version works alright on hardware.
                            So uart connection is proven and 100% secure.
                            I wanted to change welcome screen bitmap at DSO code, so as Chinese text and title at the same screen.
                            But...! Seems that's the only part which is protected in whole source.
                            I am not 100% sure but i highly suspect it is hidden in "libdso138.a" which is pre-compiled.

                            Comment


                            • #44
                              Originally posted by Altair View Post
                              Thank homefire,
                              this is an interesting link but I already use blue pill board with external UART; that site does not speak about use the board with it's native USB interface.

                              Look these pages, maybe you find something helpful;


                              http://stm32duino.com/index.php?sid=...c56f11ac8e2b66

                              Comment


                              • #45
                                Easy scope:
                                https://github.com/pingumacpenguin/S...i/Construction

                                Comment

                                Working...