Announcement

Collapse
No announcement yet.

rtc and thingspeak library, stop 4dbutton

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

  • rtc and thingspeak library, stop 4dbutton

    Good morning, I wrote a sketch runs on mega arduino with serial1 @ 200000 connected a 70dct-clb and pin4 to display resetpin.
    The sketch and the display work correctly.
    The problem occurred when I inserted the thingspeak client and the RTC module because the programmed buttons no longer respond.
    I didn't change the code for the display and no change the workshop project (visi genie). I only added the default libraries of thingspeak and ds3231 (https://github.com/NorthernWidget/DS3231) and the relevant code.
    If I edit (/ * * /) the parts related to thingspeak and rtc, the buttons will return to work.
    How can I resolve?
    Thank you



  • #2
    Hello,

    May I ask what pin did you use for your RTC?

    Note that PA12 and PA13 are special pins as it is used primarily for communication with the touch controller.
    If you did use this pins it is more likely that it is the cause why the display didn't work.

    You can refer to this data sheet for for refence: https://www.4dsystems.com.au/product...heet_R_1_6.pdf under Chapter 4.

    Hope it helps.

    Best regards,
    Bern

    Comment


    • #3
      Good morning Bern and thank you for your reply.
      RTC module is connected to arduino mega at pins 20 and 21 (sda and scl).
      Display is connected at arduino with the GEN4-IB converter, I haven't physical connection pins for the display but only serial and reset.

      I read the pdf you refer me, but I understand that refers to the hardware pins that can be used by a converter that uses all 30 pins of the display flat. I understand?

      I paste the code part related to the sw buttons, maybe I wrote some mistakes?

      Code:
      #include <genieArduino.h>
      Genie genie;
      #define RESETLINE 4
      
        Serial1.begin(200000);  //Serial1 @ 200000 (200K) Baud
        genie.Begin(Serial1);  // Use Serial 1 for talking to the Genie Library, and to the 4D Systems display
        genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
       
        // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)
        // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC
        // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and
        // the 4D Arduino Adaptors invert this signal so must be Active High.  
        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); //let the display start up after the reset (This is important) 3500
      
        // Set the brightness/Contrast of the Display - (Not needed but illustrates how)
        // Most Displays, 1 = Display ON, 0 = Display OFF. See below for exceptions and for DIABLO16 displays.
        // For uLCD-43, uLCD-220RD, uLCD-70DT, and uLCD-35DT, use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON.
       
      genie.WriteContrast(7);
      
       bool button;
      
      ...some library, int, float...
      
      
      void loop()
      {
      genie.DoEvents();
      
      ...some code...
      }
      
      void(* resetFunc) (void) = 0;//declare reset function at address 0 for arduino
      
      void myGenieEventHandler(void)
      {
        {
        genieFrame Event;
        genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below
        genie.GetEventData(&Event);
       if (Event.reportObject.cmd == GENIE_REPORT_EVENT)  // message coming from objects configured to report a message
        {
          if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)  // If the Reported Message was from a 4DButton
          {
            if (Event.reportObject.index == 0)  // If from 4DButton0
            {
             button = genie.GetEventData(&Event); // Receive the event data from 4DButton0
            
             if (button == 0) {          // if 4DButton0 has been released
             }
             else if (button == 1) {     // if 4DButton0 has been pressed
             }
            }
           }
         
          if (Event.reportObject.object == GENIE_OBJ_WINBUTTON) // If a Winbutton was pressed
            {
            if (Event.reportObject.index == 0) {// If Winbutton #0 was pressed   
            genie.WriteContrast(7);
            genie.WriteObject(GENIE_OBJ_FORM, 0, 0);
            }
            }
          if (Event.reportObject.object == GENIE_OBJ_USERBUTTON)
          {
            if (Event.reportObject.index == 9)
            {
              genie.WriteContrast(0);
              genie.WriteObject(GENIE_OBJ_FORM, 5, 0);
            }
            if (Event.reportObject.index == 10)
            {
            pinMode(RESETLINE, OUTPUT); 
            digitalWrite(RESETLINE, 0); 
            delay(100);
            digitalWrite(RESETLINE, 1); 
            delay(3500);
           }
           if (Event.reportObject.index == 11)
           {
           resetFunc(); //call reset
           }
          }
        }
       }     
      }

      Comment


      • #4
        Hello,
        You mentioned that "If I edit (/ * * /) the parts related to thingspeak and rtc, the buttons will return to work."
        It might be that error is coming from there. There not much that we can do since we dont have your full file project.
        If its possible, can you send us the zip file project for us to check.
        If so, use the zip project utility located below the file tab.

        Best regards,
        Bern

        Comment


        • #5
          Hello, sorry for the delay in the response, work absorbed me. Attached the complete project Thank you

          Comment


          • #6
            Hello,

            On your main loop there's a lot of delay which is more likely causing the error on the 4dgl display, because
            the genie.DoEvents() will not response right away to that. One thing you can do is to use a non blocking delay or millis().

            Best regards,
            Bern

            Comment


            • rockinrulla
              rockinrulla commented
              Editing a comment
              Hello Bernadette,
              I'm sorry, but I removed all the delay (removed, not replaced), and inserted the part of the code related to the RTC, or / and the part relating to thingspeak, the problem remains.
              how can we fix it?
              Thank you

          • #7
            Hello,

            I see that there are quite a few Serial.print() on your code. Is it printing any data at all? It would be of help to know what your seeing on your Serial monitor.

            Also can you try to run the individual parts of your program independently i.e. just the RTC program alone.
            This will make it easier to debug and test the library that your using.

            And also can you give us a close picture of the hardware connection for us to check further.

            Kind regards,
            Bern

            Comment


            • #8
              Hi Bern,
              I wrote many Serial.print for debugging while building the program, reporting the correct data of the sensor readings.
              I removed them from the complete code, but the buttons don't work.

              I modified the code part related to the RTC, and the buttons work ALMOST correctly.
              For example the 4Dbuttons work but the WINBUTTON no.

              I created a program with only display, wifi, energy reading and thingspeak.
              All the buttons don't works

              Do you need a photo of the connections?
              If yes, I'll load it. I confirm however that the display is connected to a power supply 5v (with 5v common arduino mega) , rx and tx to serial 2 of arduino mega, the reset to pin4 of arduino mega and gnd of the dispaly to the common gnd between power supply, dispaly and gnd arduino.
              Thank you

              Comment


              • #9
                Hello,

                It's possible that the genie.DoEvents() function in the main loop is hindered by the runtime of the other functions. You might need to optimise your code by doing some of the routines only once by placing them in the void setup().
                Please note that in order to receive button events, this function must be freely running.

                Also since you have lots of serial communication going through Serial, you can set this to a higher baud rate instead of 9600.

                Kind regards,
                Bern

                Comment


                • #10
                  Hello Bern,
                  I didn't understand what you means for "note that in order to receive button events, this function must be freely running"
                  Is there something wrong with my code?

                  Also, I have 3 hardware serial,
                  Serial.begin (115200) for debugging (now for testing, before now 9600)
                  Serial1.begin (200000) for the 4D display
                  Serial2.begin (115200) for esp8266-01
                  Serial3.begin (115200) for rs 485/232 converter
                  Wire.begin () for rtc (but it isn't hw serial)

                  How should I set the hw serial speed, your advice?
                  Thank you

                  Comment


                  • #11
                    Hello,

                    The main loop should not have any blocking delay that's what I mean. It is more likely than not the cause of some error.
                    There is not much that we can do since we don't have the full components of your program for testing. All we can do is to point out possible error that causing the issue.

                    -You can use any comm speed but it is ideal that you set a higher baud rate for faster serial communication.

                    -
                    I modified the code part related to the RTC, and the buttons work ALMOST correctly.
                    For example the 4Dbuttons work but the WINBUTTON no.
                    .There might be a possible problem with how you set events on the buttons. Kindly check for this as well.

                    - If you can try to run the test draw for us to make sure that it's working just fine.

                    - On your first post you mention that
                    The problem occurred when I inserted the thingspeak client and the RTC module because the programmed buttons no longer respond.
                    Now we just want to make it clear if you happened to run your program, just using each of this library.

                    -Lastly, If possible can we have a close up photo of the hardware connection of your project.

                    Kind regards,
                    Bern

                    Comment


                    • #12
                      Hello Bern,
                      as from your advice, I removed the delays (not those for writing the rs485) and replaced with millis the upload data condition to thinkspeak.
                      Now all the buttons work, but they don't work when thingspeak uploading is working.
                      It seems correct to me, as it involves time and resources.
                      That's all for now, if I have more questions, I'll open another post.
                      Thank you

                      Comment

                      Working...
                      X