Sunday, December 10, 2017

06 December '17- Project 3- Rocket Payload

Project 3:
Our lab group consisted of Matthew, Richard, and I.  we decided to utilize the MPU 9255 9 axis sensor along with an SD card to store the data and an arduino Nano to run out program on.  We were initially given an arduino micro but quickly found out we did not have enough storage to fit our entire code onto.  Once we could fit our program on the Nano, we began to put all the sensors together and start soldering.  I initially thought it would be better to solder everything onto a perforated board.  Professor mason advised that it would be easier to solder everything directly to the board directly without having to use perforated board.  I continued on my initial plan of using the board and quickly understood why he suggested against it.  The board was insufficient in keeping any sort of solder properly secured onto it and also the pins soldered onto the arduino didn't absorb any solder when heated up.  So, after having most of the components on the perforated board i had to discard of the pins and find another Nano to use since the pins would not unsolder.  After lots of desoldering and soldering the payload was tested out with the final iteration of the code.  At first it seemed fine but realize there needed to be some modifications to account for certain values.  On launch day, the class was at a mad scramble to finishing packaging the rocket payloads, finding center of gravity, adding nose weight, and folding parachutes.  At the end of the day everyone had a successful launch and every group was able to successfully retrieve data from the payloads.
(screen shot for the initial startup for the payload; we would eventually scrap it due to storage limitations on the board) 
(The Nano we initially used but was not working and replaced afterwards)
(we had took a picture f the error that  kept popping up when trying to upload the program; problem was the usb cable we were using)


(Screen shot from Matthews laptop of the program that would go onto the Nano)





(testing out the payload after completing the assembly) 




(using styrofoam board for packing into rocket)



(Matthew, David, and I after walking out to where the rocket landed.  unsuccessful launch,  the motor tube centering ring came out and separated from the bottom half of the rocket.  Richard can be seen in the distance picking up the bottom half)


(the data from our rocket launch; includes: acceleration, gyro, magnetic field, yaw, pitch, roll, pressure, and altitude; our max altitude was 1940.6 ft)

30 November 2017- Day 26- Real Time Telemetry/ MPU 9255/ Complex Class

Day 26: Todays lab was introducing u to real time telemetry and the MPU 9255.  The real time telemetry module is often used for quad copters and is a fairly inexpensive option for seeing what is going on as its happening.  a simple usb connection to the computer, RX and TX connection on arduino with power and ground, and this module is simple to setup.  One other necessity is to download another serial monitor to be able to see live data stream onto your computer.

(connection made to Arduino for real time telemetry.)
The other portion of the lab was to setup up a MPU9255. This sensor is a 9 axis MEMS sensor with an integrated BMP 280 pressure sensor.  This module can read acceleration, gyro, and magnetic field in 3 directions along with the pressure and altitude.  My lab partners had success in getting both the telemetry and also the MPU9255 to work and sen back data to the serial monitor.  This was critical portion in our project to be able to get and record data for the flight of our rocket.

(fritzing diagram for the MPU9255)
After the lab we began discussion on Complex class with overload operators.  Professor Mason began to talk about complex number and also complex roots for the quadratic equation and thats where i began to get lost.  At this point in the class i began to put most of my focus on project 3, which was getting the rocket payload to work properly with my lab partners.  Matthew and Richard both tackled the coding while I worked on building the rocket we would launch and also the hardware soldering and packaging of our arduino into the rocket payload section.



28 November 2017- Day 25- EEPROM and C++ classes

Day 25: Lab began with learning about another way to store data collection but on the arduino board itself.  EEPROM stands for Electrically Erasable Programmable Read-Only Memory. 
The neat thing about this form is that it can remember things even when there is no power.  this kind of memory can store generated due inside of a sketch on a more permanent basis.  Certain situations such as a cycle counter where a user is not allowed to reset the count could be useful for this type of memory.  It is also possible to add more EEPROM storage external with the addition of I2C EEPROM chips that can greatly increase the Arduino storage.  For the lecture portion of class we began discussion of C++ classes.  These classes are separated into two parts: the declaration and the implementation.  The body of the class declaration has declaration statements for the data members and function prototypes for the function members. Class implementation consists of all the member defined functions.  We also discuss constructor functions.  These functions are special member functions that are automatically called when an object in that classed is declared.   Another topic we went over in class what the class operators.  The ability for the user to overload operators in C++ is a powerful feature that can be as easily as predefined data type.  

Saturday, December 9, 2017

21 November '17- Day 24- Python Visualization and MPU 6050

