File tree Expand file tree Collapse file tree 4 files changed +151
-0
lines changed
examples/Nicla Sense ME as a MKR Shield Expand file tree Collapse file tree 4 files changed +151
-0
lines changed Original file line number Diff line number Diff line change 4545 - examples/Portenta H7 as a USB Host/LEDKeyboardController
4646 - examples/Portenta H7 as a WiFi Access Point/SimpleWebServer
4747 - examples/Setting Up Portenta H7 For Arduino/Blink
48+
4849 - fqbn : arduino:mbed_portenta:envie_m4
4950 sketch-paths : |
5051 - examples/Dual Core Processing/BlinkGreenLed_M4
5354 sketch-paths : |
5455 - examples/Edge Control Getting Started
5556
57+ - fqbn : arduino:mbed_nicla:nicla_sense
58+ sketch-paths : |
59+ - examples/Nicla Sense ME as a MKR Shield/NiclaShieldController
60+
61+ - fqbn : arduino:samd:mkrwifi1010
62+ sketch-paths : |
63+ - examples/Nicla Sense ME as a MKR Shield/NiclaShieldHost
64+
5665 steps :
5766 - name : Checkout
5867 uses : actions/checkout@v2
7079 - name: Arduino_EdgeControl
7180 - name: lvgl
7281 version: 7.11.0
82+ - name: Arduino_BHY2
7383
7484 sketch-paths : |
7585 # Sketches to compile for all boards
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ This library contains the complete Arduino sketches from the Arduino Pro Tutoria
1313* https://docs.arduino.cc/hardware/portenta-h7-lite#tutorials[Arduino Portenta H7 Lite]
1414* https://docs.arduino.cc/hardware/edge-control#tutorials[Arduino Edge Control]
1515* https://docs.arduino.cc/hardware/portenta-vision-shield#tutorials[Arduino Portenta Vision Shield]
16+ * https://docs.arduino.cc/hardware/nicla-sense-me#tutorials[Arduino Nicla Sense ME]
1617
1718
1819
Original file line number Diff line number Diff line change 1+ #include " Nicla_System.h"
2+ #include " Arduino_BHY2.h"
3+ #include " Wire.h"
4+
5+ SensorXYZ accel (SENSOR_ID_ACC);
6+ SensorXYZ gyro (SENSOR_ID_GYRO);
7+ Sensor temp (SENSOR_ID_TEMP);
8+
9+ uint8_t command = 0x00 ;
10+ void requestHandler (); // request event callback
11+ void receiveEvent (int howMany); // receive event callback
12+
13+ void setup (){
14+ BHY2.begin ();
15+
16+ // Configure Sensors
17+ accel.configure (1 , 0 );
18+ gyro.configure (1 , 0 );
19+ temp.configure (1 , 0 );
20+
21+ // Give LED feedback to the user
22+ nicla::leds.begin ();
23+ nicla::leds.setColor (green);
24+
25+ Wire.begin (0x1A ); // join i2c bus with address #0x1A , do not use 0x60 nor 0x6B, the MKR board has those i2c devices
26+
27+ Wire.onRequest (requestHandler); // Callback triggered from `Wire.requestFrom()` done by the Host
28+
29+ Wire.onReceive (receiveEvent); // Callback triggered from `Wire.beginTransmission()` done by the Host
30+ }
31+
32+ void loop (){
33+ BHY2.update (10 );
34+ }
35+
36+ void I2CWrite16 (int16_t data){
37+ Wire.write ((byte)(data & 0xFF ));
38+ Wire.write ((byte)((data >> 8 ) & 0xFF ));
39+ }
40+
41+ void receiveEvent (int howMany){
42+
43+ nicla::leds.setColor (blue);
44+ while (Wire.available ()){
45+ command = Wire.read ();
46+ }
47+
48+ nicla::leds.setColor (off);
49+ }
50+
51+ void requestHandler (){
52+ nicla::leds.setColor (green);
53+
54+ int16_t dataX;
55+ int16_t dataY;
56+ int16_t dataZ;
57+
58+ switch (command){
59+
60+ // Update readings command
61+ case 0 :
62+ break ;
63+
64+ case 1 :
65+ dataX = accel.x ();
66+ I2CWrite16 (dataX);
67+ Serial.println (accel.toString ());
68+ break ;
69+
70+ case 2 :
71+ dataY = accel.y ();
72+ I2CWrite16 (dataY);
73+ break ;
74+
75+ case 3 :
76+ dataZ = accel.z ();
77+ I2CWrite16 (dataZ);
78+ break ;
79+
80+ default :
81+ break ;
82+ }
83+
84+ nicla::leds.setColor (off);
85+ }
Original file line number Diff line number Diff line change 1+ #include " Wire.h"
2+
3+ #define NICLA_I2C_ADDRESS 0x1A
4+
5+ void setup (){
6+ Serial.begin (9600 );
7+ while (!Serial);
8+
9+ Wire.begin (); // Join the I2C bus as a Host
10+ Serial.println (" Host started" );
11+ }
12+
13+ void loop (){
14+
15+ I2CWrite (1 ); // Request Acceleration X
16+ int16_t acX = getData16 ();
17+
18+ I2CWrite (2 ); // Request Acceleration Y
19+ int16_t acY = getData16 ();
20+
21+ I2CWrite (3 ); // Request Acceleration Z
22+ int16_t acZ = getData16 ();
23+
24+ Serial.print (" ACCELERATION :" );
25+ Serial.print (" X: " );
26+ Serial.print (acX);
27+ Serial.print (" Y: " );
28+ Serial.print (acY);
29+ Serial.print (" Z: " );
30+ Serial.print (acZ);
31+ Serial.println ();
32+
33+ delay (2500 );
34+ }
35+
36+ void I2CWrite (int command){
37+ Wire.beginTransmission (NICLA_I2C_ADDRESS);
38+ Wire.write (command);
39+ Wire.endTransmission ();
40+ delay (100 );
41+ }
42+
43+ int16_t getData16 (){
44+ int16_t data = 0 ;
45+
46+ Wire.requestFrom (0x1A , 2 );
47+
48+ while (Wire.available ()){
49+ for (int i = 0 ; i < 2 ; i++){
50+ data |= Wire.read () << (8 * i);
51+ }
52+ }
53+
54+ return data;
55+ }
You can’t perform that action at this time.
0 commit comments