Skip to content

Commit b91921e

Browse files
committed
added joystick-imu example for Serial Studio
1 parent 1c2f68b commit b91921e

6 files changed

Lines changed: 286 additions & 0 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MKRBatteryChecks/MKR_battery_WiFi_sleep/arduino_secrets.h
1717
.DS_Store
1818
.DS_Store
1919
.DS_Store
20+
*.DS_Store

joystick-imu/combined.json

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{
2+
"t": "%1",
3+
"g": [
4+
{
5+
"t": "Joystick",
6+
"d": [
7+
{
8+
"t": "H",
9+
"v": "%2",
10+
"u": "-",
11+
"g": true,
12+
"w": "bar",
13+
"max": 1023,
14+
"min": 0
15+
},
16+
{
17+
"t": "V",
18+
"v": "%3",
19+
"u": "-",
20+
"g": true,
21+
"w": "bar",
22+
"max": 1023,
23+
"min": 0
24+
},
25+
{
26+
"t": "button",
27+
"v": "%4",
28+
"u": "-",
29+
"g": true,
30+
"w": "bar",
31+
"max": 1,
32+
"min": 0
33+
}
34+
]
35+
},
36+
{
37+
"t": "Accelerometer",
38+
"w": "accelerometer",
39+
"d": [
40+
{
41+
"t": "X",
42+
"v": "%5",
43+
"u": "g",
44+
"g": true,
45+
"w": "x",
46+
"min": "-3.0",
47+
"max": "3.0"
48+
},
49+
{
50+
"t": "Y",
51+
"v": "%6",
52+
"u": "g",
53+
"g": true,
54+
"w": "y",
55+
"min": "-3.0",
56+
"max": "3.0"
57+
},
58+
{
59+
"t": "Z",
60+
"v": "%7",
61+
"u": "g",
62+
"g": true,
63+
"w": "z",
64+
"min": "-3.0",
65+
"max": "3.0"
66+
}
67+
]
68+
},
69+
{
70+
"t": "Gyroscope",
71+
"w": "gyro",
72+
"d": [
73+
{
74+
"t": "Yaw",
75+
"v": "%8",
76+
"u": "deg/s",
77+
"g": true,
78+
"w": "yaw",
79+
"min": "600",
80+
"max": "600"
81+
},
82+
{
83+
"t": "Roll",
84+
"v": "%9",
85+
"u": "deg/s",
86+
"g": true,
87+
"w": "roll",
88+
"min": "600",
89+
"max": "600"
90+
},
91+
{
92+
"t": "Pitch",
93+
"v": "%10",
94+
"u": "deg/s",
95+
"g": true,
96+
"w": "pitch",
97+
"min": "600",
98+
"max": "600"
99+
}
100+
]
101+
}
102+
]
103+
}

joystick-imu/imu.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"t": "%1",
3+
"g": [
4+
{
5+
"t": "Accelerometer",
6+
"w": "accelerometer",
7+
"d": [
8+
{
9+
"t": "X",
10+
"v": "%2",
11+
"u": "g",
12+
"g": true,
13+
"w": "x",
14+
"min": "-3.0",
15+
"max": "3.0"
16+
},
17+
{
18+
"t": "Y",
19+
"v": "%3",
20+
"u": "g",
21+
"g": true,
22+
"w": "y",
23+
"min": "-3.0",
24+
"max": "3.0"
25+
},
26+
{
27+
"t": "Z",
28+
"v": "%4",
29+
"u": "g",
30+
"g": true,
31+
"w": "z",
32+
"min": "-3.0",
33+
"max": "3.0"
34+
}
35+
]
36+
},
37+
{
38+
"t": "Gyroscope",
39+
"w": "gyro",
40+
"d": [
41+
{
42+
"t": "Yaw",
43+
"v": "%5",
44+
"u": "deg/s",
45+
"g": true,
46+
"w": "yaw",
47+
"min": "600",
48+
"max": "600"
49+
},
50+
{
51+
"t": "Roll",
52+
"v": "%6",
53+
"u": "deg/s",
54+
"g": true,
55+
"w": "roll",
56+
"min": "600",
57+
"max": "600"
58+
},
59+
{
60+
"t": "Pitch",
61+
"v": "%7",
62+
"u": "deg/s",
63+
"g": true,
64+
"w": "pitch",
65+
"min": "600",
66+
"max": "600"
67+
}
68+
]
69+
}
70+
]
71+
}

joystick-imu/joystick-imu.ino

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Example for Serial Studio and Nano 33 IoT
3+
Reads a joystick on A0, A1, and D2
4+
and the accelerometer and gyro on a Nano 33 IoT
5+
Serial Studio download: https://github.com/Serial-Studio/Serial-Studio/tags
6+
Tutorial: https://www.alex-spataru.com/blog/introducing-serial-studio
7+
Uses the following library:
8+
http://librarymanager/All#Arduino_LSM6DS3
9+
The circuit:
10+
- Joystick H axis attached to pin A0
11+
- Joystick V axis attached to pin A1
12+
- Nano 33 IoT built-in LSM6DS6 IMU
13+
14+
Included in the project folder are 3 JSON files for Serial Studio:
15+
joystick.json, imu.json, combined.json
16+
Comment out the lines you don't need
17+
18+
created 1 Feb 2021
19+
by Tom Igoe
20+
*/
21+
#include <Arduino_LSM6DS3.h>
22+
23+
// pin for the pushbutton:
24+
const int buttonPin = 2;
25+
26+
void setup() {
27+
Serial.begin(9600);
28+
// stop until serial port is open:
29+
while (!Serial);
30+
// initialize the pushbutton:
31+
pinMode(buttonPin, INPUT_PULLUP);
32+
// initialise the IMU:
33+
if (!IMU.begin()) {
34+
Serial.println("Failed to initialize IMU!");
35+
while (true);
36+
}
37+
}
38+
39+
void loop() {
40+
// arrays for the accel and gyro readings:
41+
float accel[3];
42+
float gyro[3];
43+
44+
// read joystick: h, v, button
45+
int horizontal = analogRead(A0);
46+
delay(1);
47+
int vertical = analogRead(A1);
48+
int buttonState = digitalRead(buttonPin);
49+
// read accelerometer:
50+
if (IMU.accelerationAvailable()) {
51+
IMU.readAcceleration(accel[0], accel[1], accel[2]);
52+
}
53+
// read gyroscope:
54+
if (IMU.gyroscopeAvailable()) {
55+
IMU.readGyroscope(gyro[0], gyro[1], gyro[2]);
56+
}
57+
// print them all:
58+
Serial.print("/*");
59+
Serial.print("Joystick and IMU,");
60+
Serial.print(horizontal);
61+
Serial.print(",");
62+
Serial.print(vertical);
63+
Serial.print(",");
64+
Serial.print(buttonState);
65+
for (int axis = 0; axis < 3; axis++) {
66+
Serial.print(",");
67+
Serial.print(accel[axis]);
68+
}
69+
for (int axis = 0; axis < 3; axis++) {
70+
Serial.print(",");
71+
Serial.print(gyro[axis]);
72+
}
73+
Serial.println("*/");
74+
}

joystick-imu/joystick.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"t": "%1",
3+
"g": [
4+
{
5+
"t": "Joystick",
6+
"d": [
7+
{
8+
"t": "H",
9+
"v": "%2",
10+
"u": "-",
11+
"g": true,
12+
"w": "bar",
13+
"max": 1023,
14+
"min": 0
15+
},
16+
{
17+
"t": "V",
18+
"v": "%3",
19+
"u": "-",
20+
"g": true,
21+
"w": "bar",
22+
"max": 1023,
23+
"min": 0
24+
},
25+
{
26+
"t": "button",
27+
"v": "%4",
28+
"u": "-",
29+
"g": true,
30+
"w": "bar",
31+
"max": 1,
32+
"min": 0
33+
}
34+
]
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)