Announcement

Collapse
No announcement yet.

Weird behavior when using SPI

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

  • CaM
    replied
    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!

    Leave a comment:


  • michael_4D
    replied

    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:	54
Size:	33.3 KB
ID:	66685

    I hope this helps.

    Best regards,

    Leave a comment:


  • CaM
    replied
    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.

    Leave a comment:


  • michael_4D
    replied
    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

    Leave a comment:


  • CaM
    replied
    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

    Leave a comment:


  • michael_4D
    replied
    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);

    Leave a comment:


  • CaM
    replied
    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.

    Leave a comment:


  • CaM
    replied
    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);
    
      }
    }

    Leave a comment:


  • michael_4D
    replied
    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.

    Leave a comment:


  • CaM
    replied
    Heya Michael. This should do it

    https://drive.google.com/drive/folde...S2?usp=sharing

    looking at things again I think it may infact be the addition of the working thermocouples that is causing this slower reaction. Without the thermocouple code it works very smoothly. Adding it back in you can see how jerky it is. Maybe the rate the thermocouples can be read? Even the TX/RX lights on the arduino flash much slower

    Thanks

    Cam

    Leave a comment:


  • michael_4D
    replied
    Hello,

    Would care to send your current program?

    This should help us understand your situation better

    Leave a comment:


  • CaM
    replied
    Well..... Turned out the new library didn't help so was back to the drawing board. After trials it seemed to be the BMP280 causing the issue. I had a spare of different brand and configuration which done the trick over I2C!

    Everything is up and running now with only values being projected to the screen relevant to what form is being displayed. This works for the most part but has slowed it down considerably. The boost value tends to not update fast enough. This I assume is due to the increased loop times as the program is scanning through the loop each time and finding which if statement is true to then write the value only to repeat this over and over.

    Any ideas on speeding this up?

    My only thought is to simply write these values constantly and see how I go...

    Leave a comment:


  • CaM
    replied
    That's pretty much what I ended up doing (getting better at solving these small tasks ) I made a seperate function holding all that and then call that function during the loop

    Although I'm back to square 1 with everything but the thermocouples updating unless the form has changed. I'm really stuck as to why this is

    I've tried different libraries, even switched my BMP to use the hardware SPI... nothing

    [EDIT]

    This gives me hope Seemed to have the same problem, different screen

    https://forum.arduino.cc/index.php?topic=387251.0
    Last edited by CaM; 6th December 2018, 06:13 PM.

    Leave a comment:


  • tonton81
    replied
    your updating the values on form change which is fine according above, however, to continue writing values you should put the WriteObjects in your loop somewhere to continue writing afterwards, this is because the event fires only once. If you take the form change event and set a global variable called “myForm” for example, then in your loop you could always do:

    if ( myForm == 1 ) { doThis(); } // if your on form1

    Leave a comment:


  • CaM
    replied
    Originally posted by tonton81 View Post
    was it working before?
    what does it do? nothing at all on screen?
    how are your connections? (common ground? shield??
    Yup all was working before except the values from thermocouples only updated upon form change. Since adding the code below, I now have data written to each form when active but it seems to only be written once upon arriving at that form. How would I have it continually updating in real time?

    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)
          {
            // Write to CoolGauge0 with the value in the EgtTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, EgtTemp_lcd);
            // Write to CoolGauge1 with the value in the boost variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 1, boost);
          }
          else if (Event.reportObject.index == 1)
          {
            // Write to CoolGauge2 with the value in the boost variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 2, boost);
          }
          else if (Event.reportObject.index == 3)
          {
            // Write to CoolGauge3 with the value in the oilpress variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 3, oilpress);
          }
          else if (Event.reportObject.index == 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, H2oTemp_lcd);
          }
          else if (Event.reportObject.index == 5)
          {
            // Write to CoolGauge6 with the value in the EgtTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 6, EgtTemp_lcd);
          }
          else if (Event.reportObject.index == 6)
          {
            // Write to CoolGauge7 with the value in the H2oTemp variable
            genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 7, H2oTemp_lcd);
          }
          else if (Event.reportObject.index == 7)
          {
            // Write to Leddigits4 with the value in EgtTemp variable
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 4, EgtTemp_lcd);
            // Write to Leddigits5 with the value of boost variable / 10
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 5, (boost / 10));
            // Write to Leddigits6 with the value in oilpress variable
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 6, oilpress);
            // Write to Leddigits7 with the value in H2oTemp variable
            genie.WriteObject(GENIE_OBJ_LED_DIGITS, 6, oilpress);
          }
        }
      }
    }
    Cheers
    Cam

    Leave a comment:

Working...
X