Announcement

Collapse
No announcement yet.

Converting from SGC to GFX

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

  • Converting from SGC to GFX

    I have a project that interfaces a uVGA-II in SGC mode to an Arduino. The Arduino currently reads a stream of values from a micrometer, performs a series of calculations, also reads inputs from a couple of momentary switches for "menu" and "sample" input, and constructs the screen output to be sent to the uVGA-II serially.

    Now, I want to move all the display functions onto the uVGA-II in GFX mode. I'm trying to decide what functionality to leave on the Arduino. Where do I break the functionality into Arduino side, and GFX side?

    If I let the Arduino do all the I/O and decision making, and just send the variable data that needs to be displayed, what's the fastest way to get that data into the GFX?
    Current Arduino sketch:


    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;
    int wave;
    char* error = 0;
    byte a;
    float mm;
    char* family;
    char* menu;
    int minnum;
    int maxnum;
    float maxmm;
    int maxl;
    int staticl;
    int staticl5;
    int staticl4;
    int staticl3;
    float jump;
    float range;
    byte mydata[14];
    long num;
    int gearFamily = 7;
    int c0 = 0;
    int c1 = 0;

    // Mode button
    const int buttonPin = 4; // the pin that the pushbutton is attached to
    int buttonPushCounter = 7; // counter for the number of button presses
    int buttonState = 0; // current state of the button
    int lastButtonState = 0; // previous state of the button

    // Average button
    const int avgPin = 6; // switch is connected to pin 6
    int avgVal; // variable for reading the pin status
    int avgVal2; // variable for reading the delayed status
    int avgButtonState = 0; // variable to hold the button state
    int sampleState = 0; // Which sample am I taking (1 of 3)?
    long m1=0;
    long m2=0;
    long m3=0;
    int samplel1=0;
    int samplel2=0;
    int samplel3=0;
    int sampleAvgl=0;

    void setup()

    {
    Serial3.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

    // initialize the button pin as a input:
    pinMode(buttonPin, INPUT);
    pinMode(avgPin, INPUT); // Set the switch pin as input
    avgButtonState = digitalRead(avgPin); // read the initial state

    delay(500);

    // initialize uVGA card with autobaud

    autoBaud();


    // resolution 640x480

    control(12, 1); // 12 = screen resolution, 1 = 640x480

    // set baud rate

    setBaud(11); // 13 - 115200 Baud (won't work at higher rates)

    Serial3.begin(56600);


    // clear screen

    clearScreen();

    // Blue background

    replaceBackground(0, 31); // color msb:lsb

    //opaque text

    textOpacity(1); // 0 = transparent, 1 = opaque

    //pen size

    penSize(0); // 0 = solid, 1 = wireframe


    }







    void loop()

    {



    // read menu button

    // read the pushbutton input pin:r />buttonState = digitalRead(buttonPin);

    // compare the buttonState to its previous state
    if (buttonState != lastButtonState) {
    // clearScreen();
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
    // if the current state is HIGH then the button
    // went from off to on:
    buttonPushCounter++;
    clearScreen();

    }


    }
    // save the current state as the last state,
    //for next time through the loop
    lastButtonState = buttonState;

    if (buttonPushCounter == 8) {
    buttonPushCounter = 1;
    }

    gearFamily = buttonPushCounter;

    // gearFamily = 1;


    // 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= 6371)

    {
    family = "Over W M17";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }



    }
    else if (gearFamily == 2)
    {
    // do j/h pump

    family="J/H Pump";
    menu = "J/H Sort";
    wave = 4;

    if (num = 4477 && num = 4573 && num = 7038 && num = 7134 && num = 8325 && num = 8642 && num = 10908 && num = 11100 && num = 12045 && num = 12301 && num = 14089 && num = 14313 && num = 18869 && num = 19061)

    {
    family = "Over J/H 750";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }


    }
    else if (gearFamily == 3)
    {
    // do minipump

    family="Mini Pump";
    menu = "MP Sort";
    wave = 3;


    if (num = 5042 && num = 5110 && num = 5810 && num = 5862 && num = 7062 && num = 7130 && num = 8576 && num = 8700 && num = 9890 && num = 9998)

    {
    family = "Over MP390";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }
    }

    else if (gearFamily == 4)

    {
    // do webster pump match

    family = "Webster";
    menu = "Webster Match";
    wave = 3;

    if (num = 2290 && num = 2331 && num = 2920 && num = 2971 && num = 6330 && num = 6371)

    {
    family = "Over W M17";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }



    }
    else if (gearFamily == 5)
    {
    // do j/h pump

    family="J/H Pump";
    menu = "J/H Match";
    wave = 4;

    if (num = 4477 && num = 4573 && num = 7038 && num = 7134 && num = 8325 && num = 8642 && num = 10908 && num = 11100 && num = 12045 && num = 12301 && num = 14089 && num = 14313 && num = 18869 && num = 19061)

    {
    family = "Over J/H 750";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }


    }
    else if (gearFamily == 6)
    {
    // do minipump

    family="Mini Pump";
    menu = "MP Match";
    wave = 3;


    if (num = 5042 && num = 5110 && num = 5810 && num = 5862 && num = 7062 && num = 7130 && num = 8576 && num = 8700 && num = 9890 && num = 9998)

    {
    family = "Over MP390";
    staticl = 0;
    staticl5 = 0;
    staticl4 = 0;
    staticl3 = 0;
    }



    }

    else if (gearFamily == 7){

    // do instructions
    family = " ";
    menu = "Instructions";

    }

    digitalWrite(req,LOW);

    error=0;

    // delay(25);







    sendText(22, 05, 3, 255, 255, family);
    sendText(22, 03, 3, 255, 255, menu);



    // }

    if (gearFamily >= 1 && gearFamily = 4 && gearFamily
    Steve Spence KK4HFJ
    http://arduinotronics.blogspot.com

  • #2


    I'm thinking I want to dump the raw readings from the micrometer onto the bus pins, and do all the conversion math and variable stuffing on the uVGA-II.
    Steve Spence KK4HFJ
    http://arduinotronics.blogspot.com

    Comment


    • #3


      I think you'll find the quickest way is to transfer serially at 256kbaud, I don't think anyone has been able to approach that speed over the bus pins.



      Obviously since the 'transfer' (via whatever method) is likely to be the slowest piece of the pie the idea is to transfer as little as possible.



      So have some 'macros' on the Arduino, that invoke a series of predefined actions on the uVGA, have as many 'images' pre-rendered on the uSD as possible.
      Mark

      Comment


      • #4


        The Arduino won't talk to the uVGA any faster than 115200. The only thing I "have" to transfer is a 5 digit number, I can calc everything off that on the uVGA. There's not much to render, I'm just displaying text (and possibly a few rectangles to box the text).
        Steve Spence KK4HFJ
        http://arduinotronics.blogspot.com

        Comment


        • #5


          I uploaded the the Pmmc for GFX. Here is my new connection schematic. I stripped all the SGC graphics off the Arduino, so it's only sending 5 character measurements to the serial 1 on the uVGA-II. I had to move the two momentary switches off the Arduino and on to the uVGA, as that decision making is now happening on the uVGA. Everything look ok so far?


          Attached files
          Steve Spence KK4HFJ
          http://arduinotronics.blogspot.com

          Comment


          • #6

            Just to make sure everything is working ok, I loaded and ran the random circles sample program. pretty colors! My next step is to read the data from serial 1 being output from the Arduino.

            The following program lists my micrometer readings on the screen, but 3.5 characters are shifted off the left side of the screen. I see half of the 4th character on.
            UPDATE: Hit "Auto Adjust" on my monitor, and all came into view.


            Code:
             #platform "uVGA-II_GFX2"/*- serial interface test--- PICASO Platform --*///==================================================================================================func main()var ch;gfx_Cls();txt_Set(FONT_SIZE, FONT2);print ("Serial Input Test\n");print ("Download prog to flash\n");print ("Then use WS3 Terminal\n");to(COM0); print("serial input test:\n");// now just stay in a looprepeatch := serin1();if (ch != -1)print( [CHR] ch ); // if a key was received from PC, print its ascii valueendifforeverendfunc//==================================================================================================
            Steve Spence KK4HFJ
            http://arduinotronics.blogspot.com

            Comment


            • #7


              If I want to display a constantly changing value (from serin1) in a box on the screen, how would I go about that?
              Steve Spence KK4HFJ
              http://arduinotronics.blogspot.com

              Comment


              • #8


                Just add a gfx_MoveTo(100,100); to always print in the same place. Put it in your repeat loop, before your print statement.
                You can also use something like gfx_Rectangle(75,75,120,120,WHITE);
                to draw a box around the position if you want.

                Comment


                • #9


                  That is pretty cool, but I only see one character in the box, the last digit of the micrometer setting. In the previous example I had a line break after each full set of numbers. I think what is happening is each character is being sent back to the same point, over writing the last one. How do I get the whole set of 5 and then rewrite? A for loop loading a variable, then print the variable?


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

                  Comment


                  • #10


                    The way I would do it is start each number coming from your arduino with a $ or some similar message start character. (Or maybe use the line feed '/n' if you are already sending that at the end of your message.)

                    Then use com1_init(combuf,5,'$') to start up the buffered coms. combuf is just an array big enough to hold your set of data.

                    Then in your loop check for com1_Full() to return 1. Once it does, grab your number out of the buffer, print it and the use the com1_init to start looking for the message again.

                    The buffer stores two ascii characters per entry and as long as your number is always 5 characters I would imagine it would look something like this.

                    if(com1_Full())
                    gfx_MoveTo(100,100);
                    print([CHR]LObyte(combuf[0]),[CHR]HIbyte(combuf[0]),[CHR]LObyte(combuf[1]),[CHR]HIbyte(combuf[1]),[CHR]LObyte(combuf[2]));
                    com1_init(combuf,5,'$');
                    endif

                    Comment


                    • #11


                      Fantastic. I'll update my project when I return on Tuesday, and post photo.
                      Now, If I want to use that 5 character number in a variable for further calculations? For instance, insert the decimal place (12345 is really 12.345 mm).
                      Steve Spence KK4HFJ
                      http://arduinotronics.blogspot.com

                      Comment


                      • #12


                        Error: 'com1_init' not found

                        Looked at the internals guide, it needs to be com1_Init.

                        I'm not getting any display (other than the rectangle box).

                        This is what I'm sending from the Arduino:

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

                        Comment


                        • #13


                          shouldn't I have something like

                          combuf := serin1();

                          I already set

                          var combuf;

                          in the proper place.

                          HTML Code:
                          #platform "uVGA-II_GFX2"
                          /*
                          - serial interface test-
                          -- PICASO Platform --
                          */
                          //==================================================================================================
                          #inherit "4DGL_16bitColours.fnc"
                          func main()
                          var combuf[5];
                          gfx_Cls();
                          txt_Set(FONT_SIZE, FONT2);
                          
                          gfx_Rectangle(75,75,140,120,WHITE);
                          
                          
                          // now just stay in a loop
                          repeat
                          
                          if(com1_Full())
                          gfx_MoveTo(100,100);
                          print([CHR]LObyte(combuf[0]),[CHR]HIbyte(combuf[0]),[CHR]LObyte(combuf[1]),[CHR]HIbyte(combuf[1]),[CHR]LObyte(combuf[2]));
                          com1_Init(combuf,5,'0');
                          endif
                          forever
                          
                          endfunc
                          //==================================================================================================
                          Steve Spence KK4HFJ
                          http://arduinotronics.blogspot.com

                          Comment


                          • #14


                            What I'm really aiming for here is to stuff the 5 digits into a variable, and display (or further calculate on) that variable.
                            Steve Spence KK4HFJ
                            http://arduinotronics.blogspot.com

                            Comment


                            • #15


                              Hi Steve,
                              I just picked up on what you are trying to do,
                              eg

                              If I want to display a constantly changing value (from serin1) in a box on the screen, how would I go about that?
                              I suggest that you run many of the 4DGL program samples
                              so that you become familiar with the languge, and its capabilities -
                              this will help you to understand what is available - programatically.

                              If you are still stuck give us an outiline example ofe xactly what you are trying to do, and we will try to help with a code example.
                              Regards,
                              Dave

                              Comment

                              Working...
                              X