Day 24 started with a Mega Lab as Mason describes it.  This lab was to include a visual representation of objects in motion using Python and also involved the usage of the MPU 6050.  The python lab was a bit of a disappointment on my end since my laptop was unable to download all the necessary software to use in the lab.  My lab partners were successful in getting the python running on their laptops.  I stood by and watched as they adapted the Python code into the Arduino IDE.  One of the sensors that first utilized in python was the ultrasonic HC-SR04 sensor.  This sensor can give an accurate distance of an object.  The Python visualization portion of it allowed the program to change the length of a cylinder by integrating the distance sensors reading when moving your hand toward and away from it.  The MPU 6050 is an Inertial Measurement Unit.  This device can measure with an integrated accelerometer, gyroscope, magnetometer, and altimeter.  Once we got the python visualization to work properly on the computer we then carried on to the sensor and getting data to read back from it.  The sensor gave our lab group some initial troubles since our data was not quite exact to what other groups were getting.  We found out later on that we had the wrong sensor and had to find the correct one to use.  Once we got situated the sensor values came out as predicted.

(An example of how the accelerometer function in the IMU)

(interfacing the MPU6050 with the arduino)
(implementing the sensor for our rocket project; the pitch, yaw, and roll of the rocket described above )





16 November 2017- Day 23- C++ Skills Improvement/BMP180 Pressure Sensor

Day 23: The lab for today included the BMP180 sensor.  This sensor is capable of reading pressure value range between 30,000 and 110,000 Pascals.  The board also include a temperature sensor that is capable of detecting a range between 0 and 65 C.  This sensor is ideal for measuring pressure changes and can be utilized for altimetry inside of our rocket project.  The board is I2C compatible which makes it a great addition to any related projects using this digital interface.


(A simple connection to the Arduino board for the BMP180)
 Note that this sensors maximum supply voltage is 3.6v.  Do not connect it to the 5v pin on the arduino.
For the lecture portion of class we were given more insight on a C++ program that can determine which direction the trade winds will be blowing.  This following is the program for the tradewinds:
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
/*  Declare variables.  */
int r, c, k, maxk=0;
int grid[5][5], category[8]={0,0,0,0,0,0,0,0};
double perc;
char* direction[8]={"N  ","NE ","E  ","SE ","S  ",
"SW ","W  ","NW "};
ifstream winds;
/*  Read and print information from the file.  */
winds.open("winds1.txt");
if (winds.fail())
     cout << "Error opening input file." << endl;
else
     {
     for (r=0; r<=4; r++)
          winds >> grid[r][0] >> grid[r][1] >> grid[r][2]
          >> grid[r][3] >> grid[r][4];
     //  Determine sums for the direction categories.
     for (r=0; r<=4; r++)
          for (c=0; c<=4; c++)
          {
          k = grid[r][c];
          category[k]++;
          }
//  Determine category with maximum sum.
     for (k=0; k<=7; k++)
          if (category[k] > category[maxk])
               maxk = k;
//  Print report.
cout.setf(ios::fixed);
cout.precision(1);
perc = (double)category[maxk]/25*100;
cout << "The wind is blowing from the " << direction[maxk–1]
<< perc << "% of the time." << endl;
//  Close file.
winds.close();
}
//  Exit program.
return 0;

}

For homework, we took this program and modified it to output a percentage and direction of the winds blowing, a possible hurricane/cyclone output, and also read from a data file of 100 rows by a 100 columns.  

14 November 2017- Day 22- Introduction to C++ and logging with SD cards

Day 22:
The affordable nature of working with arduino and the ease of implementation for just about any electronic sensor allows this platform to be an ideal solution for collecting large amounts of data.  The only drawback to the arduino is the limited space available on the chip for storing data.  One way around these restrictions is to include an SD card to store .csv files that can be easily retrieved and also stored in large data sets.  A good example is a weather station.  They require to be put in remote locations and left to collect for long periods of time.  Storing all the information such as pressure, wind speed, temperature, and humidity can be easily accessed in an excel file.
Before starting to use an SD card you must format the card to the proper file system type.  The arduino also comes with an SD library with all necessary functions to properly implement into your program.  When writing to an SD card it is important to note that the file names must be in 8.3 format.  This means the extension can only be 3 characters and the name must be 8 characters or fewer.  Reading from an SD card can be helpful for setting program parameters. For homework we were required to implement the SD card and a temp sensor to collect the temperature once a min and store into an excel file.

(example of the program for saving to SD card.)
(SD card shield hooked up to Arduino; buttons were just left on breadboard)

For the lecture we were introduced to the C++ language.  We noticed of the bat that a lot of the same features in the C language translate almost verbatim to the C++.  C++ also had some new features but not much different than its predecessor.  The following are a side by side example of the same program in both C and C++ to see the differences between the syntax but have the same output:
 Velocity/Acceleration Program in C:
#include <stdio.h>
#include <math.h>

