Announcement

Collapse
No announcement yet.

Converting from SGC to GFX

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

  • #16


    I've gone though each of the four serial examples provided with the IDE for this platform, and have read the serial chapter in the internals manual. For now, I simply want to read the 5 digit number from the arduino and save it in a variable for further processing. I've documented my code above.

    I'm confused on com_Init.

    buffer size is in bytes, and there are two bytes per array element, and I'm trying to pass 5 characters, so buffer size should be 20? The internals guide says a buffer size of 20 equals 12 characters.

    I'm using Serial3.println(num); on the Arduino, so '/n' should be the qualifier?
    It also seems to me that

    com1_Init(combuf,5,'0');
    ( or com1_Init(combuf,10,'/n'); ?)


    Should be above the forever loop, not in it?
    Steve Spence KK4HFJ
    http://arduinotronics.blogspot.com

    Comment


    • #17


      Ok Steve understood,
      a while ago I had a great idea of making an assembler and burner for the little 6 pim Microchip IC's
      and started to make an assembler/programmer written in 4DGL for the little beasties
      but never finished it.

      If you have a look through this code (far from finished but does a good deal so far),
      It should show a lot of techniques for extracting numbers etc from a string.


      Attached files picasm10.4dg (37.4 KB)
      Regards,
      Dave

      Comment


      • #18


        I'm sorry, but I don't understand half of that code. I found the section on Serin(), but it looks just like the code sample I used that only displays 1 character (the last of the 5) on my screen.
        I was hoping for a simple 3 line or so function that:

        Reads the 5 characters in, saves to a variable, looks for next set of characters, save to same variable etc.

        The micrometer is constantly moving, so the variable has to have the latest reading in it.
        Steve Spence KK4HFJ
        http://arduinotronics.blogspot.com

        Comment


        • #19


          Ok, I got the actual 5 digit number displaying on the screen in one spot with the following script (it changes correctly as I move the micrometer), but I need it in a variable. This seems like progress of sorts. ch == 565656561310 (the stream coming from the arduino) when the mic is reading 8888, so I told it to reset position when it sees a 10 ....


          UPDATE: on less than 5 digit mic readings, say 5429, I still get a 5 digit reading on the screen. The first 4 are correct, but the 5th digit will stay steady as I move the mic up and down in the 4 digit mic reading range, and will change as I again move from a 5 digit mic reading to a 4, and stay steady until I make that same transition again, where it comes up with a different 5th digit.


          HTML Code:
           #platform "uVGA-II_GFX2"
          /*
          - serial interface test-
          -- PICASO Platform --
          */
          //================================================== ================================================
          func main()
          var ch;
          gfx_Cls();
          txt_Set(FONT_SIZE, FONT2);
          gfx_MoveTo(90,100);
          // now just stay in a loop
          repeat
          ch := serin1();
          if (ch != -1)
          print( [CHR] ch ); // if a key was received from PC, print its ascii value
          // print (ch);
          if (ch == 10)
          gfx_MoveTo(90,100);
          endif
          endif
          forever
          endfunc
          //================================================== ================================================
          Steve Spence KK4HFJ
          http://arduinotronics.blogspot.com

          Comment


          • #20


            Would it help if during sending from the Arduino, I did a

            Serial3.print(num, DEC);

            instead of

            Serial3.println(num);

            I think I need to add a "separator" so the receiving unit knows where start and stop is.

            Serial3.print("$");
            Serial3.print(num, DEC);
            Steve Spence KK4HFJ
            http://arduinotronics.blogspot.com

            Comment


            • #21


              Not to butt in, but this thread may give you some of the info you are looking for.....
              http://4d.websitetoolbox.com/post/picking-out-data-from-a-string-5821237
              _______________
              Best Regards,
              Howard

              Comment


              • #22


                ok, that kind of helps. I have values (4-5) coming in ascii, and need to assemble them back into one number. I'm also now sending a separator, value 36 ($), that needs to be stripped out. My problem earlier was a CR and a LF (13 and 10). Now I'm getting 54 55 52 55 36 (6 7 4 7 $) into the uVGA-II.

                That example shows how to break them out into discreet variables, I just want one, containing 6747.

                UPDATE: When I scroll the micrometer up into a 5 character range, I get 5 digits and a $, when I scroll back down to a 4 digit range, I get 2 ($$) padding out to 6 characters (12345$ and 2345$$).

                0.006 on the mic displays as 6$$$$$
                0.000 displays as 0$8$$$

                The extra $$$ are screen artifacts, as the value displayed gets fewer positions, the old $ did not go away. I have to write a " " to that spot between prints?



                HTML Code:
                #platform "uVGA-II_GFX2"/*
                - serial interface test-
                -- PICASO Platform --
                */
                //================================================== ================================================
                func main()
                var ch;
                gfx_Cls();
                txt_Set(FONT_SIZE, FONT2);
                gfx_MoveTo(90,100);
                // now just stay in a loop
                repeat
                ch := serin1();
                if (ch != -1)
                print( [CHR] ch ); 
                // print (ch);
                if (ch == 36)
                gfx_MoveTo(90,100);
                endif
                endif
                forever
                endfunc
                //================================================== ================================================
                Steve Spence KK4HFJ
                http://arduinotronics.blogspot.com

                Comment


                • #23


                  I think I need to convert each incoming ascii character to decimal (unless it's 36) and concatenate?

                  I'm not sure how to do that.
                  Steve Spence KK4HFJ
                  http://arduinotronics.blogspot.com

                  Comment


                  • #24


                    If you download the program I wrote (first one), the format for a command is :
                    ...
                    You don't need to do fixed padding, as it handles variable width. But you do need to send a CR. Alternatively, you could modify the second program to send down a fixed number of characters, and pre-pad leading zeros to your number (ie 0002). You also would need to bump the number of characters from 4 to 5, if that is what you need....
                    _______________
                    Best Regards,
                    Howard

                    Comment


                    • #25


                      I'm not understanding. Can you show me how to take the incoming stream of ascii characters (which can vary from 0-5 digits), and save them to a single variable? Do you need me to make any changes on the arduino side to facilitate this?

                      This is the current Arduino sketch:

                      [HTML]int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
                      int dat = 2; //mic Data line goes to pin 2
                      int clk = 3; //mic Clock line goes to pin 3
                      int i = 0; int j = 0; int k = 0;
                      byte mydata[14];
                      int num;

                      void setup(){
                      Serial3.begin(9600);
                      Serial.begin(9600);
                      pinMode(req, OUTPUT);
                      pinMode(clk, INPUT);
                      pinMode(dat, INPUT);
                      digitalWrite(clk, HIGH); // enable internal pull ups
                      digitalWrite(dat, HIGH); // enable internal pull ups
                      digitalWrite(req,LOW); // set request at LOW

                      }
                      void loop(){

                      // get data from mic
                      digitalWrite(req, HIGH); // generate set request
                      for( i = 0; i < 13; i++ ) {
                      k = 0;
                      for (j = 0; j < 4; j++) {
                      while( digitalRead(clk) == LOW) { } // hold until clock is high
                      while( digitalRead(clk) == HIGH) { } // hold until clock is low
                      bitWrite(k, j, (digitalRead(dat) & 0x1)); // read data bits, and reverse order )
                      }
                      // extract data
                      mydata[i] = k;
                      // sign = mydata[4];
                      // decimal = mydata[11];
                      // units = mydata[12];


                      }

                      // assemble measurement from bytes
                      char buf[7];
                      for(int lp=0;lp
                      Steve Spence KK4HFJ
                      http://arduinotronics.blogspot.com

                      Comment


                      • #26


                        I only have to divide the assembled variable by 1000 to get the actual measurement in mm.
                        Steve Spence KK4HFJ
                        http://arduinotronics.blogspot.com

                        Comment


                        • #27


                          Did you download and study the 4DGL program in post #21 of the link I provided? The program does just that.......
                          _______________
                          Best Regards,
                          Howard

                          Comment


                          • #28


                            http://4d.websitetoolbox.com/post/show_single_post?pid=1273344257&postcount=21
                            _______________
                            Best Regards,
                            Howard

                            Comment


                            • #29


                              If you look at the program, and still have trouble, I can help you modify it so it does what you need......
                              _______________
                              Best Regards,
                              Howard

                              Comment


                              • #30


                                I did download it, loaded it into the IDE, and played around with it. It's very cool, very comprehensive, and reminds me of buying a maserati to go grocery shopping. The maserati can do that, but it's capable of so much more. My need is so very simple. Can't we do it with 3 or so lines of code? I don't need to display the result (well, maybe just for debugging), as this variable is the basis for a whole bunch of calculations for different gear pumps(look at my original arduino sketch at the beginning of this thread, 25+ pages of code).
                                Steve Spence KK4HFJ
                                http://arduinotronics.blogspot.com

                                Comment

                                Working...
                                X