Skip to content

Commit

Permalink
adjusting lab 3 library
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamenm03 committed Jan 23, 2024
1 parent 0c48850 commit e45dd59
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions examples/Lab3-SD/Lab3-SD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,35 @@
// CS - pin 10
const int chipSelect = 10;

// This is the pin your first TMP36 is connected to.
// Change this as needed.
// ############### START EDITING HERE (1/3) ###############
// Adjust the following pins according to your setup

// Pin for first TMP36
const int tmp1Pin = A0;

// This is the pin your second TMP36 is connected to.
// Change this as needed.
// Pin for second TMP36
const int tmp2Pin = A1;

// This is the pin your voltage divider is connected to.
// Change this as needed.
// Pin for voltage divider
const int vDivPin = A2;

// This is the pin your pressure sensor is connected to.
// Change this as needed.
// Pin for pressure sensor
const int pressPin = A3;

// This is the pin your humidity sensor is connected to.
// Change this as needed.
// Pin for humidity sensor
const int humidPin = A4;

// These are the pins your accelerometer is connected to (x, y, and z axes)
// Change these as needed.
// Pins for accelerometer
const int accelxPin = A5;
const int accelyPin = A6;
const int accelzPin = A7;

// ############### END EDITING HERE (1/3) ###############

// For future labs, you may find it helpful to copy the above settings for additional sensors.
// **HINT HINT WINK WINK**

// This is the string that goes at the top of your csv file. It is the column headers for your spreadsheet.
// You can change this as needed.
const String header = "Time (ms),TMP36_1 (Raw),TMP36_2 (Raw),Voltage (Raw),Pressure (raw),Humidity (raw),Accel_x (raw),Accel_y (raw),Accel_z (raw)";

#include <SPI.h>
Expand Down Expand Up @@ -73,14 +71,22 @@ void loop() {

// Note: in future labs, you may need to change this to add additional sensors.

int tmp1Val = analogRead(tmp1Pin); // First temperature reading (raw)
int tmp2Val = analogRead(tmp2Pin); // Second temperature reading (raw)
int vDivVal = analogRead(vDivPin); // Battery voltage reading (####THIS IS FROM VOLTAGE DIVIDER, ADJUST ACCORDINGLY####)
int pressVal = analogRead(pressPin); // Pressure reading (raw)
int humidVal = analogRead(humidPin); // Humidity reading (raw)
int accelxVal = analogRead(accelxPin); // X-Acceleration reading (raw)
int accelyVal = analogRead(accelyPin); // Y-Acceleration reading (raw)
int accelzVal = analogRead(accelzPin); // Z-Acceleration reading (raw)
double tmp1Val = analogRead(tmp1Pin); // First temperature reading (raw)
double tmp2Val = analogRead(tmp2Pin); // Second temperature reading (raw)

// ############### START EDITING HERE (2/3) ###############

double vDivVal = analogRead(vDivPin); // Battery voltage reading (THIS IS FROM VOLTAGE DIVIDER)

double vDivAdj = ???; // What should this line be to make the vDivAdj accurately reflect the battery voltage?

// ############### END EDITING HERE (2/3) ###############

double pressVal = analogRead(pressPin); // Pressure reading (raw)
double humidVal = analogRead(humidPin); // Humidity reading (raw)
double accelxVal = analogRead(accelxPin); // X-Acceleration reading (raw)
double accelyVal = analogRead(accelyPin); // Y-Acceleration reading (raw)
double accelzVal = analogRead(accelzPin); // Z-Acceleration reading (raw)

// Now let's make a nice string to write to the file.
// This is a comma-separated value (csv) file, so we need to separate each value with a comma.
Expand All @@ -94,8 +100,8 @@ void loop() {
// add the second raw TMP36 value
dataString += String(tmp2Val);
dataString += ",";
// add the raw voltage divider value
dataString += String(vDivVal);
// add the adjusted voltage divider value
dataString += String(vDivValAdj);
dataString += ",";
// add the raw pressure value
dataString += String(pressVal);
Expand All @@ -119,8 +125,12 @@ void loop() {
dataFile.println(dataString);
dataFile.close();

// ############### START EDITING HERE (3/3) ###############

// if you want to print to the serial port as well, uncomment the following line...
// Serial.println(dataString);

// ############### END EDITING HERE (3/3) ###############
}
// if the file isn't open, pop up an error:
else {
Expand Down

0 comments on commit e45dd59

Please sign in to comment.