For the I2C section of the lab, we used the VL53LOX to measure distance.

IMG_6178.MOV

For the second part off the serial lab, Callie and I used an SD card reader to record gyro data to the card and then saving the SD card. This went over smoothly, and I feel like I understand synchronous serial pretty well, as I had a brief foray into it for our midterm robot, even though we quickly picked another direction.

DATALOG.CSV

IMG_0427.HEIC

/*
  Minimal SD card datalogger with IMU

  This example shows how to log data from the Nano 33 IoT's 
  IMU sensor to an SD card using the SD library. 
  Contains only the bare minimum needed to write to the file. 
  There are no serial outputs, only the blinking LED.

  The circuit:
   Nano 33 IoT with SD card attached to SPI bus as follows:
 ** SDO - pin 11
 ** SDI - pin 12
 ** SCK - pin 13
 ** CS - pin 10 (for Nano and Uno; for MKRZero SD: SDCARD_SS_PIN)

  created  24 Nov 2010
  modified 1 Aug 2020
  by Tom Igoe
*/
#include <SD.h>
#include <Arduino_LSM6DS3.h>

// the SPI CS pin
const int chipSelect = 10;
const int cardDetect = 9;

// the filename. Use CSV so the result can be opened in a spreadsheet
const char fileName[] = "datalog.csv";
// time of last reading, in ms:
long lastReading = 0;

void setup() {
  // variable for the LED's state:
  int ledState = HIGH;
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(cardDetect, INPUT);

  // if the card detect pin is false, no card:
  while (digitalRead(cardDetect) == LOW) {
    // toggle LED every 1/4 second while the SD card's not present:
    digitalWrite(LED_BUILTIN, HIGH);
  }
  // give the reader 5 seconds to settle the card once it's detected:
  delay(5000);

  // if the card is not present or cannot be initialized:
  while (!SD.begin(chipSelect)) {
    // toggle LED every 1/4 second while the SD card's not responding:
    digitalWrite(LED_BUILTIN, ledState);
    // change the LED state:
    ledState = !ledState;
    delay(250);
  }

  // start the IMU:
  while (!IMU.begin()) {
    // toggle LED every 1/8 second while the sensor's not responding:
    digitalWrite(LED_BUILTIN, ledState);
    // change the LED state:
    ledState = !ledState;
    delay(125);
  }
  // turn the LED off:
  digitalWrite(LED_BUILTIN, LOW);
  // write a header to the SD card file:
  // note: the \\ character allows you to extend a string
  // on another line in a C program:
  String dataString = "seconds, \\
  x acceleration, \\
  y accleration, \\
  z acceleration, \\
  x gyro, \\
  y gyro, \\
  z gyro";
  writeToSDCard(dataString);
}

void loop() {
  // read once a second:
  if (millis() - lastReading > 1000) {
    // make a string for assembling the data to log:
    String dataString = "";
    // add the current time in seconds:
    dataString += String(millis() / 1000);
    dataString += ",";

    // read your sensors:
    // values for acceleration & rotation:
    float xAcc, yAcc, zAcc;
    float xGyro, yGyro, zGyro;

    // if both accelerometer & gyrometer are ready to be read:
    if (IMU.accelerationAvailable() &&
        IMU.gyroscopeAvailable()) {
      // read accelerometer & gyrometer:
      IMU.readAcceleration(xAcc, yAcc, zAcc);

      // print the results:
      IMU.readGyroscope(xGyro, yGyro, zGyro);
      dataString += String(xAcc);
      dataString += ",";
      dataString += String(yAcc);
      dataString += ",";
      dataString += String(zAcc);
      dataString += ",";
      dataString += String(xGyro);
      dataString += ",";
      dataString += String(yGyro);
      dataString += ",";
      dataString += String(zGyro);
    }
    // write to the SD card:
    writeToSDCard(dataString);
  }  // end of if millis() statement
} // end of loop

void writeToSDCard(String inputString) {
  // open the file. Only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open(fileName, FILE_WRITE);

  // if the file is available, write to it:
  // turn the LED on while writing and off when not writing too:
  if (dataFile) {
    digitalWrite(LED_BUILTIN, HIGH);
    dataFile.println(inputString);
    dataFile.close();
    digitalWrite(LED_BUILTIN, LOW);
    lastReading = millis();
  } else {
    // if the file can't be opened, leave the LED on:
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

For our final we have made some really promising progress on the bluetooth section of our project. We are using two separate Arduinos, one as a controller and the other as the brains for the robot. In order to make a wireless controller, we decided we would try to use bluetooth. This sent me down a rabbit hole of learning about UUIDs for a service, UUIDs for characteristics and the general ideas behind a central and peripheral device.

For our peripheral Arduino, we are utilizing the built in gyroscope to send tilt data to the central. The idea behind this that we will be able to steer our bot by tilting the controller. I will attach the code below, but we are still currently working on it so I want to post the most updated version by the end of the day. Some aspects of it include:

Formatting the gyro characteristic to notify the central whenever it updates using BLEnotify

Concatenating the gyro data into a string that reads as “gyro x, gyro y, gyro z as a way of simplifying the data. I am unsure if this is the most effective way to send the data but I am happy to report our central is receiving our formatted string. How would I go about figuring out which way formatting the data would be best for the performance of the robot? The main reason we used a concatenated string was that it made sense in our brains logically, but I am not sure the Arduino feels the same…

Screenshot 2024-11-18 at 3.59.07 PM.png

We are having issues breaking the string out of concatenated form.