Skip to content

Commit 5d7d725

Browse files
authored
Merge pull request #35 from edge-ml/board/nanoV2
Board/nano v2
2 parents 5f8c8f6 + 57db181 commit 5d7d725

19 files changed

+676
-38
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EdgeML-Arduino
2-
version=1.3.3
2+
version=1.3.4
33
author=edge-ml
44
maintainer=edge-ml <edge-ml@teco.edu>
55
sentence=Library to use the Nicla Sense ME and BLE Nano 33 with edge-ml.

src/EdgeML.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef Edge_ML_BASE_H_
66
#define Edge_ML_BASE_H_
77

8+
#include <config/flags.h>
9+
810
// arduino-libraries/Arduino_BHY2@^1.0.6
911

1012
#include <config/flags.h>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "config/flags.h"
2+
#if defined NORMAL_BOARD
3+
4+
#include "APDS_Sensor_NanoV2.h"
5+
6+
void APDS_Sensor_NanoV2::start() {
7+
if (APDS.begin()) {
8+
available = true;
9+
}
10+
}
11+
12+
void APDS_Sensor_NanoV2::end() {
13+
APDS.end();
14+
available = false;
15+
}
16+
17+
void APDS_Sensor_NanoV2::get_data(int sensorID, byte *data) {
18+
switch (sensorID) {
19+
case APDS_COLOUR_NANOV2: {
20+
int r, g, b;
21+
get_color(r, g, b);
22+
uint16_t * arr = (uint16_t*)data;
23+
arr[0] = (uint16_t)r;
24+
arr[1] = (uint16_t)g;
25+
arr[2] = (uint16_t)b;
26+
break;
27+
}
28+
case APDS_BRIGHT_NANOV2: {
29+
uint16_t * arr = (uint16_t*)data;
30+
arr[0] = get_light();
31+
break;
32+
}
33+
case APDS_PROX_NANOV2: {
34+
uint16_t * arr = (uint16_t*)data;
35+
arr[0] = get_proximity();
36+
break;
37+
}
38+
case APDS_GEST_NANOV2: {
39+
int8_t * arr = (int8_t*)data;
40+
arr[0] = get_gesture();
41+
break;
42+
}
43+
default:
44+
break;
45+
}
46+
}
47+
48+
void APDS_Sensor_NanoV2::get_color(int& r, int& g, int& b) {
49+
if (!available) {
50+
return;
51+
}
52+
while (! APDS.colorAvailable()) {
53+
delay(2);
54+
}
55+
// In library is only uint16; later converted
56+
APDS.readColor(r, g, b);
57+
58+
}
59+
60+
uint16_t APDS_Sensor_NanoV2::get_light() {
61+
if (!available) {
62+
return 0;
63+
}
64+
while (! APDS.colorAvailable()) {
65+
delay(2);
66+
}
67+
68+
int r, g, b, c;
69+
APDS.readColor(r, g, b, c);
70+
// In library is only uint16
71+
return (uint16_t)c;
72+
}
73+
74+
uint8_t APDS_Sensor_NanoV2::get_proximity() {
75+
if (!available) {
76+
return -1;
77+
}
78+
while (! APDS.proximityAvailable()) {
79+
delay(2);
80+
}
81+
// In library is only uint8
82+
return (uint8_t)APDS.readProximity();
83+
}
84+
85+
// Warning if gesture is turned on then it will wait for a gesture!!!
86+
int8_t APDS_Sensor_NanoV2::get_gesture() {
87+
if (!available) {
88+
return -1;
89+
}
90+
while (! APDS.gestureAvailable()) {
91+
delay(2);
92+
}
93+
94+
// In library is only int8
95+
return (int8_t)APDS.readGesture();
96+
}
97+
98+
int APDS_Sensor_NanoV2::get_sensor_count() {
99+
return sensor_count;
100+
}
101+
102+
#endif
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef APDS_Sensor_H_NANOV2
2+
#define APDS_Sensor_H_NANOV2
3+
4+
#include "config/flags.h"
5+
#if defined NORMAL_BOARD
6+
7+
#include <Arduino_APDS9960.h>
8+
#include <boards/generic_boards/SensorInterface.h>
9+
#include "SensorID_NanoV2.h"
10+
11+
class APDS_Sensor_NanoV2: public SensorInterface {
12+
public:
13+
void start() override;
14+
void end() override;
15+
16+
void get_data(int sensorID, byte *data) override;
17+
18+
int get_sensor_count() override;
19+
20+
void get_color(int& r, int& g, int& b);
21+
uint16_t get_light();
22+
uint8_t get_proximity();
23+
int8_t get_gesture();
24+
25+
const int sensor_count = 4;
26+
27+
private:
28+
bool available = false;
29+
};
30+
31+
#endif
32+
#endif //APDS_Sensor_H_NANOV2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "config/flags.h"
2+
#if defined NORMAL_BOARD
3+
4+
#include "BARO_Sensor_NanoV2.h"
5+
6+
void BARO_Sensor_NanoV2::start() {
7+
if (BARO.begin()) {
8+
available = true;
9+
}
10+
}
11+
12+
void BARO_Sensor_NanoV2::end() {
13+
BARO.end();
14+
available = false;
15+
}
16+
17+
void BARO_Sensor_NanoV2::get_data(int sensorID, byte *data) {
18+
float * floatArray = (float*)data;
19+
floatArray[0] = get_pressure();
20+
}
21+
22+
float BARO_Sensor_NanoV2::get_pressure() {
23+
if (!available) {
24+
return 0.0;
25+
}
26+
27+
return BARO.readPressure();
28+
}
29+
30+
int BARO_Sensor_NanoV2::get_sensor_count() {
31+
return sensor_count;
32+
}
33+
34+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef BARO_SENSOR_H_NANOV2
2+
#define BARO_SENSOR_H_NANOV2
3+
4+
#include "config/flags.h"
5+
#if defined NORMAL_BOARD
6+
7+
#include <Arduino_LPS22HB.h>
8+
#include <boards/generic_boards/SensorInterface.h>
9+
#include "SensorID_NanoV2.h"
10+
11+
class BARO_Sensor_NanoV2: public SensorInterface {
12+
public:
13+
void start() override;
14+
void end() override;
15+
16+
void get_data(int sensorID, byte *data) override;
17+
18+
int get_sensor_count() override;
19+
20+
float get_pressure();
21+
22+
const int sensor_count = 1;
23+
private:
24+
bool available = false;
25+
};
26+
27+
#endif
28+
#endif //BARO_SENSOR_H_NANOv
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "config/flags.h"
2+
#if defined NORMAL_BOARD
3+
4+
#include "HTS_Sensor_NanoV2.h"
5+
6+
void HTS_Sensor_NanoV2::start() {
7+
if (HS300x.begin()) {
8+
available = true;
9+
}
10+
}
11+
12+
void HTS_Sensor_NanoV2::end() {
13+
HS300x.end();
14+
available = false;
15+
}
16+
17+
void HTS_Sensor_NanoV2::get_data(int sensorID, byte *data) {
18+
float value;
19+
switch (sensorID) {
20+
case HTS_TEMP_NANOV2:
21+
value = get_temperature();
22+
break;
23+
case HTS_HUM_NANOV2:
24+
value = get_humidity();
25+
break;
26+
default:
27+
break;
28+
}
29+
30+
float * floatArray = (float*)data;
31+
floatArray[0] = value;
32+
}
33+
34+
float HTS_Sensor_NanoV2::get_temperature() {
35+
if (!available) {
36+
return 0.0;
37+
}
38+
39+
// -5 correction from original code
40+
return HS300x.readTemperature()-5;
41+
}
42+
43+
float HTS_Sensor_NanoV2::get_humidity(){
44+
if (!available) {
45+
return 0.0;
46+
}
47+
48+
return HS300x.readHumidity();
49+
}
50+
51+
int HTS_Sensor_NanoV2::get_sensor_count() {
52+
return sensor_count;
53+
}
54+
55+
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef HTS_SENSOR_H_NANOV2
2+
#define HTS_SENSOR_H_NANOV2
3+
4+
#include "config/flags.h"
5+
#if defined NORMAL_BOARD
6+
7+
#define CELSIUS CELSIUS_WRAP
8+
#define FAHRENHEIT FAHRENHEIT_WRAP
9+
#include <Arduino_HS300x.h>
10+
#undef CELSIUS
11+
#undef FAHRENHEIT
12+
#include <boards/generic_boards/SensorInterface.h>
13+
#include "SensorID_NanoV2.h"
14+
15+
class HTS_Sensor_NanoV2: public SensorInterface {
16+
public:
17+
void start() override;
18+
void end() override;
19+
20+
void get_data(int sensorID, byte *data) override;
21+
22+
int get_sensor_count() override;
23+
24+
float get_temperature();
25+
float get_humidity();
26+
27+
const int sensor_count = 2;
28+
private:
29+
bool available = false;
30+
};
31+
32+
#endif
33+
#endif //HTS_SENSOR_H_NANOV2
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "config/flags.h"
2+
#if defined NORMAL_BOARD
3+
4+
#include "IMU_Sensor_NanoV2.h"
5+
6+
void IMU_Sensor_NanoV2::start() {
7+
if (available) {
8+
return;
9+
}
10+
if (IMU.begin()) {
11+
available = true;
12+
}
13+
}
14+
15+
void IMU_Sensor_NanoV2::end() {
16+
if (!available) {
17+
return;
18+
}
19+
available = false;
20+
}
21+
22+
void IMU_Sensor_NanoV2::get_data(int sensorID, byte *data) {
23+
float x, y, z;
24+
switch (sensorID) {
25+
case IMU_ACCELERATION_NANOV2:
26+
IMU.readAcceleration(x,y,z);
27+
break;
28+
case IMU_GYROSCOPE_NANOV2:
29+
IMU.readGyroscope(x,y,z);
30+
break;
31+
case IMU_MAGNET_NANOV2:
32+
IMU.readMagneticField(x,y,z);
33+
break;
34+
default:
35+
break;
36+
}
37+
38+
float * floatArray = (float*)data;
39+
floatArray[0] = x;
40+
floatArray[1] = y;
41+
floatArray[2] = z;
42+
}
43+
44+
int IMU_Sensor_NanoV2::get_sensor_count() {
45+
return sensor_count;
46+
}
47+
48+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2
2+
#define EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2
3+
4+
#include "config/flags.h"
5+
#if defined NORMAL_BOARD
6+
7+
#include "Arduino_BMI270_BMM150.h"
8+
#include <boards/generic_boards/SensorInterface.h>
9+
#include "SensorID_NanoV2.h"
10+
11+
class IMU_Sensor_NanoV2: public SensorInterface {
12+
public:
13+
void start() override;
14+
void end() override;
15+
16+
void get_data(int sensorID, byte data[]) override;
17+
18+
int get_sensor_count() override;
19+
20+
const int sensor_count = 3;
21+
22+
private:
23+
bool available = false;
24+
};
25+
26+
#endif
27+
#endif //EDGEML_ARDUINO_IMU_SENSOR_NANO_HV2

0 commit comments

Comments
 (0)