Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IMPORTANT WARNING: THE ACCELEROMETER DOES NOT SUPPORT FIVE VOLT POWER! ATTACHING

ID: 3348783 • Letter: I

Question

IMPORTANT WARNING: THE ACCELEROMETER DOES NOT SUPPORT FIVE VOLT POWER! ATTACHING THE Vcc PIN TO FIVEVOLTS MAY CAUSE IRREPARABLE DAMAGE TO THE ACCELEROMETER WHICH YOU ARE RESPONSIBLE FOR. 1) Acknowledge that you have read and understood the warning concerning damage to your accelerometer 2) Connect your accelerometer to your Arduino (Use the instructions given below) 3) Add this line to your setup) function 4) Connect your Arduino's AREF pin to the 3.3V pin, this will change the analog reference from analogReference (EXTERNAL) 5.0V to the same 3.3V used by the accelerometer and should give you more accurate results. Make sure that you don't accidentally connect the 3.3V pin to GND, doing so will damage your Arduino. 5) Writea program that prints the X, Y, and Zaccelerations to the serial monitor every 250ms (See Programming Hints below) 6) Complete the following table Axis X+ (X= +1g) X- (X--1g) Y+ (Y +1g) Y- (Y-1g) Raw Value (counts) Acceleration (8) Hint: Your Acceleration (g) should be 1g or-1g.

Explanation / Answer

    GIVEN DATA:-

1) Acknowledge that you read and understand the warning concerning damage to your    acclerometer.

2) CONNECT YOUR ACCELEROMETER TO YOUR ARDUINO (Use the instructions given below)

3) ADD THIS LINE TO YOUR SETUP() FUNCTION          

    PROGRAM:-

To make it straightforward I actualized the exemplary squint program that flips the yield stick associated with the on-board LED. avr-gcc toolchain doesn't know the Arduino Uno board design, it just knows the microcontroller that is mounted on it, which is the Atmega328p, so we have to peruse/compose straightforwardly the equipment I/O registers of that specific chip, and take a gander at its pinout to comprehend the stick names and where they go: everything can be found in the Atmega328p datasheet. Rather from the Arduino Uno schematics we can discover where the pins are associated, for instance we can find that the LED is associated with the PB5 stick of the Atmega328p chip, so's the stick we have to control. Presently we have to compose the code that flips the PB5 stick. The AVR compiler is supplemented with a C library: avr-libc, which contains helpful capacities and headers to get to the functionalities and I/Os of AVR chips. It likewise makes it simple to compose finish C programs without utilizing low level computing construct. Inside the avr-libc manual and the Atmega328p datasheet there are numerous cases on the best way to flip IOs, and with them I arranged the accompanying code in a record called "led.c":

#include <avr/io.h>

#include <util/delay.h>

#define BLINK_DELAY_MS 1000

int main (void)

{

/* set pin 5 of PORTB for output*/

DDRB |= _BV(DDB5);

while(1) {

/ set pin 5 high to turn led on /

PORTB |= _BV(PORTB5);

_delay_ms(BLINK_DELAY_MS);

/ set pin 5 low to turn led off /

PORTB &= ~_BV(PORTB5);

_delay_ms(BLINK_DELAY_MS);

}

}

The Port "B" of the microcontroller can be changed a tiny bit at a time with extraordinary guidelines called "sbi" and "cbi". In C we utilize the bitwise "|=" and "&=" task administrators, which typically read and compose a variable, however the compiler perceives those sort of gets to creating advanced gathering in the event of bit-wise activities, and there is no perused activity included. The "_BV" large scale together with PORTB5 is utilized to manufacture an esteem that contains one on the bit that relates to PB5. The primary capacity contains a vast circle that raises and brings down the bit 5 of PORTB enroll and between these tasks sits tight for one moment utilizing the library work "_delay_ms". On the off chance that you introduced avr-gcc on your Linux machine, the ports definitions and valuable macros (like "_BV") can be found in the "/usr/lib/avr/incorporate/avr/iom328p.h" and "/usr/lib/avr/incorporate/avr/sfr_defs.h" headers, or in the registry where the library has been introduced.

The compiler can make an ELF executable program that contain machine code and other data, for example, program segment memory design and investigate data. So as to gather a program and transfer it to the Arduino Uno, We have to make an IHEX document and utilize the avrdude instrument to stack it inside the Flash. The instrument to change over the ELF into IHEX for our situation is avr-objcopy. Presently it's a great opportunity to run the summon lines that manufacture and transfer the LED squint program. The majority of the parameters and alternatives of the avr-gcc and the avrdude devices for the Uno board can be found in the "equipment/arduino/boards.txt" document from inside the Arduino IDE establishment registry, and some other data is available in the avrdude manual. The orders that I used to arrange and transfer the "led.c" code above are:

$ avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o led.o led.c

$ avr-gcc -mmcu=atmega328p led.o -o led

$ avr-objcopy -O ihex -R .eeprom led led.hex

$ avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:led.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f

avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

To disable this feature, specify the -D option.

avrdude: erasing chip

avrdude: reading input file "led.hex"

avrdude: input file led.hex auto detected as Intel Hex

avrdude: writing flash (88 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 88 bytes of flash written

avrdude: safemode: Fuses OK