int main(void)
{
/* Declare variables. */
double time, velocity, acceleration;
/* Get time value from the keyboard. */
printf("Enter new time value in seconds: \n");
scanf("%lf",&time);
/* Compute velocity and acceleration. */
velocity = 0.00001*pow(time,3) - 0.00488*pow(time,2) + 0.75795*time + 181.3566;
acceleration = 3 - 0.000062*velocity*velocity;
/* Print velocity and acceleration. */
printf("Velocity = %8.3f m/s \n",velocity);
printf("Acceleration = %8.3f m/sˆ2 \n",acceleration);
/* Exit program. */
return 0;
}

Same program in C++:
#include <iostream>
#include <cmath>
using namespace std;
int main(void)

{
// Declare variables.
double time, velocity, acceleration;
// Get time value from the keyboard.
cout << "Enter new time value in seconds:" << endl;
cin >> time;
// Compute velocity and acceleration.
velocity = 0.00001*pow(time,3) - 0.00488*pow(time,2)
+ 0.75795*time + 181.3566;
acceleration = 3 - 0.000062*velocity*velocity;
// Print velocity and acceleration.
cout.setf(ios::fixed);
cout.precision(3);
cout << "Velocity = " << velocity << " m/s" << endl;
cout << "Acceleration = " << acceleration << " m/s^2" << endl; // Exit program.
return 0;
}


First off, you notice the input and output statements at the beginning of the program. Also, the print statements have a different syntax with cout and << for setting what needs to print out from the program.     We start to find out that the same way functions, arrays, and data files are used in C are also used similarly in C++.  

09 November 2017- Day 21- Dynamic Data Structures

Day 21: Class began with the lab using more interrupts with timer this time. This time we used a speaker that would pay a certain note scale that would change by an octave when a button was pressed at any point in the progression.  The volatile variables change inside the interrupt.  Also, the timer interrupt function is set to milliseconds.

(fritzing diagram for the speaker interrupt lab)
The class lecture was on dynamic data structures.  Data structures can store data and allocate memory, when required, depending on the size of the data file.  also, they can shrink and grow during the execution of a program.  There are certain pre defined data structures in C such as, int, boolean, and character.  These are known as primitive data structures.  There's also user defined data structures such as arrays, lists, and files.  Lists have both linear and non-linear forms.  There are certain advantages and disadvantages to each type.

07 November '17- Day 20- Arrays Structures and Timer interrupts part 1

Day 20: the day of reckoning. As we began the class, we felt a eerie aura surround professor mason as he walked into the classroom grinning from ear to ear.  He had a look in his eyes that would make any grown person tremble to the bone.  His long strides felt thunderous as he made his way to the front of the classroom.  He carried his head high and peaked out to the students as their lingered over their keyboards as they furiously try to finish whatever work they hadn't finished.  It has become apparent that most students have succumbed to the ever dreary nearing end of the semester.
The lab began with introduction into interrupt timers.  This neat little trick allow the Arduino to work almost simultaneous with multitasking.  In essence, it effectively can weave tasks together.  Using hardware interrupts are triggered depending on the state, or change of state, of an input I/O pin.  this allows you to not have to poll the state of a button each time through the loop.  hard ware interrupts are a trade off from polling input pins.  to ensure the arduino is listening for the interrupt you must declare the variable with volatile before the variable you want to watch.  part of the homework was to implement a CdS sensor to immediately change an LED red when the sensor goes dark.
(the program for the interrupt lab)
After the lab professor mason introduced us to the arrays of structures in C.  Structures allow us to sort information in arrays with multiple variables and be able to access within the array for any structure. Again for homework we have to categorize hurricanes and be able to utilize the structures to input names, categories, and also dates for each storm.

(given table of information for homework)

For homework we had to use this table to write a program that will be accessible for modifying and printing out different data sets.
  

Monday, November 27, 2017

02 November '17- Day 19 - Programming Pointers and STR functions

Day 19: the class began with lab on dan sequencing and using character strings to be able to take inputs and find the number of occurrences and also the locations. Next came the modifications to the program which included printing out long and short strings, allow the user to enter short or long strings, read long strings from a file and input short, modify to use either lowercase or uppercase letters, and check the length of short string with long string.
Here is the code for the lab:

/*––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-*/ 
/* This program initializes a long character string and a short */ 
/* character string. It then prints the locations of the short */
 /* string in the long string. It also prints the number of */ 
/* occurrences of the short string in the long string. */ 
#include <stdio.h>
#include <string.h>
int main(void)
{
/* Declare and initialize variables. */
int count=0;
char long_str[]="AAACTGACATTGGACCTACTTTGACT",
short_str[]="ACT";
char *ptr1=long_str, *ptr2=short_str;
/* Count the number of occurrences of short_str in long_str. */
/* While the function strstr does not return NULL, increment */
/* count and move ptr1 to next character of the long string. */ while ((ptr1=strstr(ptr1,ptr2)) != NULL)
{
printf("location %i \n",ptr1-long_str+1);
count++;
ptr1++;
}
/* Print number of occurrences. */
printf("number of occurrences: %i \n",count);
/* Exit program. */

return 0;
} /*
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-*/ 

