From 0f108eb2606621d886636e50defbe0bb77e90bdc Mon Sep 17 00:00:00 2001 From: marqdevx Date: Thu, 23 Sep 2021 11:12:47 +0200 Subject: [PATCH 1/3] Add Nicla Sense ME sketches, and CI for compiling --- .github/workflows/compile-examples.yml | 10 ++ .../NiclaShieldController.ino | 127 ++++++++++++++++++ .../NiclaShieldHost/NiclaShieldHost.ino | 71 ++++++++++ 3 files changed, 208 insertions(+) create mode 100644 examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino create mode 100644 examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 471d753..e220f4e 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -45,6 +45,7 @@ jobs: - examples/Portenta H7 as a USB Host/LEDKeyboardController - examples/Portenta H7 as a WiFi Access Point/SimpleWebServer - examples/Setting Up Portenta H7 For Arduino/Blink + - fqbn: arduino:mbed_portenta:envie_m4 sketch-paths: | - examples/Dual Core Processing/BlinkGreenLed_M4 @@ -53,6 +54,14 @@ jobs: sketch-paths: | - examples/Edge Control Getting Started + - fqbn: arduino:mbed_nicla:nicla_sense + sketch-paths: | + - examples/Nicla Sense ME as a MKR Shield/NiclaShieldController + + - fqbn: arduino:samd:mkrwifi1010 + sketch-paths: | + - examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost + steps: - name: Checkout uses: actions/checkout@v2 @@ -70,6 +79,7 @@ jobs: - name: Arduino_EdgeControl - name: lvgl version: 7.11.0 + - name: Arduino_BHY2 sketch-paths: | # Sketches to compile for all boards diff --git a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino new file mode 100644 index 0000000..70e740c --- /dev/null +++ b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino @@ -0,0 +1,127 @@ +#include "Nicla_System.h" + +#include "Arduino_BHY2.h" + +#include "Wire.h" + +SensorXYZ accel(SENSOR_ID_ACC); + +SensorXYZ gyro(SENSOR_ID_GYRO); + +Sensor temp(SENSOR_ID_TEMP); + +uint8_t command = 0x00; + +void requestHandler(); //request event callback + +void receiveEvent(int howMany); //receive event callback + +void setup() +{ + + BHY2.begin(); + + //Configure Sensors + + accel.configure(1, 0); + + gyro.configure(1, 0); + + temp.configure(1, 0); + + //Give LED feedback to the user + + nicla::leds.begin(); + + nicla::leds.setColor(green); + + Wire.begin(0x1A); // join i2c bus with address #0x1A , do not use 0x60 nor 0x6B, the MKR board has those i2c devices + + Wire.onRequest(requestHandler); // Callback triggered from `Wire.requestFrom()` done by the Host + + Wire.onReceive(receiveEvent); // Callback triggered from `Wire.beginTransmission()` done by the Host +} + +void loop() +{ + + BHY2.update(10); +} + +void I2CWrite16(int16_t data) +{ + + Wire.write((byte)(data & 0xFF)); + + Wire.write((byte)((data >> 8) & 0xFF)); +} + +void receiveEvent(int howMany) +{ + + nicla::leds.setColor(blue); + + while (Wire.available()) + + { + + command = Wire.read(); + } + + nicla::leds.setColor(off); +} + +void requestHandler() +{ + + nicla::leds.setColor(green); + + int16_t dataX; + + int16_t dataY; + + int16_t dataZ; + + switch (command) + + { + + //Update readings command + + case 0: + + break; + + case 1: + + dataX = accel.x(); + + I2CWrite16(dataX); + + Serial.println(accel.toString()); + + break; + + case 2: + + dataY = accel.y(); + + I2CWrite16(dataY); + + break; + + case 3: + + dataZ = accel.z(); + + I2CWrite16(dataZ); + + break; + + default: + + break; + } + + nicla::leds.setColor(off); +} diff --git a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino new file mode 100644 index 0000000..cc75b1f --- /dev/null +++ b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino @@ -0,0 +1,71 @@ +#include "Wire.h" +#define NICLA_I2C_ADDRESS 0x1A + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + + Wire.begin(); // Join the I2C bus as a Host + Serial.println("Host started"); +} + +void loop() +{ + + I2CWrite(1); // Request Acceleration X + + int16_t acX = getData16(); + + I2CWrite(2); // Request Acceleration Y + + int16_t acY = getData16(); + + I2CWrite(3); // Request Acceleration Z + + int16_t acZ = getData16(); + + Serial.print("ACCELERATION :"); + + Serial.print(" X: "); + Serial.print(acX); + + Serial.print(" Y: "); + Serial.print(acY); + + Serial.print(" Z: "); + Serial.print(acZ); + + Serial.println(); + + delay(2500); +} + +void I2CWrite(int command) +{ + Wire.beginTransmission(NICLA_I2C_ADDRESS); + Wire.write(command); + Wire.endTransmission(); + delay(100); +} + +int16_t getData16() +{ + + int16_t data = 0; + + Wire.requestFrom(0x1A, 2); + + while (Wire.available()) + { + + for (int i = 0; i < 2; i++) + { + + data |= Wire.read() << (8 * i); + } + } + + return data; +} \ No newline at end of file From 59e614669320e24e6cbd6b26ebafe7ba8b210fb4 Mon Sep 17 00:00:00 2001 From: marqdevx Date: Thu, 30 Sep 2021 14:43:42 +0200 Subject: [PATCH 2/3] Added Nicla Sense ME link --- README.adoc | 1 + 1 file changed, 1 insertion(+) diff --git a/README.adoc b/README.adoc index 14f81ae..d2a24a5 100644 --- a/README.adoc +++ b/README.adoc @@ -13,6 +13,7 @@ This library contains the complete Arduino sketches from the Arduino Pro Tutoria * https://docs.arduino.cc/hardware/portenta-h7-lite#tutorials[Arduino Portenta H7 Lite] * https://docs.arduino.cc/hardware/edge-control#tutorials[Arduino Edge Control] * https://docs.arduino.cc/hardware/portenta-vision-shield#tutorials[Arduino Portenta Vision Shield] +* https://docs.arduino.cc/hardware/nicla-sense-me#tutorials[Arduino Nicla Sense ME] From 4fd4aeb8283da9d0a058fc4a0daaf8db25e17e6f Mon Sep 17 00:00:00 2001 From: marqdevx Date: Thu, 30 Sep 2021 15:07:25 +0200 Subject: [PATCH 3/3] Nicla Sense ME tutorial: formatting alginment --- .../NiclaShieldController.ino | 60 +++---------------- .../NiclaShieldHost/NiclaShieldHost.ino | 32 +++------- 2 files changed, 17 insertions(+), 75 deletions(-) diff --git a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino index 70e740c..f7c3abf 100644 --- a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino +++ b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldController/NiclaShieldController.ino @@ -1,38 +1,25 @@ #include "Nicla_System.h" - #include "Arduino_BHY2.h" - #include "Wire.h" SensorXYZ accel(SENSOR_ID_ACC); - SensorXYZ gyro(SENSOR_ID_GYRO); - Sensor temp(SENSOR_ID_TEMP); uint8_t command = 0x00; - void requestHandler(); //request event callback - void receiveEvent(int howMany); //receive event callback -void setup() -{ - +void setup(){ BHY2.begin(); //Configure Sensors - accel.configure(1, 0); - gyro.configure(1, 0); - temp.configure(1, 0); //Give LED feedback to the user - nicla::leds.begin(); - nicla::leds.setColor(green); Wire.begin(0x1A); // join i2c bus with address #0x1A , do not use 0x60 nor 0x6B, the MKR board has those i2c devices @@ -42,84 +29,55 @@ void setup() Wire.onReceive(receiveEvent); // Callback triggered from `Wire.beginTransmission()` done by the Host } -void loop() -{ - +void loop(){ BHY2.update(10); } -void I2CWrite16(int16_t data) -{ - +void I2CWrite16(int16_t data){ Wire.write((byte)(data & 0xFF)); - Wire.write((byte)((data >> 8) & 0xFF)); } -void receiveEvent(int howMany) -{ +void receiveEvent(int howMany){ nicla::leds.setColor(blue); - - while (Wire.available()) - - { - + while (Wire.available()){ command = Wire.read(); } nicla::leds.setColor(off); } -void requestHandler() -{ - +void requestHandler(){ nicla::leds.setColor(green); int16_t dataX; - int16_t dataY; - int16_t dataZ; - switch (command) - - { - - //Update readings command - + switch (command){ + + //Update readings command case 0: - break; case 1: - dataX = accel.x(); - I2CWrite16(dataX); - Serial.println(accel.toString()); - break; case 2: - dataY = accel.y(); - I2CWrite16(dataY); - break; case 3: - dataZ = accel.z(); - I2CWrite16(dataZ); - break; default: - break; } diff --git a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino index cc75b1f..7e49f23 100644 --- a/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino +++ b/examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost/NiclaShieldHost.ino @@ -1,68 +1,52 @@ #include "Wire.h" + #define NICLA_I2C_ADDRESS 0x1A -void setup() -{ +void setup(){ Serial.begin(9600); - while (!Serial) - ; + while (!Serial); Wire.begin(); // Join the I2C bus as a Host Serial.println("Host started"); } -void loop() -{ +void loop(){ I2CWrite(1); // Request Acceleration X - int16_t acX = getData16(); I2CWrite(2); // Request Acceleration Y - int16_t acY = getData16(); I2CWrite(3); // Request Acceleration Z - int16_t acZ = getData16(); Serial.print("ACCELERATION :"); - Serial.print(" X: "); Serial.print(acX); - Serial.print(" Y: "); Serial.print(acY); - Serial.print(" Z: "); Serial.print(acZ); - Serial.println(); delay(2500); } -void I2CWrite(int command) -{ +void I2CWrite(int command){ Wire.beginTransmission(NICLA_I2C_ADDRESS); Wire.write(command); Wire.endTransmission(); delay(100); } -int16_t getData16() -{ - +int16_t getData16(){ int16_t data = 0; Wire.requestFrom(0x1A, 2); - while (Wire.available()) - { - - for (int i = 0; i < 2; i++) - { - + while (Wire.available()){ + for (int i = 0; i < 2; i++){ data |= Wire.read() << (8 * i); } }