Announcement

Collapse
No announcement yet.

Graph input from I2C sensor

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

  • Graph input from I2C sensor

    Hi
    I am a newbie here and looking for some advice.
    I would like to connect the uLCD-28PTU directly to a sensor through I2C and Graph the input values on the display.
    Are there any tutorials on I2C sensor inputs and graphing? Especially with a scalable y-axis?

    Thanks

  • #2


    Hi: You might want to read some of the postings in this thread....
    You will not be able to do it with the Visi Genie programming environment.

    If you want to use Visi Genie you will need an Arduino or Raspi to use I2C


    http://4d.websitetoolbox.com/post/i2c-6755113

    EDIT: found this thread too

    http://4d.websitetoolbox.com/post/Realtime-Graph-Chart-6353866


    Regards
    Bob

    Comment


    • #3


      You could also use ViSi and the supplied with Workshop Scope sample, combined with the P2012 appnote http://www.4dsystems.com.au/appnotes/
      Mark

      Comment


      • #4


        Thank you, I am working through the Nunchuck example now.
        I guess my question was related to the statement in D4004 for the Scope widget. It says "It is designed to be driven by an external host controller."
        Does this mean the scope cannot be driven by I2C input or analog inputs on the GPIO pins?
        It would be a shame if this were true.

        I apologize if this is addressed in another of the many app notes I have not read yet, no complaints though, it is nice to see a development tool supported by so many practical examples for a change. Most manufacturers assume their customers are all multi-skilled software engineers.

        Comment


        • #5


          That app note is for Genie, 'which is designed to be driven by an external host controller' (at least in this case, there are certain totally autonomous things Genie can do).

          When you use Visi you can certainly drive the scope by I2C or the analogue pins
          Mark

          Comment


          • #6


            Thank you.
            A silly question, where is the code for the Wii Nunchuck App note P2012?
            I looked on my PC to see if it was downloaded as part of the Workshop but cant see it.

            Type it manually? I am not sure all the code blocks are in the app note.

            Thanks

            Comment


            • #7


              Use the zip, it contains the source as well as the app note
              Mark

              Comment


              • #8


                Ahhh...Duh
                Sorry

                Comment


                • #9


                  Mark
                  Could you explain the syntax and function of the gfx_Scope function? It is not in the reference manual.
                  I derive a variable value from my sensor which ends up as newY1 in my example below. The value is 23 and can go up to 100 and down to 10 or so. It prints correctly and also outputs to the LedDigits correctly when i enable them.

                  I want to drive the scope trace from this value?
                  the other scope examples drove the scope from a Sin value rather than an input value so i couldnt follow well, but from what i understood the newY1 is the current value and oldY1 would be the previous value? Each time through the loop I could make oldY1 := newY1?

                  Thanks

                  Comment


                  • #10
                    Thought i would add my sample code to explain.
                    Thanks

                    Code:
                    #platform "uLCD-28PTU"
                    #inherit "4DGL_16bitColours.fnc"
                    #inherit "VisualConst.inc"
                    #inherit "COOLGAUGE4Const.inc"
                    #inherit "LEDDIGITSDISPLAY.INC"
                    #inherit "Scope4.inc"
                    
                    #constant device    0x80
                    #constant speed     I2C_SLOW
                    
                    
                    var data;
                    var data1;
                    var myTemp;
                    var myTemp1;
                    var myTempTot;
                    var myTempC;
                    var myRh;
                    var myRhTot;
                    var myRetTemp;
                    var myRetRh;
                    var oldY1 := 0;
                    var newY1;
                    
                    func receive()
                        I2C_Open(speed);
                        I2C_Start();
                        I2C_Write(device);
                        I2C_Write(0xE5);
                        I2C_Restart();
                        I2C_Write(device + 0x01);
                    
                        data:=I2C_Read();
                        I2C_Ack();
                    
                        data1:=I2C_Read();
                    
                        I2C_Nack();
                        I2C_Stop();
                        //I2C_Ack();
                    
                        I2C_Start();
                        I2C_Write(device);
                        I2C_Write(0xE0);
                        I2C_Restart();
                        I2C_Write(device + 0x01);
                        myTemp:=I2C_Read();
                        I2C_Ack();
                        myTemp1:=I2C_Read();
                        I2C_Nack();
                    
                        I2C_Stop();
                    
                    endfunc
                    
                     func RetTemp(var valin)
                        var li[2] ;
                        umul_1616(li, valin,17572) ;
                        return li[1] - 4685 ;
                    endfunc
                    
                       func RetRh(var valin)
                        var li[2] ;
                        umul_1616(li, valin,12500) ;
                        return li[1] - 600 ;
                    endfunc
                    
                    
                    func main()
                    //  Uncomment the following if uSD images used.
                    
                        putstr("Mounting...\n");
                        if (!(disk:=file_Mount()))
                            while(!(disk :=file_Mount()))
                                putstr("Drive not mounted...");
                                pause(200);
                                gfx_Cls();
                                pause(200);
                            wend
                        endif
                        gfx_TransparentColour(0x0020);
                        gfx_Transparency(ON);
                    
                    //    hndl := file_LoadImageControl("COOLGA~4.dat", "COOLGA~4.gci", 1);
                     //   img_Show(hndl, iLeddigits1);  // show all digits at 0, only do this once
                    
                        // Scope1 1.0 generated 2/26/2014 9:50:36 AM
                        // Create empty initial scope
                       gfx_RectangleFilled(12, 92, 231, 151, DARKBLUE) ;
                        gfx_Hline(92 + 0, 12, 231, YELLOW) ;
                        Graticule(12, 92, 231, 211, 10,  10, 0x0280) ;
                    
                    
                    repeat
                        receive();
                        myRhTot := (data<<8) + data1;
                        myRetRh := RetRh(myRhTot);
                        myTempTot := myTemp<<8 + myTemp1;
                        myRetTemp := RetTemp(myTempTot);
                    
                        //newY1 := myRetTemp / 100;
                        newY1 := myRetRh / 100;
                    
                           // print(myRetTemp);
                            //print(newY1);
                    
                        // Leddigits1 1.0 generated 2/25/2014 11:51:50 PM
                    
                    //    ledDigitsDisplay(myRetTemp, iLeddigits1+1, 20, 4, 1, 52, 0) ;
                        pause(1000);
                    
                    
                    
                        // draw and update scope
                            Graticule(12, 92, 231, 151, 10,  10, 0x0280) ;
                            gfx_Scope(12, 220, 91, 220, 0, 20, DARKBLUE,
                                  oldY1, newY1, LIME, 0,0,0, 0,0,0, 0,0,0  ;
                        gfx_Hline(152 + 0, 28, 231, YELLOW) ;
                    
                        oldY1 := newY1;
                    
                    
                        forever
                    
                    endfunc

                    Comment


                    • #11


                      Other than to set the 0th element of oldY to -1 before the first call to scope, you should never touch any oldY values, they are used internally by the scope to 'undraw' the old values.

                      Have a look at the Picaso ViSi scope sample, it might help a bit with some of the parameters and what they are for.

                      Also the ViSi Genie reference describes some of the parameters of the scope widget in mode detail and most of those parameters relate directly to parameters that you are using.
                      Mark

                      Comment


                      • #12


                        Mark, I understand the scope layout, and parameters.as set in Visi genie.

                        What i dont understand is how to change what drives the trace. In all the examples, the trace is driven by for-next loops that fill 1000 values into buffers and generate a sine wave for a nice demo. However nothing shows me how to drive it from a real world value.
                        My sensor output is only updated once per minute and the value could be between 1 and 100 max.

                        So please could you explain how to construct the gfx_scope and mem_Copy statements to use a variable X to plot the scope?

                        Appreciate your help

                        Comment


                        • #13


                          So you only want to update 1 value at a time?

                          Use the memcopy to move all values 1 towards the start (discarding the old start) and place the new value in the last value
                          Mark

                          Comment

                          Working...
                          X