Announcement

Collapse
No announcement yet.

Weird behavior when using SPI

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

  • #16
    Hello Cam,

    On the ScreenUpdate function of your arduino project, I noticed quite a few of these:
    Code:
    if (Form == 4);
    {
    
    // Do something here
    
    }
    I believe the events enclosed on the curly brackets won't be executed, this is because if (Form == 4); is a one- liner syntax.

    This means that it should be followed by an event before the semicolon. e.g. if (Form ==4 ) digitalWrite(LEDpin, HIGH);

    On that same function, I also noticed that the ifs were not nested properly e.g. if (Form == 5) was inside the condition of if (Form ==1)

    I hope this helps.

    Best regards,

    Last edited by michael_4D; 5th January 2019, 05:00 PM.
    Michael

    Comment


    • #17
      Hi Michael

      Thanks for looking at my code. That was quite the mistake!

      This has however likely alluded me to another possible problem. After correcting (At least I think I have) that mistake, I seem to only get values showing on Form 0. Now the thing is that this is the starting form. It is almost as if Form gets set to 0 and never changes after. I used the GTX tool and checked that the display was actually reporting the Form change when cycling thru the different forms and it is. Maybe your eyes see something I don't? Thanks

      Code:
      void myGenieEventHandler(void)
      {
        genieFrame Event;
        genie.DequeueEvent(&Event);
      
        if (Event.reportObject.cmd == GENIE_REPORT_EVENT)
        {
          if (Event.reportObject.object == GENIE_OBJ_FORM)
          {
            if (Event.reportObject.index == 0)
            {
              Form = 0;
            }
            else if (Event.reportObject.index == 1)
            {
              Form = 1;
            }
            else if (Event.reportObject.index == 3)
            {
              Form = 3;
            }
            else if (Event.reportObject.index == 4)
            {
              Form = 4;
            }
            else if (Event.reportObject.index == 5)
            {
              Form = 5;
            }
            else if (Event.reportObject.index == 6)
            {
              Form = 6;
            }
            else if (Event.reportObject.index == 7)
            {
              Form = 7;
            }
          }
        }
      }
      
      void ScreenUpdate()
      {
        if (Form == 0)
        {
          // Write to CoolGauge0 with the value in the EgtTemp variable
          genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, Egt);
          // Write to CoolGauge1 with the value in the boost variable
          genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 1, boost);
          //Set PEAK Egt temp to display
          if ( Egt > 0 && Egt > EgtPeak)
          {
            EgtPeak = Egt;
            // Write to MAX digits with the value in the H2oPeak variable
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, EgtPeak);
          }
          //Set PEAK PSI to display
          if ((rawBoost - atmpsi) > 0 && (rawBoost - atmpsi) > boostpeak)
          {
            boostpeak = (rawBoost - atmpsi);
            // Write to MAX digits with the value in the peakboost variable
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, (boostpeak * 10));  // Prob a more elegant way to this, but the scaling messes me up....does the trick
          }
        }
          if (Form == 1)
          {
            // Write to CoolGauge2 with the value in the boost variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 2, boost);
          }
          if (Form == 3)
          {
            // Write to CoolGauge3 with the value in the oilpress variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 3, oilpress);
          }
          if (Form == 4)
          {
            // Write to CoolGauge4 with the value in the oilpress variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 4, oilpress);
            // Write to CoolGauge5 with the value in the H2oTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 5, H2o);
            //Set PEAK oil pressure to display
            if ((oilpress / 10) > 0 && (oilpress / 10) > oilpresspeak)
            {
              oilpresspeak = (oilpress / 10);
              // Write to MAX digits with the value in the oilpresspeak variable
              genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, oilpresspeak);
            }
            //Set PEAK water temp to display
            if ( H2o > 0 && H2o > H2oPeak)
            {
              H2oPeak = H2o;
              // Write to MAX digits with the value in the H2oPeak variable
              genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, (H2oPeak * 10));
            }
          }
          if (Form == 5)
          {
            // Write to CoolGauge6 with the value in the EgtTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 6, Egt);
          }
          if (Form == 6)
          {
            // Write to CoolGauge7 with the value in the H2oTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 7, H2o);
          }
          if (Form == 7)
          {
          // Write to Leddigits4 with the value in EgtTemp variable
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 4, Egt);
          // Write to Leddigits6 with the value in oilpress variable
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 6, (oilpress / 10));
          // Write to Leddigits7 with the value in H2o variable
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 7, (H2o * 10));
          // Write to Leddigits5 with the value of boost variable
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 5, boost);
      
        }
      }

      Comment


      • #18
        It appears this may be the case.

        I have set up a spare pin to output and have an LED attached to it. From here I place the code to drive the LED in various places. When set inside the if (Form == 0) Curly brackets it is ON. If I add this to another that is not 0 the LED never lights up


        I think the event handler part is wrong..
        Last edited by CaM; 9th January 2019, 03:47 PM.

        Comment


        • #19
          Hello Cam,

          Your description seems a little odd, could you please use else ifs on your ScreenUpdate() function?

          This should make for a more efficient process as the Arduino will not read through all all the condiitons over and over again.

          When set inside the if (Form == 0) Curly brackets it is ON. If I add this to another that is not 0 the LED never lights up
          Is it executing the other processes? i.e. in from 3 : genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 3, oilpress);
          Michael

          Comment


          • #20
            Thanks for the tip, I did try that with no change so changed it back. I see what you mean and it makes sense. Thanks!

            It seems that only the form number that has been set to the variable 'Form' displays data written to the screen. I set Form at the top as type int (int Form = 0). Changing this to Another number will allow that Form to be written to on the screen but only that one. It does not update the Form variable when changing screens.

            Cheers Michael

            Comment


            • #21
              Hello Cam,

              I've attached a modified version of your project, this might help you on debugging.

              I commented out all the other processes except for the part concerning the communication with the display.

              I hope this helps.
              Attached Files
              Michael

              Comment


              • #22
                Thanks Michael

                I'm using a nano so how do I run the screen and the serial monitor? Thought I could only do one at once. Seems you have software serial in there but I'm not familiar with this. Also no call to the ScreenUpdate function. Was that wrong? Also after uploading the display program it says program type different diablo - picaso and screen doesn't work

                Cheers
                Last edited by CaM; 15th January 2019, 03:18 PM.

                Comment


                • #23

                  Hello Cam,

                  Sorry About that, I thought you were familiar with software serial.

                  Here's a reference page that may provide additional insight, this post might provide additional information too.

                  In essence, what I did was print something on the Arduino Serial port for every event that's happening on the Serial port that's being used by the Display and Arduino.

                  To do this I used a Software Serial port (serial) to communicate with the display ( genie.Begin(serial)).

                  Serial 0 was used for the "Logs" that can be viewed through the Arduino IDEs Serial Monitor

                  I believe the Arduino Nano supports Software Serial too, so to simulate this on your end, all you have to do is rewire the connection of your Arduino and display.

                  If you were using Pin 0 for the Rx of your Arduino, you'll have to move it to pin 5. You should also move the connection of your Tx pin from Pin 1 to Pin 6.

                  Essentially you should have :
                  Display Tx ---------> Arduino pin 5
                  and Display Rx ----------------> Arduino Pin 6.
                  Everything else should remain he same.

                  I didn't call the ScreenUpdate() yet as you've stated on your other post that you were having issues with recieving the object index data from your display. The goal of that was to print something on the Arduino port during every form switch, this should help us determine where the bug is coming from.

                  Also after uploading the display program it says program type different diablo - picaso and screen doesn't work
                  Upon openning the ViSi genie project, you would notice that the target display for this is a gen4-uLCD-32DT, could you please try changing the target display under the project tab into the one that you're currently using?

                  I've attached a reference photo for your guidance.

                  Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	33.3 KB
ID:	66685

                  I hope this helps.

                  Best regards,
                  Michael

                  Comment


                  • #24
                    Thanks for that Michael.

                    Some positive news at last! I added the "else if's, " back into the ScreenUpdate function and moved the peak calculations outta there up to their respective sections. This didn't fix it but as I slowly added stuff back in it seemed to be working fine. Looks cleaner too. Upon adding the ScreenUpdate function back in it would glitch out and end up reporting what screen it was on randomly, and also reporting it was on a screen that it wasn't even on!

                    When scrolling thru things I had a think about the order things happen and realised that the ScreenUpdate was right after the genie.DoEvents. Perhaps it didn't have time to process the events and was running the screen update without getting the info? I moved it to the bottom after all the calculations. Voila!!

                    I think I'm actually now at a point where everything is working and need to sort a permanent solution and install things. Thanks for your persistence in helping this amateur out!

                    Comment

                    Working...
                    X