Announcement

Collapse
No announcement yet.

Need Blocks example of using Multiple MR Color Sensors with MR Core Device Interface

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

  • Need Blocks example of using Multiple MR Color Sensors with MR Core Device Interface

    A Modern Robotics color sensor has a default I2C address of 3C hexadecimal and that address is assumed by an op mode written with Blocks unless you specify otherwise.
    I have assign two color sensors different hexadecimal address using Modern Robotics Core Device Discovery.
    In Blocks I have tried setting the new address using

  • #2
    Continued...(prior post didn't work).
    In Blocks I have tried setting the new address using Set color sensor name.i2cAddress7Bit or Set color sensor name.i2cAddres8Bit to numeric value.
    I can only get one to work at a time.
    Does anyone have a Blocks example of using multiple MR color sensors with MR Core Device Interface? Please specify what address each sensor has.
    When should one use the set.7Bit or set.8Bit call?

    Comment


    • #3
      What values are you giving to Modern Robotics Core Device Discovery and Set color sensor name.i2cAddress7Bit?

      Comment


      • #4
        I set the address of the first color sensor (c1) to 0x12 and the second (c2) to 0x14. I tried many values and I have tried 7Bit and 8Bit. I assumed that values needed are decimal so I entered 18 and 20. I also read in Bruce Schafer's Blocks reference manual... wait, that's you! that the 8 bit values are bit shifted so I tried subtracting 16 from those numbers. I never got more than one sensor to work. I have attached a .png of my Blocks code with the c2 color sensor commented out.

        Thanks for the great Blocks videos by the way. I am using them at our team meetings, to give all students a broad understanding of programming and the electronics. I am hoping to get them up to the level of being able to use tensor flow.

        -Steve
        X-TankAuto.png

        Comment


        • #5
          When I try zooming in on your PNG it gets fuzzy.

          Instead of subtracting 16 try dividing by 2.

          It's getting late so I may have a clearer suggestion or question tomorrow. In the meantime if you have time, you could email the PNG to me at ftcblockshelp@ortop.org

          Comment


          • #6
            I went back and read my own documentation. I'm embarrassed to say when you are using 8-bit addresses you need to multiply the I2C port number by 2 rather than divide by 2.

            Since I can't read the PNG file you provided above, I can't tell whether you have set up two color sensors in your config file. I think you will need two.

            Please email the PNG when you have a chance.

            Comment


            • #7
              Sorry, the snow here in Seattle has delayed my response. I have tried dividing the address by 2 and multiplying by 2. Neither seem to work. I am including two blocks images (a 7 bit and an 8 bit) and a photo of the config file. If they don't work I will email them to you.
              Config.jpg
              Blocks-2MR-color-7bit.png
              Blocks-2MR-color-8bit.png
              Attached Files

              Comment


              • #8
                Thanks for the additional info and PNG files. Just to be clear, did you try 18 and 20 for 7 bit and 36 and 40 for 8 bit?

                Comment


                • #9
                  Please ignore my last two replies. I managed to double confuse myself on the way the addresses are shifted. Based on your configuring the sensor addresses using the Core Device Discovery utility as 0x12 and 0x14, if you use i2cAddress8Bit, the addresses should be 18 and 20 (decimal) as you described in an earlier message, rather than the 24 and 28 in the PNG you attached today. If you use 7-bit addresses, the values used for the pair of "set I2cAddress7Bit" blocks should be 9 and 10.
                  I also recommend you add a pair of "call <color sensor name>.enableLed" blocks -- one for each sensor to the opmode's initialization sectioin or just after the wait-for-start. Then check to see if both LEDs turn on.
                  Let me whether this helps or not.

                  Comment


                  • #10
                    Both setting the 7 bit to 9 and 10 and setting the 8 bit to 18 and 20 worked!
                    I though I had tried this (the 8 bit values) but I may have had my wires in the wrong ports on the core device interface.
                    I was unplugging things a bunch to test and I thought the order didn't matter, but tonight I made sure that the order
                    matched the config file. The ports aren't really labeled on the device.
                    The color sensor lights are on by default, and seem to work without the call <color sensor>.enabled.
                    They don't work with the sensors disabled.
                    It seems like the set I2cAddress8bit is the most logical to use and I am not sure why one would use the 7 bit?
                    Thanks for your help. I have attached the working opmode for anyone's reference.
                    Attached Files

                    Comment


                    • #11
                      The last attachment was hard to read. I am trying again as a photo.

                      Comment


                      • #12
                        That wasn't any better.

                        Comment


                        • #13
                          Thanks for the good news!

                          I can't think of a good reason why both 7-bit and 8-bit are needed so I'll make up a reason why they are both available: The I2C addresses are really 7-bits but bytes have 8 bits and way back when, someone decided the 7 address bits should be assigned to high 7 bits of an 8-bit register. Perhaps the low bit is or was used as a status bit in some implementations. That's why 8-bit addresses must always be even. Later, somewhere else decided that 7-bit addresses should be in the low 7-bits rather than the high seven bits. (Assuming we number the bits in a byte 0 through 7, the two formats both use bits 1 through 6.) So, the 7-bit format was added to an I2C software library for flexibility. The two interfaces were included in the Java library and when FTC Blocks was invented, blocks were created for both formats to match what was available in Java.

                          Comment

                          Working...
                          X