Skip to content

Commit 766e9a9

Browse files
committed
Add illustrations and code examples
1 parent d1a9a55 commit 766e9a9

File tree

5 files changed

+86
-3
lines changed

5 files changed

+86
-3
lines changed
62.7 KB
Loading
62.5 KB
Loading
105 KB
Loading
61.9 KB
Loading

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

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ void requestEvent() {
198198

199199
### Controller Writer
200200

201+
![Arduino Boards connected via I2C](./assets/I2Cb2b.png)
202+
201203
In some situations, it can be helpful to set up two (or more!) Arduino boards to share information with each other. In this example, two boards are programmed to communicate with one another in a Controller Writer/Peripheral Receiver configuration via the [I2C synchronous serial protocol](http://en.wikipedia.org/wiki/I2C). Several functions of Arduino's [Wire Library](https://www.arduino.cc/en/Reference/Wire) are used to accomplish this. Arduino 1, the Controller, is programmed to send 6 bytes of data every half second to a uniquely addressed Peripheral. Once that message is received, it can then be viewed in the Peripheral board's serial monitor window opened on the USB connected computer running the Arduino Software (IDE).
202204

203205
**Controller Writer Sketch**
@@ -280,6 +282,7 @@ void receiveEvent(int howMany)
280282
```
281283

282284
### Accelerometer
285+
![Grove IMU over I2C](./assets/GroveIMU.png)
283286

284287
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/).
285288

@@ -325,10 +328,90 @@ void loop() {
325328
}
326329
```
327330

331+
### I2C BMP280
332+
333+
![Qwiic BMP280 module](./assets/Qwiic-bmp280.png)
334+
335+
This code example lets you read the temperature over I2C from a BMP280 breakout module from Adafruit:
336+
```arduino
337+
#include <Wire.h>
338+
#include <Adafruit_BMP280.h>
339+
340+
//Create an instance of the BMP280 sensor
341+
Adafruit_BMP280 bmp;
342+
343+
void setup() {
344+
Serial.begin(9600);
345+
346+
// Start the sensor, and verify that it was found
347+
if (!bmp.begin()) {
348+
Serial.println("Sensor not found");
349+
while (1){}
350+
}
351+
352+
}
353+
354+
void loop() {
355+
// Read the values
356+
float temperature = bmp.readTemperature();
357+
358+
// Print to the Serial Monitor
359+
Serial.print("Temperature: ");
360+
Serial.print(temperature);
361+
Serial.println(" C");
362+
363+
Serial.println();
364+
delay(2000);
365+
}
366+
367+
```
368+
369+
328370
### I2C OLED
371+
![Grove OLED over I2C](./assets/GroveOLED.png)
372+
This code example draws a (very crude) version of the Arduino logo on a 128x64 I2C Grove OLED:
329373

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
374+
```arduino
375+
#include <Wire.h>
376+
#include <Adafruit_GFX.h>
377+
#include <Adafruit_SSD1306.h>
378+
379+
Adafruit_SSD1306 display(128, 64, &Wire, -1);
380+
381+
void setup() {
382+
Serial.begin(9600);
383+
384+
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
385+
Serial.println(F("SSD1306 not found"));
386+
while(1){}
387+
}
388+
389+
display.display();
390+
delay(2000);
391+
display.clearDisplay();
392+
393+
drawArduino();
394+
}
395+
396+
void loop() {
397+
}
398+
399+
void drawArduino(){
400+
display.clearDisplay();
331401
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)
402+
//Draw circles
403+
display.drawCircle(39, 32, 25, SSD1306_WHITE);
404+
display.drawCircle(89, 32, 25, SSD1306_WHITE);
334405
406+
//Draw minus
407+
display.drawLine(34, 32, 44, 32, SSD1306_WHITE);
408+
409+
// Draw plus
410+
display.drawLine(84, 32, 94, 32, SSD1306_WHITE);
411+
display.drawLine(89, 27, 89, 37, SSD1306_WHITE);
412+
413+
414+
//Render drawing
415+
display.display();
416+
}
417+
```

0 commit comments

Comments
 (0)