Announcement

Collapse
No announcement yet.

scanner i2c

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

  • scanner i2c

    Hello,

    I have a gen4-uLCD-70DCT-CLB and I need to know how I can do a scan of the i2c.

    The purpose is : When the user presses the button ( for example : two digits) in the display 4D then the selected number is sent to an xip, but before doing this I need 4D to show me a scan of the i2c.


    I don't know how I can do it, I need help.



    Thank you so much.




  • #2
    Hello,

    Welcome to the forum.

    We don't have an example code for an I2c scanner. You can sometimes get ideas from code on a different platform and change it to suit. I found this Arduino version https://playground.arduino.cc/Main/I2cScanner and it explains how it is acheived on an Arduino.

    The I2C commands for you display can be found on page 268 of this datasheet http://www.4dsystems.com.au/productp...ions_R_2_0.pdf

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Hello,


      Thank you!!!!


      But I have done the part of the scanner and I need assign the pins of the chip ( PCF8574) like outputs. In 4D , i dont see the library or something like arduino.


      How can I do it?



      Thank you in advance.

      Comment


      • #4
        Hello,

        There isnt a library function like the the Arduino Wire library. To set the I2C port on 4dgl you use this command.

        I2C1_Open(I2C_MED, PA2, PA3); // Open the I2C port in 400KHz mode.

        which would assign the pins PA2 and PA3 for I2C

        I hope this helps

        Paul

        Comment


        • #5
          Hello,

          I thought it was PA14 and PA15. I dont understand how I can do this <xip1.pinMode(1,OUTPUT)> in 4dgl.


          Thank you so much

          Comment


          • #6
            Hello,

            It can be assigned to any pin but yes PA14 and PA15 are special case I2C pins and feature slew rate control. The command above sets the input output ports for you for I2C. Can you post you I2C scanner code original to see how it can be modified for 4dgl

            Best regards

            Paul

            Comment


            • #7
              Hello,

              My original code is with arduino. I attach the file.


              Thank you so much , Paul
              Attached Files

              Comment


              • #8
                Hello,

                Thanks for that. I understand it a bit better now. The Arduino sketch uses a library for the PCF8574 and the commands you showed me earlier relate to that library. As we don't have a library for that device a function should be created with I2C commands to talk specifically to that device. I will have a look through the PCF8574 datasheet to see what is needed.

                Best regards

                Paul

                Comment


                • #9
                  Hello,


                  Thank you very much for helping me, I hope you can tell me something soon to see how we can do this function.



                  Bes regards, Paul

                  Comment


                  • #10
                    usually, like the arduino, the way to detect if a device exists or not is scanning all 127 addresses by simply opening and closing the connection to that device (without needing to transmit data), with a slight delay ~5ms per address, working addresses would return an ACK, print those ones in your app and thats it

                    Comment


                    • #11
                      Hello,
                      i am trying to control a pcf8574, i2c 8 bit pin expander. I have it working on the Arduino, and I’m trying to connect it directly to my uOLED 32028-P1 by way of a P1-EB expansion board. When I do an i2c scan, it reports 40 11 as the address, which I took to mean 0x40. The problem is according to the data sheet on the chip, grounding pins A0,A1, and A3 is supposed to be 0x20. I’ve modified the Arduino code to read and write to the pins but it’s not working, it’s not responding.
                      Has anyone tried to connect the display to this chip?

                      Thanks for your help,

                      Mark

                      Comment


                      • #12
                        I meant to say grounding A0,A1,A2 is a 0x20 address

                        Comment


                        • #13
                          hello,
                          here's my code, trying to control pcf8574 directly connected to the i2c pins of my uOLED 32028-P1. Here's my code:

                          #platform "uOLED-32028-P1"

                          func main()
                          I2C_Open(I2C_SLOW);
                          I2C_Idle();
                          I2C_Start(); // Generate Start condition
                          I2C_Write(0x42);
                          I2C_Write(0b00000000);
                          I2C_Idle();
                          I2C_Stop();
                          repeat

                          On();
                          pause(500);
                          Off();

                          forever

                          endfunc

                          func On()

                          I2C_Idle();
                          I2C_Start(); // Generate Start condition
                          I2C_Write(0x42);
                          I2C_Idle();
                          I2C_Write(0b00000011);
                          I2C_Idle();
                          I2C_Stop();

                          endfunc

                          func Off()

                          I2C_Idle();
                          I2C_Start(); // Generate Start condition
                          I2C_Write(0x42);
                          I2C_Idle();
                          I2C_Write(0b00000000);
                          I2C_Idle();
                          I2C_Stop();

                          endfunc

                          What happens is that it does the first function, turns on, but that it, no matter what I do it will only execute the first function. Any help would be appreciated.

                          Thank you,

                          Mark

                          Comment


                          • #14
                            Ok, I found this in another place on the forum and it works, I guess it needed an additional pause that I didn't have. Thanks anyway.

                            func main()
                            I2C_Open(I2C_SLOW);
                            writebyte(0b1000010, 0b00000000);

                            repeat

                            writebyte(0b1000010, 0b00000011);
                            pause(1000);
                            writebyte(0b1000010, 0b00000000);
                            pause(1000);
                            forever

                            endfunc

                            func writebyte(var address, var value)
                            I2C_Idle();
                            I2C_Start();
                            I2C_Write(address);
                            I2C_Idle();
                            I2C_Start();
                            I2C_Write(value);
                            I2C_Idle();
                            I2C_Stop();
                            endfunc

                            Comment

                            Working...
                            X