Announcement

Collapse
No announcement yet.

Weird behavior when using SPI

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

  • Weird behavior when using SPI

    Hi again!

    Quick info
    - Arduino Nano
    - 4D-SK-32PTU-AR Screen
    - i2c bmp sensor


    So I'm basically making up a monitor for my 4x4 truck. I simply read some sensors and display them on various screens. So far I have written code and connected a map sensor, barometric pressure sensor and oil press sensor. All is well.

    I have 2 sensors left which are both k-type thermocouples. I'm using an old library (hopefully this isn't the prob) that uses SPI and I connect to the dedicated header pins for MISO, SCK and power. I set a CS pin per thermocouple.

    So... I have only attached one, but upon upload I get my gauges (thermister readings) showing values but they don't update in real time. If I switch screens and come back it will have updated or I'll see it change in a split second to where it should be when I first arrive on the screen, but not whilst it sits on the screen with the gauge after. This seems to be some sort of interference as I can run this fine with just code for thermisters without the 4d code or screen and I see it fine in serial monitor.

    I add the following line to just the thermister code with serial monitor, it compiles, but I get jibberish with every 10 sec a correct reading somewhere in the middle

    genie.AttachEventHandler(myGenieEventHandler);

    I'm not super clued up on this stuff but maybe I'm missing something obvious? If not I'll perhaps try re-writing everything to do with the thermocouples. If that doesn't I'll try a new library.

    This is the library https://github.com/JChristensen/Thermocouple

    Seeing as this is the only problem I've had like this, maybe it is the library??

    Cheers!!



    Last edited by CaM; 29th November 2018, 06:02 PM.

  • #2
    Well..... I've since switched the BMP to SPI along with thermocouples....no dice. I then used software SPI for thermocouples.....no dice. Just now I created a new 4d screen with some gauges and they all update in real time using the same arduinoi code ( added 5 gauges, no.5 is what my thermocouple display temp is). What gives? I then add a new form and new gauge to original set of screens, try adding that to my code but it doesn't update....Anyone had a gauge or digits not update, but everything else does? Driving me nuts!

    Comment


    • #3
      Hello,

      Just to be clear you got your project working by redoing your GUI right?
      Just now I created a new 4d screen with some gauges and they all update in real time using the same arduinoi code ( added 5 gauges, no.5 is what my thermocouple display temp is).
      I then add a new form and new gauge to original set of screens, try adding that to my code but it doesn't update...
      Are you sure you're calling the correct parameters? for example, are you calling the correct object ID and object index to write to?

      If you don't mind, would it be possible to send your Arduino code and genie project? I think it'd be easier for us to help you that way.

      Best regards,
      Michael

      Comment


      • #4
        Heya Michael

        Thanks for the reply. I'm using the same method of writing to the gauge as I have the others eg.

        genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 7, H2oTemp); Does this look OK?

        However, after much googling I think I have something I need to take a look at first. I've not much time to do it today, but will try to take a look tomorrow. Basically I think I've been writing to all gauges on every form, each loop. I've since read somewhere this can cause issues and maybe seeing as these were the last 2 to be added, they are the ones where it has started to cause a problem. My question is, whats the best way to write to an object only when that form is active? It appears I need to use the events handler and report to the arduino what form is active. I'm just struggling to understand that part, but haven't had the chance to implement anything yet, or read up on it too much.

        I had a quick few minutes and basically created a new project and added 5 coolgauges. The fifth one was updating (this is the first one that had a problem on my actual project) along with the others in real time. This is what makes me now believe I'm going about it the wrong way when it comes to writing to the 4d screen with 6 different forms.

        Any quick example of the form active and how to only write to that form would be a lot of help if you have that available, else I'll get studying as soon as I have some more free time!

        It's coming along nicely

        I'll bundle up the code tomorrow if I get a chance! Cheers

        Comment


        • #5
          Assuming you know the form the LCD boots to, every time you switch form just update a global variable with the new number and refer to that when writing to objects

          Comment


          • #6
            Hey guys. So I decided to re-format my code to only write to objects currently visible on each form. I'm not 100% sure I've done it right, and can't resolve this compile error

            [EDIT] - I have since realised I'm not using genieDequeueEvent. This is a copy paste error... I'll give this a go

            exit status 1
            'genieDequeueEvent' was not declared in this scope
            I think I have all the curly brackets in the right places. Further reading required. Have attached my code if anyone is interested.

            Cam
            Last edited by CaM; 5th December 2018, 06:06 PM.

            Comment


            • #7
              should be a period “.” after genie

              Comment


              • #8
                So I got it to compile but seem to be missing something. If someone has a spare min to take a look that'd be hugely appreciated.

                Thanks!

                https://drive.google.com/open?id=1rl...jafJW-DuvZ9GS2

                Seems I no longer have tx/rx flashing on the arduino
                Last edited by CaM; 5th December 2018, 06:32 PM.

                Comment


                • #9
                  was it working before?
                  what does it do? nothing at all on screen?
                  how are your connections? (common ground? shield??

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      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

                      Comment


                      • #12
                        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.

                        Comment

                        Working...
                        X