Week 8: Input Devices

HTMAA 2024 - Jonathan Cohen

Group Assignment

For our group assignment we met in the ee cba lab and looked at different digital and analog signals with the logic analizer and the scope.

CMU sketch

We are looking at the i2c signal from a multi-axis hall sensor. You can see the analog on the bottom of the screen and the digital interpretation on the top

Individual Assignment

I am now thinking about legged robots and glasses projects now... For both projects IMUs are important in order to figure out what your orientation is. I will use the Adafruit 9-DOF Orientation IMU Fusion Breakout - BNO085 sensor for this weeks assignment href="https://cdn-learn.adafruit.com/downloads/pdf/adafruit-9-dof-orientation-imu-fusion-breakout-bno085.pdf">Adafruit BNO085 Sensor Data Sheet

Design!

CMU sketch

The schematic here is very simple, just following the i2c wiring. All we need are 4 connections. (CAD Link )

CMU sketch

In order to reuse the XIAO ESP32-C6 (selected since it would be cool to control the project wirelessly) and the BNO085 across projects. I will use female headers on the PCB board so that I can just solder male headers on xiao and bno085. I needed to mirror the pinouts before routing the board so that I could place the components on the back of the board. I had all this extra space on top of the board so I decided to add art and existentialist emotions to the front of the board.

CMU sketch

The bno085 footprint is locked in fusion so I could not delete all the things that I did not need so I used photoshop to delete all the dill hits I was not using.

Fabricate!

CMU sketch

The workflow was fusions to gerbers to gerber2image to photoshop to mods to milling. The 1/32 endmill was broken so I replaced it. Luckily Quentin showed me how right before since the 1/64 endmill was broken earlier.

CMU sketch CMU sketch

Solder time! I just soldered the headers onto the boards and then populated the board onto the back of the pcb.

Code!

        
#include Adafruit_BNO08x.h
#include Wire.h

Adafruit_BNO08x bno08x;
sh2_SensorValue_t sensorValue;

void setup() {
  Serial.begin(115200);
  while (!Serial) delay(10);

  if (!bno08x.begin_I2C()) {
    Serial.println("BNO08x not detected. Check wiring.");
    while (1);
  }
  Serial.println("BNO08x detected!");

  // Enable rotation vector, which provides orientation data
  setReports();
}

void loop() {
  if (bno08x.getSensorEvent(&sensorValue)) {
    if (sensorValue.sensorId == SH2_ROTATION_VECTOR) {
      float roll = sensorValue.un.rotationVector.i;
      float pitch = sensorValue.un.rotationVector.j;
      float yaw = sensorValue.un.rotationVector.real;

      // Send Euler angles over serial
      Serial.print("Orientation - Yaw: "); Serial.print(yaw);
      Serial.print(", Pitch: "); Serial.print(pitch);
      Serial.print(", Roll: "); Serial.println(roll);
    }
  }
  delay(20);
}

void setReports() {
  if (!bno08x.enableReport(SH2_ROTATION_VECTOR)) {
    Serial.println("Could not enable rotation vector");
  }
}

        
    

All we are doing having the xiao share the imu euler angles via serial to my laptop (Chatgpt 4o was used for coding help)

        
% Setup serial connection
serialPort = serialport("/dev/cu.usbmodem101", 115200);
configureTerminator(serialPort, "LF");

% Load STL file and extract vertices and faces
fv = stlread('glasses_asm.stl');
faces = fv.ConnectivityList;    % Access the faces through 'ConnectivityList'
vertices = fv.Points;           % Access the vertices through 'Points'

% Plot the STL model
h = trisurf(faces, vertices(:,1), vertices(:,2), vertices(:,3), ...
            'FaceColor', 'cyan', 'EdgeColor', 'none');

% Setup plot properties
axis equal;
view(3);
camlight;
lighting phong;
axis manual;
xlim([-200 200]);  % Adjust these limits based on your model size
ylim([-200 200]);
zlim([-200 200]);

% Create a transformation object
tform = hgtransform;
set(h, 'Parent', tform);  % Set the transformation as the parent of the plot

% Continuously read and update orientation
while true
    if serialPort.NumBytesAvailable > 0
        % Read a line of data
        line = readline(serialPort);
        
        % Parse Euler angles from serial line
        data = sscanf(line, 'Orientation - Yaw: %f, Pitch: %f, Roll: %f');
        if numel(data) == 3
            yaw = deg2rad(data(1));   % Convert to radians
            pitch = deg2rad(data(2));
            roll = deg2rad(data(3));

            % Create a rotation matrix based on yaw, pitch, and roll
            Rx = makehgtform('xrotate', roll);
            Ry = makehgtform('yrotate', pitch);
            Rz = makehgtform('zrotate', yaw);

            % Combine rotations into a single transformation matrix
            R = Rz * Ry * Rx;

            % Apply the combined transformation to the transform object
            set(tform, 'Matrix', R);
            drawnow;
        end
    end
end
        
    

Matlab is taking the euler angles and using them to rotate the glasses stl file for head tracking.

Reflections

CMU sketch

(IMU orientation)

CMU sketch

The matlab visualizer for head tracking has some issues that gave it a ton of latency and is acting a bit weird. I need to debug. The IMU is a very cool sensor and I look forward to learning more about its capabilities.