Last active
July 22, 2018 14:03
-
-
Save rena2019/7621ea14990427accdb14e56f4ae59c1 to your computer and use it in GitHub Desktop.
This file contains 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
#include <Arduino.h> | |
#include <Wire.h> | |
// Elechouse PN532 v3 board | |
// Switch: 1, 0 for I2C | |
#define SDA1 21 | |
#define SCL1 22 | |
TwoWire I2Cone = TwoWire(0); | |
void scan1(){ | |
Serial.println("Scanning I2C Addresses"); | |
uint8_t cnt=0; | |
for(uint8_t i=0;i<128;i++){ | |
I2Cone.beginTransmission(i); | |
uint8_t ec=I2Cone.endTransmission(true); | |
if(ec==0){ | |
if(i<16)Serial.print('0'); | |
Serial.print(i,HEX); | |
cnt++; | |
} | |
else Serial.print(".."); | |
Serial.print(' '); | |
if ((i&0x0f)==0x0f)Serial.println(); | |
} | |
Serial.print("Scan Completed, "); | |
Serial.print(cnt); | |
Serial.println(" I2C Devices found."); | |
} | |
void setup() { | |
Serial.begin(115200); | |
I2Cone.begin(SDA1,SCL1,400000); // SDA pin 21, SCL pin 22 | |
} | |
void loop() { | |
scan1(); | |
Serial.println(); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment