File tree 3 files changed +208
-0
lines changed
examples/Nicla Sense ME as a MKR Shield
3 files changed +208
-0
lines changed Original file line number Diff line number Diff line change 45
45
- examples/Portenta H7 as a USB Host/LEDKeyboardController
46
46
- examples/Portenta H7 as a WiFi Access Point/SimpleWebServer
47
47
- examples/Setting Up Portenta H7 For Arduino/Blink
48
+
48
49
- fqbn : arduino:mbed_portenta:envie_m4
49
50
sketch-paths : |
50
51
- examples/Dual Core Processing/BlinkGreenLed_M4
53
54
sketch-paths : |
54
55
- examples/Edge Control Getting Started
55
56
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
+
56
65
steps :
57
66
- name : Checkout
58
67
uses : actions/checkout@v2
70
79
- name: Arduino_EdgeControl
71
80
- name: lvgl
72
81
version: 7.11.0
82
+ - name: Arduino_BHY2
73
83
74
84
sketch-paths : |
75
85
# Sketches to compile for all boards
Original file line number Diff line number Diff line change
1
+ #include " Nicla_System.h"
2
+
3
+ #include " Arduino_BHY2.h"
4
+
5
+ #include " Wire.h"
6
+
7
+ SensorXYZ accel (SENSOR_ID_ACC);
8
+
9
+ SensorXYZ gyro (SENSOR_ID_GYRO);
10
+
11
+ Sensor temp (SENSOR_ID_TEMP);
12
+
13
+ uint8_t command = 0x00 ;
14
+
15
+ void requestHandler (); // request event callback
16
+
17
+ void receiveEvent (int howMany); // receive event callback
18
+
19
+ void setup ()
20
+ {
21
+
22
+ BHY2.begin ();
23
+
24
+ // Configure Sensors
25
+
26
+ accel.configure (1 , 0 );
27
+
28
+ gyro.configure (1 , 0 );
29
+
30
+ temp.configure (1 , 0 );
31
+
32
+ // Give LED feedback to the user
33
+
34
+ nicla::leds.begin ();
35
+
36
+ nicla::leds.setColor (green);
37
+
38
+ Wire.begin (0x1A ); // join i2c bus with address #0x1A , do not use 0x60 nor 0x6B, the MKR board has those i2c devices
39
+
40
+ Wire.onRequest (requestHandler); // Callback triggered from `Wire.requestFrom()` done by the Host
41
+
42
+ Wire.onReceive (receiveEvent); // Callback triggered from `Wire.beginTransmission()` done by the Host
43
+ }
44
+
45
+ void loop ()
46
+ {
47
+
48
+ BHY2.update (10 );
49
+ }
50
+
51
+ void I2CWrite16 (int16_t data)
52
+ {
53
+
54
+ Wire.write ((byte)(data & 0xFF ));
55
+
56
+ Wire.write ((byte)((data >> 8 ) & 0xFF ));
57
+ }
58
+
59
+ void receiveEvent (int howMany)
60
+ {
61
+
62
+ nicla::leds.setColor (blue);
63
+
64
+ while (Wire.available ())
65
+
66
+ {
67
+
68
+ command = Wire.read ();
69
+ }
70
+
71
+ nicla::leds.setColor (off);
72
+ }
73
+
74
+ void requestHandler ()
75
+ {
76
+
77
+ nicla::leds.setColor (green);
78
+
79
+ int16_t dataX;
80
+
81
+ int16_t dataY;
82
+
83
+ int16_t dataZ;
84
+
85
+ switch (command)
86
+
87
+ {
88
+
89
+ // Update readings command
90
+
91
+ case 0 :
92
+
93
+ break ;
94
+
95
+ case 1 :
96
+
97
+ dataX = accel.x ();
98
+
99
+ I2CWrite16 (dataX);
100
+
101
+ Serial.println (accel.toString ());
102
+
103
+ break ;
104
+
105
+ case 2 :
106
+
107
+ dataY = accel.y ();
108
+
109
+ I2CWrite16 (dataY);
110
+
111
+ break ;
112
+
113
+ case 3 :
114
+
115
+ dataZ = accel.z ();
116
+
117
+ I2CWrite16 (dataZ);
118
+
119
+ break ;
120
+
121
+ default :
122
+
123
+ break ;
124
+ }
125
+
126
+ nicla::leds.setColor (off);
127
+ }
Original file line number Diff line number Diff line change
1
+ #include " Wire.h"
2
+ #define NICLA_I2C_ADDRESS 0x1A
3
+
4
+ void setup ()
5
+ {
6
+ Serial.begin (9600 );
7
+ while (!Serial)
8
+ ;
9
+
10
+ Wire.begin (); // Join the I2C bus as a Host
11
+ Serial.println (" Host started" );
12
+ }
13
+
14
+ void loop ()
15
+ {
16
+
17
+ I2CWrite (1 ); // Request Acceleration X
18
+
19
+ int16_t acX = getData16 ();
20
+
21
+ I2CWrite (2 ); // Request Acceleration Y
22
+
23
+ int16_t acY = getData16 ();
24
+
25
+ I2CWrite (3 ); // Request Acceleration Z
26
+
27
+ int16_t acZ = getData16 ();
28
+
29
+ Serial.print (" ACCELERATION :" );
30
+
31
+ Serial.print (" X: " );
32
+ Serial.print (acX);
33
+
34
+ Serial.print (" Y: " );
35
+ Serial.print (acY);
36
+
37
+ Serial.print (" Z: " );
38
+ Serial.print (acZ);
39
+
40
+ Serial.println ();
41
+
42
+ delay (2500 );
43
+ }
44
+
45
+ void I2CWrite (int command)
46
+ {
47
+ Wire.beginTransmission (NICLA_I2C_ADDRESS);
48
+ Wire.write (command);
49
+ Wire.endTransmission ();
50
+ delay (100 );
51
+ }
52
+
53
+ int16_t getData16 ()
54
+ {
55
+
56
+ int16_t data = 0 ;
57
+
58
+ Wire.requestFrom (0x1A , 2 );
59
+
60
+ while (Wire.available ())
61
+ {
62
+
63
+ for (int i = 0 ; i < 2 ; i++)
64
+ {
65
+
66
+ data |= Wire.read () << (8 * i);
67
+ }
68
+ }
69
+
70
+ return data;
71
+ }
You can’t perform that action at this time.
0 commit comments