Announcement

Collapse
No announcement yet.

Strings with arduino

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

  • Strings with arduino

    when i switch between strings other stings become invisible. for example i have 3 stings on one form and only the one that was previously changed is visible.

    right now im just using genie.WriteStr(9,keyvalue)this is one of 3 commands). What is my problem. i want them all to be visible. i am using visi-geni

  • #2
    Hello Danhoo,



    Welcome to the forum!



    Based on your post, I have replicated your situation but I did not find a problem.


    Have check you the string area on each string object? maybe, this covers the other string objects.



    If you want me to check your project, you can send it here: kayven at 4dsystems dot com dot au

    Or you can attach it here.



    For your reference, I have attached the ViSi-genie project and the Arduino project (used 4D Arduino Adaptor Shield) that I have used to simulate your concern.





    Please don’t hesitate to ask if you have questions.

    Best regards,
    Kayven
    Attached Files

    Comment


    • #3
      Thanks for the reply. your code works just fine. what i have also done is kept my screen program on the screen and uploaded the writestr demo arduino sketch and that worked just fine the strings on the screen didnt disappear. so there has to be something wrong with my arduino sketch right? here is my code

      #include "genieArduino.h"
      Genie genie;
      #define RESETLINE 4
      char keyvalue[9];
      int counter = 0;
      int temp;
      int sheetw[9];
      int prebton; //previous button pressed
      int prescn = 0x00;//previous screen
      void setup() {
      Serial.begin(9600);
      genie.Begin(Serial);
      genie.AttachEventHandler(myGenieEventHandler);
      pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
      digitalWrite(RESETLINE, 0); // Reset the Display via D4
      delay(100);
      digitalWrite(RESETLINE, 1); // unReset the Display via D4

      delay (3500);
      }

      void loop() {
      // put your main code here, to run repeatedly:
      genie.DoEvents();
      }

      void myGenieEventHandler(void)
      {
      genieFrame Event;
      genie.DequeueEvent(&Event);

      //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
      if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
      {
      if(Event.reportObject.object == GENIE_OBJ_KEYBOARD)
      {
      if (Event.reportObject.index == 0) // If keyboard0
      {
      temp = genie.GetEventData(&Event);
      if(temp >= 46 && temp <= 57 && counter <=9)
      {

      keyvalue[counter] = temp; // Receive the event data from the keyboard
      genie.WriteStr(0,keyvalue); //prints to String Object
      counter = counter + 1; //increment array
      }
      else if(temp == 8) //check if backspace
      {
      counter--;
      keyvalue[counter] = 0;
      genie.WriteStr(0,keyvalue);
      }
      else if(temp == 13)
      {
      genie.WriteObject(GENIE_OBJ_FORM,prescn,0);
      if(prebton ==12){
      genie.WriteStr(9,keyvalue); ////////////////////////////// HERE ARE MY 3 STINGS THAT ARE DISAPPEARING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      }
      if(prebton ==13){
      genie.WriteStr(10,keyvalue);
      }
      if(prebton ==14){
      genie.WriteStr(11,keyvalue);
      }
      }
      else if(temp == 32)
      {
      keyvalue[0] = 0;
      keyvalue[1] = 0;
      keyvalue[2] = 0;
      keyvalue[3] = 0;
      keyvalue[4] = 0;
      keyvalue[5] = 0;
      keyvalue[6] = 0;
      keyvalue[7] = 0;
      counter = 0;
      genie.WriteStr(0,keyvalue);
      delay(10);
      }
      }
      }
      if (Event.reportObject.object == GENIE_OBJ_WINBUTTON){
      if (Event.reportObject.index == 12){
      genie.WriteObject(GENIE_OBJ_FORM,0x03,0);

      prebton = 12;
      prescn = 0x00;
      }
      if (Event.reportObject.index == 13){
      genie.WriteObject(GENIE_OBJ_FORM,0x03,0);
      prebton = 13;
      prescn = 0x00;
      }
      if (Event.reportObject.index == 14){
      genie.WriteObject(GENIE_OBJ_FORM,0x03,0);
      prebton = 14;
      prescn = 0x00;
      }
      if (Event.reportObject.index == 1){
      genie.WriteObject(GENIE_OBJ_FORM,0x03,0);
      prebton = 1;
      prescn = 0x00;
      }
      if (Event.reportObject.index == 10){

      // this is to go to home
      }
      }
      }
      }

      Comment


      • #4
        And another thing is that when i move the genie.WriteObject(GENIE_OBJ_FORM,prescn,0); AFTER those 3 if commands the string disappears immediately when it goes from number-pad form to main screen form.

        here is what i found from another forum topic... strings are held in RAM and thus when you change form, the string is cleared... this is my problem. can i somehow work around this so that it dosnt get cleared??
        Last edited by danhoo; 12th September 2018, 01:59 AM.

        Comment


        • #5
          Hello again,


          Thank you for posting your Arduino Sketch.



          In switching of the form using the code as shown below:

          Code:
          //proper syntax:
          genie.WriteObject(GENIE_OBJ_FORM, Form Index, 0);
          will clear the display's screen and draw the content of the form.


          On your code, the 3 string object has become invisible because you are calling a form that these string objects are not present.


          And also, when you use the code as shown below:

          Code:
          //proper syntax:
          genie.WriteStr( String Index, Value);
          this will print only the value to the string object regardless of what is the current form.



          This will show the value to the string object regardless of the switching of the form.

          So I suspect, this is the reason on your first post, that only the one that was previously changed is visible.


          It would be great if you can send me the WS4(Visi-Genie) project file.

          Please open your application in Workshop4, go to File, Zip Project and send the ZIP either on the forum or to my email, along with the .ino file of the Arduino code.

          If you do not wish to post it on the forum, please send it to my email.


          Best regards,
          Kayven
          Last edited by kayven@4d; 12th September 2018, 06:14 PM.

          Comment


          • #6
            Ok i uploaded the files now. i changed the arduino code now. the values do show up now but "keyvalue" does not want to go in the "sheetw" right. only the number 655 pops up on the string. why?? mind that the code is only have done.
            Attached Files

            Comment


            • kayven@4d
              kayven@4d commented
              Editing a comment
              I've received that today, thank you danhoo and I'll check at it now

            • danhoo
              danhoo commented
              Editing a comment
              If u want Kayven u can call me now, +1 226 499 5765

          • #7
            Hi,

            Thank you for sharing your project.

            First off, I don't make any changes on your ViSi-genie project but I made changes on your Arduino sketch especially to the counter routines and also, printing of the values to the string objects.

            Here's the modified code I've made:

            Code:
            #include "genieArduino.h"
            #include "SoftwareSerial.h"
            SoftwareSerial gSerial(2, 3);
            Genie genie;
            #define RESETLINE 4
            char keyvalue[9];
            int counter = 0;
            int temp;
            int prebton;
            int prescn = 0x00;
            char sheetbuffer[9];
            char stripbuffer[9];
            char Qtybuffer[9];
            
            
            void setup() {
              Serial.begin(9600);
              gSerial.begin(9600);
              genie.Begin(gSerial);
              genie.AttachEventHandler(myGenieEventHandler);
              pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)
              digitalWrite(RESETLINE, 1);  // Reset the Display via D4  
              delay(100);
              digitalWrite(RESETLINE, 0);  // unReset the Display via D4
              delay (3500);
              Serial.println("genie Ready");
            }
            
            void loop() {
              // put your main code here, to run repeatedly:
              genie.DoEvents();
            }
            
            void myGenieEventHandler(void)
            {
              genieFrame Event;
              genie.DequeueEvent(&Event);
            
              //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects)
              if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
              {
                if (Event.reportObject.object == GENIE_OBJ_KEYBOARD)
                {
                  if (Event.reportObject.index == 0)                              // If keyboard0
                  {
                    temp = genie.GetEventData(&Event);
            
                    if (temp >= 46 && temp <= 57 && temp != 8 && temp != 13)
                    {
                      if (counter < 8) {
                        keyvalue[counter] = temp;                         // Receive the event data from the keyboard
                        genie.WriteStr(0, keyvalue);                      //prints to String Object
                        counter++;
                      }
                      genie.WriteStr(0, keyvalue);                        //prints to String Object
                    }
                    else if (temp == 8)                                   //check if backspace()
                    {
                      if (counter > 0  ) counter-- ;
                      keyvalue[counter] = 0;
                      genie.WriteStr(0, keyvalue);
                    }
            
                    else if (temp == 13)                                 //check if enter()
                    {
                      genie.WriteObject(GENIE_OBJ_FORM, prescn, 0);
            
                      if (prebton == 12) {  
                        for (int x = 0; x <= counter; x++) {
                          sheetbuffer[x] = keyvalue[x];
                        }
                      }
                      if (prebton == 13) {  
                        for (int x = 0; x <= counter; x++) {
                          stripbuffer[x] = keyvalue[x];
                        }
                      }
            
            
                      if (prebton == 14) {    
                        for (int x = 0; x <= counter; x++) {
                          Qtybuffer[x] = keyvalue[x];
                        }
                      }
            
                      genie.WriteStr(9, sheetbuffer);
                      genie.WriteStr(10, stripbuffer);
                      genie.WriteStr(11, Qtybuffer);
            
                    }
                    else if (temp == 32)
                    {
                      keyvalue[0] = 0;
                      keyvalue[1] = 0;
                      keyvalue[2] = 0;
                      keyvalue[3] = 0;
                      keyvalue[4] = 0;
                      keyvalue[5] = 0;
                      keyvalue[6] = 0;
                      keyvalue[7] = 0;
                      counter = 0;
                      genie.WriteStr(0, keyvalue);
                      delay(10);
                    }
                  }
                }
            
                if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
                  if (Event.reportObject.index == 12) {                    
                    genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
            
                    prebton = 12;
                    prescn = 0x00;
                  }
                  if (Event.reportObject.index == 13) {
                    genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);    
                    prebton = 13;
                    prescn = 0x00;
                  }
                  if (Event.reportObject.index == 14) {
                    genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);  
                    prebton = 14;
                    prescn = 0x00;
                  }
                  if (Event.reportObject.index == 1) {
                    genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
                    prebton = 1;
                    prescn = 0x00;
                  }
                  if (Event.reportObject.index == 10) {    
            
                    // this is to go to home
                  }
            
              
                }
              }
            }

            Hope it helps,

            Best regards,
            Kayven
            Last edited by kayven@4d; 19th September 2018, 05:04 PM.

            Comment


            • #8
              dont worry about the keyboard string, i got it... https://www.youtube.com/watch?v=XYy1VT5aQpo&t=2s. i need to the sting into a float value right?

              Comment


              • #9
                Your welcome Danhoo!


                Thank you for the video you uploaded, it helps me a lot to figure out your project. It's an awesome project if just you know.


                With regards to the "number pop up" as you mentioned in your video:
                just insert:


                Code:
                genie.WriteStr(0, keyvalue);

                as the snippet Arduino sketch shown below:

                Code:
                    if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) {
                      if (Event.reportObject.index == 12) {
                        genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
                        genie.WriteStr(0, keyvalue);
                        prebton = 12;
                        prescn = 0x00;
                      }
                      if (Event.reportObject.index == 13) {
                        genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
                        genie.WriteStr(0, keyvalue);
                        prebton = 13;
                        prescn = 0x00;
                      }
                      if (Event.reportObject.index == 14) {
                        genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
                        genie.WriteStr(0, keyvalue);
                        prebton = 14;
                        prescn = 0x00;
                      }
                      if (Event.reportObject.index == 1) {
                        genie.WriteObject(GENIE_OBJ_FORM, 0x03, 0);
                        genie.WriteStr(0, keyvalue);
                        prebton = 1;
                        prescn = 0x00;
                      }
                      if (Event.reportObject.index == 10) {
                
                        // this is to go to home
                      }
                
                
                    }
                Based on your video, the MoveCommand(..) function has two arguments:
                distance and Altspeed, am I right?

                So, you'll need to use a snippet Arduino sketch as shown below for MoveCommand(..) function :


                Code:
                String sheetbufferString (sheetbuffer);
                long sheetbufferLong = sheetbufferString.toInt();
                
                //MoveCommand(sheetbufferLong,...);
                I declared "sheetbufferLong" variable as a long variable because the "long variables" have an extended size than "int variables". Also, I think you will not use negative number so, it is recommended that variables declared as unsigned int or unsigned long.

                About the decimal concern, can I ask a question? what to do with it?
                If none, you'll need to remove the (.) button on the keyboard.


                I've also attached the modified version of your Arduino sketch.


                Hopefully, this will help you.



                If you have concerns, I'm willing to help you.

                Best regards,
                Kayven
                Attached Files
                Last edited by kayven@4d; 19th September 2018, 10:11 AM.

                Comment


                • #10
                  thank you again! I think your idea is great, it should work! The reason i need a decimal because, say i want my backstop to be 4.50" or 4.25". That toInt really was a help so i did some research and i found toFloat https://www.arduino.cc/reference/en/...tions/tofloat/. This would work not?

                  Comment


                  • #11
                    No worries.

                    Yes, of course, it will work Danhoo, as shown below:

                    Code:
                    float sheetbufferFloat = sheetbufferString.toFloat();       //string to float conversion

                    Maybe you will need a float with integer calculation and a Map(...) function as found here:



                    Best regards,
                    Kayven
                    Last edited by kayven@4d; 19th September 2018, 10:15 AM.

                    Comment

                    Working...
                    X