The following is what was generated:


location 3
location 18
location 24
number of occurrences: 3

24 October '17- Day 17- Pointers in function references & Joystick and robot car

Day 17 of class began with the lab involving the use of a joystick to control the robocar we had worked on previous to utilize a motor control board.  once both motors were hooked up to the drive line on the car it was a simple task to connect the wires to the motor control board.  The tricky part became trying to figure out which wire was going to move the motors in unison or opposite directions.  A little bit of testing out each motor by applying a voltage for a short moment, we took note of the direction of the motor spinning in order to hook them up correctly.
After ab we began lecture which introduced then use of pointer in function references.  Character strings were also discussed and how they can used in cryptography and pattern recognition software.

(screen shot of the code for the motor controller)

(the over head view of the robocar and components)

(close up of joystick connections to line up the correct wire color code on the arduino board)

(First getting one motor to work using the motor control board; also the motor controller we used is different)

(close up of breadboard with one motor control by the potentiometer)

26 October '17- Day 18_ Bluetooth wireless connection & Dynamic memory allocation

Day 18.  The class began with the overall excitement to learn about blue tooth connectivity with Arduino.  A few student additions ,from days of past, came into the class to learn of this so called bluetooth magic.  The Lab included the bluetooth shield we were to work on and get connected with via our laptop or smartphone.  This task was no small feat.  Since everyone in the class was trying to connect to their bluetooth Arduino shield, it became a fiasco to figure out whose board belong to whom in the slue of identical device names.  Some were more successful than other when it came to identifying the correct devices and only one or two groups were successful in renaming their devices.  As the lab went on, certain students fell onto dark times as they were unable to ultimately crack the davinci code for their bluetooth lab.  The professor of the dark arts, Sir Martin Mason, began to instruct on how to properly utilize dynamic memory allocation in our C programming for the class.  This became a vital process as to run a program with not enough memory available could cause it not to run.  it can also optimize the amount of run time the program would need to complete what ever process we assign it.
(the arduino bluetooth shield connected including the lcd screen for the project)
 

Wednesday, November 15, 2017

17 October '17- Day 15- Higher dimensional arrays and pointers

Beginning of class we were introduced to higher dimensional arrays and pointers.  most engineering problems can be solved using 1 or 2 dimensional arrays but on occasion a 3 dimensional array can be useful.  We also began discussion on addresses and pointer in C.  An address is a specific integer value to specify the memory location.   in order to properly utilize this feature we must move away from using repl.it and use a compiler that we can use offline.  Virtual-C IDE is one example of a downloadable compiler from the many out there.
Once an offline compiler has been installed, using pointer to reference memory locations is much more reliable.  The overall advantage to using pointers in a program is to optimize the speed at which the program runs and use less memory.
(example showing the Virtual-C IDE program and a sample code using pointers.)
In Lab we began discussion on how to wire up and control a c motor using a potentiometer.  The POT value in the middle would stop the motor and turning the POT to the left or right would speed up the motor in that direction.  Certain precautions must be made to protect the Arduino board since the pins are not designed to run a dc motor so having protection diodes and a secondary power source to run the motor are necessary.  

(Lab using a potentiometer to control the direction of the spinning dc motor)
(mounted dc motor on the robocar chassis)









Monday, November 13, 2017

19 October '17- Day 16- H-Bridge and and Motor Driver

The class began with Mason introducing our lab for the day.  The lab was to be able to control a motor using an H-bridge controller.  Named so because the diagram of the switches looks similar to the letter H.  The h-bridge controller allows you to control a dc motor and be able to reverse its direction with a command to close 2 diagonally located switches and vice versa for forward movement.  The L9110s is another type of motor controller but allows to connect two dc motors on the same shield as opposed to the single motor controller.  L9110s also is more affordable and convenient with the terminal blocks on the board instead of having to solder directly to the board.  


(diagram of L9110s, the power and ground are connected where the motor inputs should go)
(wired up one motor with the single motor controller and a potentiometer to control the spinning direction of the motor)
(An L9110s installed on robocar with two dc motors and joystick to control movement in every direction)

After Lab we began discussion about pointers and how they're used in C.  A pointer is a variable containing the address of another variable.  Plain and simple, these pointers are used to run programs faster and use less memory.  Pointers are also utilized to allocate memory for an array at future usage.  

(examples on how pointers and arrays work together)
(more examples of pointers)

(more pointer examples)