IMU Drawing Machine
Components List
Microcontroller:
- Arduino Nano 33 BLE
- Arduino Nano Shield Module
Input / Output
- None
Power
- 9V Battery Module
Attachment
Band*1
Connector*1
If you do not have all the above components, please refer to Hardware page to get the kit.
Software
You can try the sketch on p5 editor, or you can download the code here.
Hardware
About accessing IMU sensor from Arduino Nano 33 BLE, please refer to Get Started with Arduino
/*
FlexiDots IMU Drawing Machine
https://studiohuahong.github.io/FlexiDots/examples/IMU-drawing-machine.html
*/
#include
#include // change to Arduino_LSM6DS3.h for Nano 33 IoT or Uno WiFi Rev 2
BLEService imuService ("2A5A20B9-0000-4B9C-9C69-4975713E0FF2");
BLECharacteristic accelerationCharacteristic ("2A5A20B9-0001-4B9C-9C69-4975713E0FF2", BLENotify, sizeof(float) * 3);
void setup() {
Serial.begin(9600);
// while (!Serial); // uncomment to wait for Serial port to be opened
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
if (!BLE.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
BLE.setLocalName("FlexiDots IMU Drawing Machine");
BLE.setDeviceName("FlexiDots IMU Drawing Machine");
BLE.setAdvertisedService(imuService);
imuService.addCharacteristic(accelerationCharacteristic);
BLE.addService(imuService);
BLE.advertise();
}
void loop() {
if (BLE.connected()) {
if (accelerationCharacteristic.subscribed() && IMU.accelerationAvailable()) {
float acceleration[3];
// x, y, z
IMU.readAcceleration(acceleration[0], acceleration[1], acceleration[2]);
accelerationCharacteristic.writeValue(acceleration, sizeof(acceleration));
}
}
}