| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Gregory Manker--Lab 4

Page history last edited by Greg 7 years, 4 months ago

PART A

a. Based on the readings from the serial monitor, what is the range of the analog values being read?

0-1023

 

b. How many bits of resolution does the analog to digital converter (ADC) on the Atmega32U4 have (hint: where might you look to find this sort of thing)? How many are you using with the range of values you're seeing?

The ADC has 10 bits of resolution, and we're using log2(1024) = all 10 bits!

 

PART B

1.

a. Describe the voltage change over the sensing range of the sensor. A sketch of voltage vs. distance would work also. Does it match up with what you expect from the datasheet?

In my case, the output voltage started at 1.7 when I held my piece of paper right against the sensor. Values increased to about 3.12 very quickly, and then decreased very slowly to about .042 V. Thus, my data follows the pattern laid out in the graph on the SparkFun spec sheet, but my axes are slightly different because my Vo at x=0 is different.

 

 

int sensorPin = A0;    

float sensorValue = 0;     // variable to store the value coming from the sensor

 

void setup() {

  Serial.begin(9600);

}

 

void loop() {

  sensorValue = analogRead(sensorPin);

  Serial.print("Voltage: ");

  Serial.print(getAdjustedVoltage(sensorValue));

  Serial.println("");

  delay(1000); 

}

 

/* getAdjustedVoltage

 * input: raw data value from bend sensor

 * return: an adjusted voltage

 * The bend sensor scales values to a number between 0 and 1023.

 * In order for these values to be interpreted as voltages, they

 * must be scaled using a linear function.

 */

float getAdjustedVoltage(float valueToAdjust) {

  return ((5.0/1023.0)*valueToAdjust);

}

 

2.

a. Include your accelerometer read-out code in your write-up.

 

#include <LiquidCrystal.h>

 

LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

 

// these constants describe the pins. They won't change:

const int xpin = A3;                  // x-axis of the accelerometer

const int ypin = A2;                  // y-axis

const int zpin = A1;                  // z-axis (only on 3-axis models)

 

void setup()

{

  // initialize the serial communications:

  Serial.begin(9600);

 

  // initialize the LCD

  lcd.begin(16,2);

}

 

void loop()

{

  lcd.clear();

 

  // Print the X values

  Serial.print(analogRead(xpin));

  lcd.print("X:"); lcd.print(analogRead(xpin)); lcd.print("\t");

 

  // Print the Y Values

  Serial.print("\t");

  Serial.print(analogRead(ypin));

  lcd.print("Y:"); lcd.print(analogRead(ypin)); lcd.print("\t");

 

  // Print the Z Values

  Serial.print("\t");

  Serial.print(analogRead(zpin));

  lcd.setCursor(0,1); lcd.print("Z:"); lcd.print(analogRead(zpin));

  Serial.println();

 

  // Delay before next reading:

  delay(1000);

}

 

Part C.

1.

a. Upload a picture of your rotary encoder in action!

 

PART D

1.

a. Turn in a copy of your final state diagram.

Initial:

FINAL:

2.

a. How many byte-sized data samples can you store on the Atmega32U4?

1000 bytes EEPROM == 1000 byte-size data samples.

b. How would you get your analog data from the ADC to be byte-sized?

I would create a linear mapping function that takes values between 0 and 1023 and maps them from 0 to 256. Because I have to use discrete values (I can't send a value of 147.5... that's definitely not a byte), I would round each number depending on whether it's closer to the the value above or below it. This means I'll lose some resolution, but my output value will be 8 bits--as desired.

 

3.

http://www.youtube.com/watch?v=eUykBnWnEW4

 

Comments (0)

You don't have permission to comment on this page.