Skip to main content

Posts

Showing posts from November, 2017

Day 15: Higher Dimensional Arrays and Pointers | Transistors and Motors

Software Higher Dimensional Arrays Arrays can be defined with more than two subscripts  Example 1.1 Three-Dimensional array int b[3][4][2]; The 3 subscripts correspond to the x, y, and z coordinates if the array is positioned at the origin of a 3-dimensional space.  Arrays with more than 3 subscripts are rarely used, and could cause many issues and complicate debugging and maintenance of the program... at least in C. That's a job for Matlab.  Addresses and Pointers One of the main lessons we learn in Engineering 6, and perhaps in any course taught by Professor Martin Mason, is that if Professor Mason says that something is fun and that the students will love it, there is a very high probability that said topic is, in fact, not fun, and the students will not love it.  So of course, when it was said by Professor Mason that pointers would be loved by all, a ripple of fear traveled through the room.  Luckily, David, who described himself as ...

Day 26: EEPROM | C++ Classes

Hardware: EEPROM Electrically Erasable Programmable Read-Only Memory non-volatile memory Why Use EEPROM Situations where data unique to situation needs a more permanent home What kind of data can be stored Anything that can be represented as bytes One byte=8 bits Software In C++, classes are building blocks of object-oriented programming Similar to structure, except designed to also include function members  Instances of a class are called objects Defining a Class Data Type Class definition consists of two parts: class declaration and class implementation Class declaration: name of class is specified using the keyword "class," body of declaration consists of type declaration statements for the data members and function prototypes for function members Example 1.1 class sample { public: void print(); double variable(); }; Class design includes function members to implement desired operations.  Example 1.2 // These sta...

Day 24: BMP180 | C++ Skills Development

Hardware: BMP180 // Calibration values int ac1; int ac2; int ac3; unsigned int ac4; unsigned int ac5; unsigned int ac6; int b1; int b2; int mb; int mc; int md; // b5 is calculated in bmp180GetTemperature(...), this variable is also used in bmp180GetPressure(...) // so ...Temperature(...) must be called before ...Pressure(...). long b5; // Calculate temperature given ut. // Value returned will be in units of 0.1 deg C const unsigned char OSS = 2; // Oversampling Setting short bmp180GetTemperature(unsigned int ut) {  long x1, x2;  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;  x2 = ((long)mc << 11)/(x1 + md);  b5 = x1 + x2;  return ((b5 + 8)>>4); } // Calculate pressure given up // calibration values must be known // b5 is also required so bmp180GetTemperature(...) must be called first. // Value returned will be pressure in units of Pa. long bmp180GetPressure(unsigned long up) {...

Day 23: Intro to C++ | Data Logging with SD Cards

Lab: Data Logging with SD Cards SD Cards Nonvolatile memory, useful for storing info Can both write data to a file and read existing information from SD card Before doing anything, we first needed to format the SD card. It was quite simple to do, I simply right-clicked the card under "My Computer"and selected the format option. Since the card I was using was 4GB, I used FAT32 for the file system type. Then I just clicked start to format it.  Interfacing with Arduino SD cards are 3.3V devices SPI: Serial Peripheral Interface bus. SD communication utilizes this Arduino comes with SD library, which abstracts away lower-level SPI communication and allows user to easily read and write files on SD card SD Card SPI Interface Pins Used: MOSI: Master Output, Slave Input.  MISO: Master Input, Slave Output SCLK: Serial Clock CS: Chip Select Writing to an SD Card Now it was time to actually take a shot at writing data to an SD card. I followed all...