I2C Port Scanner

The following port scanner prints out the address (in decimal) of each of the I2C devices found on the I2C bus:

(defun scn () 
  (dotimes (p 127)
    (with-i2c (str p)
      (when str (print p)))))

It's useful for checking that you have got the correct I2C address for a sensor or other I2C device. If the device doesn't appear it may indicate that you need to add pullups on the SDA and SCL lines. A good choice is about 4.7kΩ.