Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp and BLINKM Code Example — Parallax Forums

Basic Stamp and BLINKM Code Example

schreinerschreiner Posts: 2
edited 2009-11-18 07:21 in BASIC Stamp
I have a BLINKM LED device which speaks I2C and am having getting code to work with the BS2px using the I2COUT and I2CIN commands.· Actually I have no problems sending commands to the BLINKM using the I2COUT command but I cannot read data from the BLINKM using the I2CIN command.· I try to read the I2C address of the BLINKM but only get 0x255 in return even though the device is at address 0x01.· The I2CIN command format in the help for PBASIC is confusing because the examples do not include the slaveid parameter.

Can anyone provide sample code or clear up my thinking of the I2CIN command specifically for its use with the BLINKM device?

I was trying these instruction sequences when atempting to read the address of the BLINKM:

I2COUT 0, 1, [noparse][[/noparse]"a"]
PAUSE 100
I2CIN 0, 1, [noparse][[/noparse]dev_address1]
DEBUG dev_address1

and this sequence:

I2CIN 0, 1, $61, [noparse][[/noparse]dev_address1]
DEBUG dev_address1

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-18 07:21
    You have to supply a device address with the I2COUT statement. By default, it's $09. The BLINKM will also respond to the $00 general call address, but only for output (I2COUT). The general call address doesn't work for input operations. To output a command to the BLINKM, you'd need to use:

    I2COUT <pin>,$09,<command> or I2COUT <pin>,$09,<command>,[noparse][[/noparse]<data>]

    If the BLINKM is the only I2C device attached, you could use $00 instead of $09.

    To read data from the BLINKM, you'd use:

    I2CIN <pin>,$09,<command>,[noparse][[/noparse]<variable>]

    To set a new address, you could use: I2COUT <pin>,$09,"A",[noparse][[/noparse]<new address>,$d0,$0d,<new address>]
    See the BLINKM documentation for an explanation of the above

    To read the BLINKM's version, you could use: I2CIN <pin>,$09,"z",[noparse][[/noparse]<major version>,<minor version>]

    The stuff in <> brackets is descriptive, not to be taken literally.
Sign In or Register to comment.