0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ArduinoAdvent Calendar 2021

Day 17

vistaでstm32duino その17

Posted at

#概要

vistaでstm32duinoやってみた。
i2c scanner、やってみた。

#写真

DSCN0549.JPG

#サンプルコード

#include <Wire.h>

void setup() {
	Serial.begin(9600);
	Wire.begin();
	Serial.println("\nI2C Scanner");
}

void loop() {
	byte error, 
		address;
	int nDevices;
	Serial.println("Scanning...");
	nDevices = 0;
	for (address = 1; address < 127; address++) 
	{
		Wire.beginTransmission(address);
		error = Wire.endTransmission();
		if (error == 0) 
		{
			Serial.print("I2C device found at address 0x");
			if (address < 16) 
				Serial.print("0");
			Serial.println(address, HEX);
			nDevices++;
		}
		else if (error == 4) 
		{
			Serial.print("Unknown error at address 0x");
			if (address < 16) 
				Serial.print("0");
			Serial.println(address, HEX);
		}
	}
	if (nDevices == 0)
		Serial.println("No I2C devices found");
	else
		Serial.println("done");
	delay(5000);
}





#結果

Scanning...
I2C device found at address 0x27
done
Scanning...
I2C device found at address 0x27
done
Scanning...
I2C device found at address 0x27
done


以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?