I did this way and have an error
Code: Select all
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire_slave.h>
//use IIC2
//TwoWire WIRE2 (2,I2C_FAST_MODE);
//#define Wire WIRE2
//////////////////
#define OLED_RESET -1 // use -1 if no reset pin on OLED board
// use second I2C bus on STM32F103
// TwoWire Wire2(SDA2, SCL2);
TwoWire Wire2(PB11, PB10);
Adafruit_SSD1306 Display
// below is for a 128x64 OLED. Other option is 128x32 for smaller OLED
(128, 64, &Wire2, OLED_RESET);
//////////////////
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the 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); // wait 5 seconds for next scan
}
////////////////////
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // if nothing is displayed using 0x3C, try 0x3D
// Display1
Display1.clearDisplay();
Display1.setTextSize(2);
Display1.setTextColor(WHITE, BLACK);
Display1.setCursor(0, 0 );
Display1.println("Display");
Display1.println("I2C #2 @ 3C");
Display1.display();
////////////////////
error
Arduino: 1.8.12 (Mac OS X), Board: "Generic STM32F103C series, STM32F103C8 (20k RAM. 64k Flash), Serial, 72Mhz (Normal), Smallest (default)"
i2c_scanner_wire:38:25: error: no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'
TwoWire Wire2(PB11, PB10);
^
In file included from /var/folders/yj/fygyw1t57zggv9lf50h08zr80000gn/T/arduino_modified_sketch_609513/i2c_scanner_wire.ino:27:0:
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate: TwoWire::TwoWire(i2c_dev*)
TwoWire(i2c_dev* i2cDevice);
^~~~~~~
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate expects 1 argument, 2 provided
i2c_scanner_wire:40:1: error: 'Adafruit_SSD1306' does not name a type
Adafruit_SSD1306 Display
^~~~~~~~~~~~~~~~
i2c_scanner_wire:90:4: error: 'Display1' does not name a type
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // if nothing is displayed using 0x3C, try 0x3D
^~~~~~~~
i2c_scanner_wire:93:3: error: 'Display1' does not name a type
Display1.clearDisplay();
^~~~~~~~
i2c_scanner_wire:94:3: error: 'Display1' does not name a type
Display1.setTextSize(2);
^~~~~~~~
i2c_scanner_wire:95:3: error: 'Display1' does not name a type
Display1.setTextColor(WHITE, BLACK);
^~~~~~~~
i2c_scanner_wire:96:3: error: 'Display1' does not name a type
Display1.setCursor(0, 0 );
^~~~~~~~
i2c_scanner_wire:97:3: error: 'Display1' does not name a type
Display1.println("Display");
^~~~~~~~
i2c_scanner_wire:98:3: error: 'Display1' does not name a type
Display1.println("I2C #2 @ 3C");
^~~~~~~~
i2c_scanner_wire:99:3: error: 'Display1' does not name a type
Display1.display();
^~~~~~~~
exit status 1
no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'