Skip to content

Commit 593c8e1

Browse files
committed
NOT WORKING: add examples w/ nano33ble sensors
1 parent 9108d81 commit 593c8e1

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Arduino LSM9DS1 - Simple Accelerometer
3+
4+
This example reads the acceleration values from the LSM9DS1
5+
sensor and continuously prints them to the Serial Monitor
6+
or Serial Plotter.
7+
8+
The circuit:
9+
- Arduino Nano 33 BLE Sense
10+
11+
created 10 Jul 2019
12+
by Riccardo Rizzo
13+
14+
This example code is in the public domain.
15+
*/
16+
17+
#include <Arduino_LSM9DS1.h>
18+
19+
void setup() {
20+
Serial.begin(9600);
21+
while (!Serial);
22+
Serial.println("Started");
23+
24+
if (!IMU.begin()) {
25+
Serial.println("Failed to initialize IMU!");
26+
while (1);
27+
}
28+
29+
Serial.print("Accelerometer sample rate = ");
30+
Serial.print(IMU.accelerationSampleRate());
31+
Serial.println(" Hz");
32+
Serial.println();
33+
Serial.println("Acceleration in G's");
34+
Serial.println("X\tY\tZ");
35+
}
36+
37+
void loop() {
38+
float x, y, z;
39+
40+
if (IMU.accelerationAvailable()) {
41+
IMU.readAcceleration(x, y, z);
42+
43+
Serial.print(x);
44+
Serial.print('\t');
45+
Serial.print(y);
46+
Serial.print('\t');
47+
Serial.println(z);
48+
}
49+
delay(100);
50+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
APDS9960 - All sensor data from APDS9960
3+
4+
This example reads all data from the on-board APDS9960 sensor of the
5+
Nano 33 BLE Sense:
6+
- color RGB (red, green, blue)
7+
- proximity
8+
- gesture
9+
and prints updates to the Serial Monitor every 100 ms.
10+
11+
The circuit:
12+
- Arduino Nano 33 BLE Sense
13+
14+
This example code is in the public domain.
15+
*/
16+
17+
#include <Arduino_APDS9960.h>
18+
19+
void setup() {
20+
Serial.begin(9600);
21+
while (!Serial); // Wait for serial monitor to open
22+
23+
if (!APDS.begin()) {
24+
Serial.println("Error initializing APDS9960 sensor.");
25+
while (true); // Stop forever
26+
}
27+
}
28+
29+
int proximity = 0;
30+
int r = 0, g = 0, b = 0;
31+
unsigned long lastUpdate = 0;
32+
33+
void loop() {
34+
35+
// Check if a proximity reading is available.
36+
if (APDS.proximityAvailable()) {
37+
proximity = APDS.readProximity();
38+
}
39+
40+
// check if a gesture reading is available
41+
if (APDS.gestureAvailable()) {
42+
int gesture = APDS.readGesture();
43+
switch (gesture) {
44+
case GESTURE_UP:
45+
Serial.println("Detected UP gesture");
46+
break;
47+
48+
case GESTURE_DOWN:
49+
Serial.println("Detected DOWN gesture");
50+
break;
51+
52+
case GESTURE_LEFT:
53+
Serial.println("Detected LEFT gesture");
54+
break;
55+
56+
case GESTURE_RIGHT:
57+
Serial.println("Detected RIGHT gesture");
58+
break;
59+
60+
default:
61+
// ignore
62+
break;
63+
}
64+
}
65+
66+
// check if a color reading is available
67+
if (APDS.colorAvailable()) {
68+
APDS.readColor(r, g, b);
69+
}
70+
71+
// Print updates every 100ms
72+
if (millis() - lastUpdate > 100) {
73+
lastUpdate = millis();
74+
Serial.print("PR=");
75+
Serial.print(proximity);
76+
Serial.print(" rgb=");
77+
Serial.print(r);
78+
Serial.print(",");
79+
Serial.print(g);
80+
Serial.print(",");
81+
Serial.println(b);
82+
}
83+
delay(320);
84+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
HTS221 - Read Sensors
3+
4+
This example reads data from the on-board HTS221 sensor of the
5+
Nano 33 BLE Sense and prints the temperature and humidity sensor
6+
values to the Serial Monitor once a second.
7+
8+
The circuit:
9+
- Arduino Nano 33 BLE Sense
10+
11+
This example code is in the public domain.
12+
*/
13+
14+
#include <Arduino_HTS221.h>
15+
16+
void setup() {
17+
Serial.begin(9600);
18+
while (!Serial);
19+
20+
if (!HTS.begin()) {
21+
Serial.println("Failed to initialize humidity temperature sensor!");
22+
while (1);
23+
}
24+
}
25+
26+
void loop() {
27+
// read all the sensor values
28+
float temperature = HTS.readTemperature();
29+
float humidity = HTS.readHumidity();
30+
31+
// print each of the sensor values
32+
Serial.print("Temperature = ");
33+
Serial.print(temperature);
34+
Serial.println(" °C");
35+
36+
Serial.print("Humidity = ");
37+
Serial.print(humidity);
38+
Serial.println(" %");
39+
40+
// print an empty line
41+
Serial.println();
42+
43+
// wait 1 second to print again
44+
delay(1000);
45+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
void setup() {
2+
// put your setup code here, to run once:
3+
Serial.begin(115200);
4+
while (!Serial);
5+
Serial.tags();
6+
Humidity.start();
7+
Gesture.start();
8+
Accelerometer.start();
9+
}
10+
11+
void loop() {
12+
// put your main code here, to run repeatedly:
13+
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)