Skip to content

Commit a371820

Browse files
committed
Merge branch 'main' of https://github.com/ITPNYU/physcomp
2 parents 7758921 + 22e6cf6 commit a371820

File tree

7 files changed

+1070
-160
lines changed

7 files changed

+1070
-160
lines changed
84.5 KB
Loading

Labs/Intro_to_SparkFun_Qwiic_I2C_Shield_for_Arduino_Nano/Diagram.svg

Lines changed: 402 additions & 0 deletions
Loading
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#include <SPI.h>
2+
#include <Wire.h>
3+
#include <Adafruit_GFX.h>
4+
#include <Adafruit_SSD1306.h>
5+
#include "Adafruit_SHTC3.h"
6+
#include <Adafruit_Sensor.h>
7+
#include "Adafruit_BMP3XX.h"
8+
#include "Adafruit_APDS9960.h"
9+
Adafruit_APDS9960 apds;
10+
11+
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
12+
#define BMP_SCK 13
13+
#define BMP_MISO 12
14+
#define BMP_MOSI 11
15+
#define BMP_CS 10
16+
17+
#define SEALEVELPRESSURE_HPA (1013.25)
18+
19+
Adafruit_BMP3XX bmp;
20+
21+
#define SCREEN_WIDTH 128 // OLED display width, in pixels
22+
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
23+
24+
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
25+
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
26+
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
27+
28+
bool showingTempAndHumidity = true;
29+
30+
31+
void setup() {
32+
Serial.begin(115200);
33+
34+
// Setting up SHTC3
35+
if (!shtc3.begin()) {
36+
Serial.println("Couldn't find SHTC3");
37+
while (1) delay(1);
38+
}
39+
Serial.println("Found SHTC3 sensor");
40+
41+
// Setting up BMP390
42+
if (!bmp.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
43+
Serial.println("Could not find a valid BMP3 sensor, check wiring!");
44+
while (1)
45+
;
46+
}
47+
// Set up oversampling and filter initialization
48+
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
49+
bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
50+
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
51+
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
52+
53+
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
54+
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
55+
Serial.println(F("SSD1306 allocation failed"));
56+
for (;;)
57+
; // Don't proceed, loop forever
58+
}
59+
60+
display.setTextSize(1); // Normal 1:1 pixel scale
61+
display.setTextColor(SSD1306_WHITE); // Draw white text
62+
display.cp437(true); // Use full 256 char 'Code Page 437' font
63+
64+
// Setting up Adafruit_APDS9960
65+
if(!apds.begin()){
66+
Serial.println("failed to initialize device! Please check your wiring.");
67+
}
68+
apds.enableProximity(true);
69+
apds.enableGesture(true);
70+
}
71+
72+
void loop() {
73+
sensors_event_t humidity, temp;
74+
75+
uint8_t gesture = apds.readGesture();
76+
if(gesture == APDS9960_LEFT || gesture == APDS9960_RIGHT){
77+
showingTempAndHumidity = !showingTempAndHumidity;
78+
}
79+
80+
shtc3.getEvent(&humidity, &temp); // populate temp and humidity objects with fresh data
81+
display.clearDisplay();
82+
display.setCursor(0, 0);
83+
if (showingTempAndHumidity) {
84+
display.println("Temperature: ");
85+
display.print(temp.temperature);
86+
display.println(" degree C");
87+
display.println("");
88+
89+
display.println("Humidity: ");
90+
display.print(humidity.relative_humidity);
91+
display.println("% rH");
92+
}
93+
94+
// Serial.println(bmp.performReading());
95+
if (!showingTempAndHumidity) {
96+
display.println("Pressure: ");
97+
display.print(bmp.pressure / 100.0);
98+
display.println(" hPa");
99+
display.println("");
100+
101+
display.println("Approx.Altitude: ");
102+
display.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
103+
display.println(" m");
104+
}
105+
106+
showingTempAndHumidity = !showingTempAndHumidity;
107+
display.display();
108+
delay(3000);
109+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Intro to SparkFun Qwiic I2C Shield for Arduino Nano
2+
3+
This lab introduces the SparkFun Qwiic I2C Shield for Arduino Nano, which provides an easy way to connect I2C devices to your Arduino Nano.
4+
5+
## Overview
6+
7+
The SparkFun Qwiic I2C Shield for Arduino Nano is a breakout board that:
8+
- Provides Qwiic connectors for easy I2C device connections
9+
- Maintains compatibility with the Arduino Nano form factor
10+
- Simplifies wiring by eliminating the need for pull-up resistors
11+
12+
## Resources
13+
14+
- [Lab Documentation](https://itp.nyu.edu/physcomp/?page_id=12623)
15+
- [SparkFun Qwiic I2C Shield Product Page](https://www.sparkfun.com/sparkfun-qwiic-shield-for-arduino-nano.html)
16+
17+
## Getting Started
18+
19+
1. Connect the shield to your Arduino Nano
20+
2. Connect I2C devices using Qwiic cables
21+
3. Upload the example code to your Arduino Nano
22+
23+
## Example Code
24+
25+
This repository contains example code demonstrating how to:
26+
- Initialize I2C communication
27+
- Read from and write to I2C devices
28+
- Handle multiple I2C devices on the same bus
29+
30+
## Requirements
31+
32+
- Arduino Nano
33+
- SparkFun Qwiic I2C Shield
34+
- Qwiic-compatible I2C devices
35+
- Arduino IDE or compatible development environment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <SPI.h>
2+
#include <Wire.h>
3+
#include <Adafruit_GFX.h>
4+
#include <Adafruit_SSD1306.h>
5+
#include "Adafruit_SHTC3.h"
6+
7+
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
8+
9+
#define SCREEN_WIDTH 128 // OLED display width, in pixels
10+
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
11+
12+
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
13+
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
14+
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
15+
16+
17+
void setup() {
18+
Serial.begin(115200);
19+
20+
// Setting up SHTC3
21+
if (!shtc3.begin()) {
22+
Serial.println("Couldn't find SHTC3");
23+
while (1) delay(1);
24+
}
25+
Serial.println("Found SHTC3 sensor");
26+
27+
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
28+
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
29+
Serial.println(F("SSD1306 allocation failed"));
30+
for (;;)
31+
; // Don't proceed, loop forever
32+
}
33+
34+
display.setTextSize(1); // Normal 1:1 pixel scale
35+
display.setTextColor(SSD1306_WHITE); // Draw white text
36+
display.cp437(true); // Use full 256 char 'Code Page 437' font
37+
}
38+
39+
void loop() {
40+
sensors_event_t humidity, temp;
41+
42+
shtc3.getEvent(&humidity, &temp); // populate temp and humidity objects with fresh data
43+
display.clearDisplay();
44+
display.setCursor(0, 0);
45+
46+
display.println("Temperature: ");
47+
display.print(temp.temperature);
48+
display.println(" degree C");
49+
display.println("");
50+
51+
display.println("Humidity: ");
52+
display.print(humidity.relative_humidity);
53+
display.println("% rH");
54+
55+
display.display();
56+
delay(3000);
57+
}

0 commit comments

Comments
 (0)