Created
May 4, 2018 23:15
-
-
Save ppazos/5ebfc79d9ef2d7d20da28e6f42df35b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import com.pi4j.io.i2c.I2CBus; | |
import com.pi4j.io.i2c.I2CDevice; | |
import com.pi4j.io.i2c.I2CFactory; | |
import com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; | |
import com.pi4j.platform.PlatformAlreadyAssignedException; | |
import com.pi4j.util.Console; | |
public class I2CScanner { | |
public static final int TOUCH_KEYPAD_ADDR = 0x57; // address pin not connected (FLOATING) | |
public static void main(String[] args) | |
throws InterruptedException, PlatformAlreadyAssignedException, IOException, UnsupportedBusNumberException | |
{ | |
final Console console = new Console(); | |
console.title("<-- The Pi4J Project -->", "I2C Scanner"); | |
console.promptForExit(); | |
console.println("Vamos a ver..."); | |
I2CBus i2c = I2CFactory.getInstance(I2CBus.BUS_1); | |
// create an I2C device for an individual device on the bus that you want to communicate with | |
// in this example we will use the default address for the TSL2561 chip which is 0x39. | |
I2CDevice device; // = i2c.getDevice(TSL2561_ADDR); | |
String desc; | |
for (int i = 0; i<128; i++) | |
{ | |
device = i2c.getDevice(i); | |
try { | |
device.read(); | |
desc = "0x" + Integer.toHexString(i); | |
console.println(desc); | |
} | |
catch (Exception e) | |
{ | |
console.println(e.getMessage()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment