No announcement yet.

Inexperienced mentor trying to do something difficult with I2C

  • Filter
  • Time
  • Show
Clear All
new posts

  • Inexperienced mentor trying to do something difficult with I2C


    I am trying to connect a PixyCam5 to my MR Core Interface Module (CIM). This has been found to be legal in the rules forums.

    Unfortunately, my eyes are bigger than my stomach, so to speak. I am in over my head.

    I've got the physical part connected, fairly easily. 4 wires, 2 for power (+/-) and 2 for comm (SCL and SDA). Using the MR Core Device Discovery software with the CIM connected directly to my PC, I can see the cam has been assigned address 0xa8. When I start polling, I can see results coming in.

    Here is my dilemma. There is a huge leap from hooking up the device and seeing that there is info coming from it, to actually understanding how to grab this data, split it up into its usable chunks, and then using these chunks in an OpMode to do something.

    The info from cmucam shows that the info coming in is:

    Object block format
    Bytes 16-bit word Description
    0, 1 y sync: 0xaa55=normal object, 0xaa56=color code object
    2, 3 y checksum (sum of all 16-bit words 2-6)
    4, 5 y signature number
    6, 7 y x center of object
    8, 9 y y center of object
    10, 11 y width of object
    12, 13 y height of object

    This info will come in at a rate of 50 times per second. Basically, we set the pixy to memorize a color. The Pixy can memorize up to 7 colors, called a signature. Once a color is memorized, the cam will return the x and y coordinates on the center of an object with that color, as well as the size of the object. The pixy can send info for many objects at one time, ie- 5 objects with one signature, 12 objects with a second signature, etc.

    I am trying to figure out how to use this, with the info from other posts on I2C that have been posted here, but the info is largely over my head. I'm not sure how to use (or even what these things are): buffers, byte arrays, etc.

    I'm not sure if I should create the pixy using an ftcLegacyDevice, and ftc I2Cdevice, etc.

    I hate it when folks on this forum have asked generally, "can someone please write me an op mode to do this..." but now I'm finding myself in a similar situation.

    I am making some assumptions here, but I am guessing that the procedure will look something like:

    WHEN [deviceinterfacemodule1] .I2cPortIsReady
    | CALL [deviceinterfacemodule1] .EnableI2cReadMode
    | physicalPort --> 0
    | I2cAddress --> 0xa8 {The block only accepts a numerical value, and when I use an online hex to decimal converter, a8 is 168, which is more than the max 127 allowable}
    | memAddress --> {I have no idea}
    | length --> 13

    Then I would need to dump information into different bucket for each object being tracked.
    After that I would need to be able to access the info in each bucket and compare that info for making decisions.

    For example, there might be five objects of signature 1 (a white ball) and 3 objects of signature 2 (yellow block). I would want to find the objects that are relatively the largest (and thus the closest).

    Like I said earlier, I know I am trying to do something complicated, and If I can get this to work, then I would be much farther along to understanding MIT app inventor FTC style.

    If there are any good online resources that anyone has come across for this stuff, please let me know.

    Thanks, Folks.

    7290 Jagwires

  • #2
    Hi. FTC team 8668 here. I do not have experience with the pixycam, but I have done some stuff with a pi and a webcam tracking objects. Heres some info on that:


    • #3
      I will have some help for you in a few hours. (I have to go to the dentist.)


      • #4
        First, regarding the I2cAddress. The number 0xA8 is the 8 bit number 1010 1000. This sounds crazy, but you need to shift that one bit to the right, so you get the 7 bit number 101 0100, which is 0x54. That matches the information I found on this site:

        Second, there is a new component called FtcI2cDeviceSynch in the beta version of App Inventor. FtcI2cDeviceSynch is a lot easier to use the because it handles all the "is the port ready" stuff behind the scenes. The beta version of App Inventor is available here:

        I don't have a PixyCam5, so I can't try it out myself, but I've posted a screenshots of blocks here:

        PS - There is a problem with the beta version of App Inventor if you run a linear opmode more than once. For now, I suggest only using FtcOpMode (not FtcLinearOpMode) with the beta.


        • #5
          Thanks for the assistance. I've been away for a couple weeks and getting back into the saddle. I'll work on the tips tonight.

          Thanks again.