Announcement

Collapse
No announcement yet.

Example I2C setup for Iod-09 Module

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

  • Example I2C setup for Iod-09 Module

    Has someone made I2C work on a Iod-09. When I setup the customary way for Arduino (Wire) with specified pins (SDA,SCL) or pin numbers the display stops working - must not have the right numbers? or there is some trick?

  • #2
    Hello Carl,

    Welcome to the Forum,

    The IoD-09 has been successfully tested with I2C and the Wire library. You can use Wire.begin(2, 0); GPIO16 is not suitable as a I2C pin. It has also been tested with I2CDev library which is part of the Arduino core. It is essential that the Wire.begin is called before any I2CDev function is called.

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Thank you for solving the dilemma of pin names - there are many different schemes and names posted: e.g., GPIO02, GP02, processor pins, module pins - SDA,SCL (interestingly are defined as 4 and 5 in one of the include files) - simply using the last digit of the GPIO did not occur to me!

      Now a different issue: I have hooked up GPIO0 and GPIO2 to a scope and have written a snippet of a program that uses both I2C and GFX for testing. I'll include the program below - It is not intended to work - it is a portion of a program I used to talk I2C to a pulse-oxi chip I've used in the past. The part presented here purposely stalls at a reset command (there is no chip attached) to simply see the signals on a scope. What I have discovered (unfortunately) is that the GFX Backlight command stops the I2C clock from functioning. With the Backlight command commented out the I2C clock shows up fine on my scope. With the command in the program there is no clock signal - though the data signal is fine in either case. BTW, the situation exists with either order of begin, i.e. doesn't matter which of gfx.begin and Wire.begin occurs first.

      #include "ESP8266WiFi.h"
      #include "GFX4dIoD9.h"
      #include <Wire.h>

      GFX4dIoD9 gfx = GFX4dIoD9();

      #include "Test1-09Const.h" // Note. This file will not be created if there are no generated graphics

      void toOReg(int reg, int val) //used to send data to a specific register in a pulse oxi chip
      {
      Wire.beginTransmission(0x57);
      Wire.write(reg & 0xff);
      Wire.write(val & 0xff);
      Wire.endTransmission();
      }

      int fmOxi(int reg, int n) //used to get n bytes of data back from a pulse oxi chip
      {
      int val = 0;
      int i;
      Wire.beginTransmission(0x57);
      Wire.write(reg & 0xff);
      Wire.endTransmission();
      Wire.requestFrom(0x57,n);
      for(i=0;i<n;i++)
      {
      val = val << 8;
      val = val + Wire.read();
      }
      return val;
      }

      void setup()
      {
      gfx.begin();
      Wire.begin(2,0);
      gfx.Cls();
      gfx.ScrollEnable(false);
      // gfx.BacklightOn(true); //when commented out I2C clock works, when in I2C clock is always high
      gfx.Orientation(LANDSCAPE);
      gfx.SmoothScrollSpeed(5);
      gfx.TextColor(WHITE, BLACK); gfx.Font(2); gfx.TextSize(1);
      gfx.Open4dGFX("TEST1-~1"); // Opens DAT and GCI files for read using filename without extension. Note! Workshop generates files with Short filenames
      gfx.MoveTo(1,30);
      gfx.print("Hello World!!");
      delay(1000);
      toOReg(6,0x40); //a reset command sent out to a disconnected chip
      while(fmOxi(6,1) & 0x40) //will not end until a chip is in the circuit
      yield(); //appears to be necessary to avoid a timeout restart of the program

      } // end Setup **do not alter, remove or duplicate this line**

      void loop()
      {
      // put your main code here, to run repeatedly:
      yield(); // Required for ESP
      }

      Comment


      • #4
        Hi Carl,

        I am glad you got it working and my apologies for the Backlight bug. It has been rectified and the updated library will be available on Github shortly. The backlight function doesn't function for the IoD-09 but is left in for code compatibilty with the gen4-IoD series so that the only difference in code would be the screen size.

        Many thanks for pointing it out to us.

        Best regards

        Paul

        Comment


        • #5
          Hi Carl,

          I just noticed in your code in the comments after your first yield function. This is true if the ESP8266 is in a blocking loop. Many functions in the GFX4dIoD9 library have the yield() function built in, like large graphics, file functions and also internet functions. It is good practice to have a yield() in your main loop or in other code loops that are not part of the GFX4dIoD9 library. You may find that after you have made you project, because of the libraries yield() that you may be able to remove mainloop yield().

          Best regards

          Paul

          Comment


          • #6
            Thank you for helping understand the yield command better.
            I Finally got some I2C working well between the module and an ADS1014 ADC, which was my original goal. A word of warning to others (having sacrificed an Iod-09) - The Universal programmer apparently needs pin GPIO-0 (which is also one of the I2C pins) to program the device - It looks like some kind of clock on an O'scope. The universal programmer does not apparently connect either Iod-09 I2C pins (GP0 and GP2) to the programmer's breadboard - accessible pins - so I originally soldered jumpers to the Iod-9 pins GP0 and GP2 on the programmer, so I could breadboard up some I2C devices without removing the Iod-09 from the programmer. Don't do this.... If your I2C device interferes with pin GP0 (or you manage to blow the pin because it was pulled up to 5 volts... don't ask) you will get espcomm open and upload fail messages and the device won't program. I'm now developing with the Iod-09 in a double wide breadboard with jumpers to the universal programmer so I can connect or remove any programmer signals going to GPIO 0 and 2 before/after connecting an I2C device. This works fine for what I do. The new "A" version of Workshop seems to work well on my Windows 10 machine.

            Comment


            • #7
              Hi All!
              How can i use the RX/TX pin to I2C (what is the syntax)? Wire.begin(2,0) is the conventional syntax (GPIO0 and GPIO2), but how can i refer to the RX/TX pins?

              Comment


              • #8
                Hi,

                I have tried using I2C on RX, TX and only had success with a DAC. The default pins GPIO0 and GPIO2 work very well with the IoD-09 detached from the programming adapter. At boot the ESP8266 will push out a serial message on TX which I think causes the issue with I2C on these pins.

                If you would like to give it a try the syntax would be

                Wire.begin(1, 3)

                Which would setup I2C on TX, RX

                i hope this helps

                Best regards

                Paul

                Comment

                Working...
                X