PDA

View Full Version : Basic Stamp and BLINKM Code Example



schreiner
11-18-2009, 01:05 PM
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, ["a"]
PAUSE 100
I2CIN 0, 1, [dev_address1]
DEBUG dev_address1

and this sequence:

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


Mike Green
11-18-2009, 02:21 PM
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>,[<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>,[<variable>]

To set a new address, you could use: I2COUT <pin>,$09,"A",[<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",[<major version>,<minor version>]

The stuff in <> brackets is descriptive, not to be taken literally.