Skip to content

Commit d1a9a55

Browse files
committed
Add example breakouts
1 parent d6d9a5d commit d1a9a55

File tree

1 file changed

+56
-4
lines changed
  • content/learn/05.communication/01.wire

1 file changed

+56
-4
lines changed

content/learn/05.communication/01.wire/wire.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ An example of this is if you want to use Adafruits MCP9808 sensor module, you do
121121
To learn how to install libraries, check out our [guide to installing libraries](/software/ide-v2/tutorials/ide-v2-installing-a-library).
122122

123123
## Examples
124-
The remainder of this article is a collection of links to tutorials, schematics and code snippets that can get you off the ground with I2C.
125-
126-
124+
The remainder of this article is a collection of examples that can get you off the ground with I2C.
127125

128126
### Controller Reader
129127

@@ -279,4 +277,58 @@ void receiveEvent(int howMany)
279277
int x = Wire.read(); // receive byte as an integer
280278
Serial.println(x); // print the integer
281279
}
282-
```
280+
```
281+
282+
### Accelerometer
283+
284+
This code lets you read accelerometer data from a [Grove 6-Axis Accelerometer module](https://store.arduino.cc/collections/sensors/products/grove-6-axis-accelerometer-gyroscope) using the [seeed arduino LSM6DS3 library](https://www.arduino.cc/reference/en/libraries/seeed-arduino-lsm6ds3/).
285+
286+
```arduino
287+
#include "LSM6DS3.h"
288+
#include "Wire.h"
289+
290+
//Create instance of Accelerometer class
291+
LSM6DS3 accelerometer(I2C_MODE, 0x6A);
292+
293+
void setup() {
294+
// put your setup code here, to run once:
295+
Serial.begin(9600);
296+
while (!Serial);
297+
298+
if (accelerometer.begin() != 0) {
299+
Serial.println("LSM6DS3 not found, check your wiring.");
300+
} else {
301+
Serial.println("LSM6DS3 found!");
302+
}
303+
}
304+
305+
void loop() {
306+
//Gyroscope
307+
Serial.print("\nGyroscope:\n");
308+
Serial.print(" X1 = ");
309+
Serial.println(accelerometer.readFloatGyroX(), 4);
310+
Serial.print(" Y1 = ");
311+
Serial.println(accelerometer.readFloatGyroY(), 4);
312+
Serial.print(" Z1 = ");
313+
Serial.println(accelerometer.readFloatGyroZ(), 4);
314+
315+
//Accelerometer
316+
Serial.print("\nAccelerometer:\n");
317+
Serial.print(" X1 = ");
318+
Serial.println(accelerometer.readFloatAccelX(), 4);
319+
Serial.print(" Y1 = ");
320+
Serial.println(accelerometer.readFloatAccelY(), 4);
321+
Serial.print(" Z1 = ");
322+
Serial.println(accelerometer.readFloatAccelZ(), 4);
323+
324+
delay(1000);
325+
}
326+
```
327+
328+
### I2C OLED
329+
330+
[This code example](https://github.com/adafruit/Adafruit_SSD1306/blob/master/examples/ssd1306_128x32_i2c/ssd1306_128x32_i2c.ino) lets you write on an [Adafruit Monochrome I2C OLED display](https://www.adafruit.com/product/4440) using the popular ssd1306 driver
331+
332+
### I2C BME280
333+
[This code example](https://github.com/sparkfun/SparkFun_BME280_Arduino_Library/) lets you read temperature, humidity, pressure and altitude from [Sparkfuns BME280 breakout module](https://www.sparkfun.com/products/13676)
334+

0 commit comments

Comments
 (0)