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)

05 October '17-Day 12- Virtual-C IDE and LCD shield for Arduino

Class began with the new lab and Professor Mason introduced the LCD shield for the Arduino board.  The LCD consists of 16 column and 2 rows to display characters on and also has buttons built in that can be programmed to your liking.  The potentiometer at the top right corner of the board is to adjust the contrast of the screen.  The data pins 4-7 are used to transmit data.  Using the LiquidCrystal.h library allows the user to use set functions to make it user friendly and easy to interface.

(LCD displaying Engr-6 and increasing progress bar)



(a snap shot of the code for using the LCD in lab)

After messing with the LCD screen, we went on to talk about data files in lecture.  Data files allow you the ability of analyzing large data sets and store the information on a file that the program can access.  Utilizing an online compiler like Repl.it won't allow the creating and storing of data files since its in a directory the program may not have access to.  Using an IDE like Virtual-C allows the user to create and store data files locally for ease of access.  In order to access data files you must use a pointer "*" to reference the file in the program.  A pointer is a variable whose value is the memory address of another variable, like the memory address.  Reading data files is fairly straight forward with calling to them by name and with an "fopen" statement to associate the file with its pointer.  

10 October '17- Day 13- I2C Bus

Class began with Mason introducing the I2C bus and it features. This communication protocol was invented in the 80s and became a standard in the industry by the 90s.  The I2C bus is controlled by a master device (such as the Arduino) and talk to one or more slave devices utilizing only two input and output pins.  Each slave device has a unique address that can be called on by the master in order to communicate with that specific slave device.  This allows for many slave devices to be called upon via the same master device.

After the brief introduction into the I2C we began lecture with two dimensional arrays.  in the C language we can include data that is in a grid or table setup.  Rows begin with 0 as the first horizontal grouping and columns are the vertical groupings of data.  A good implementation of two dimensional arrays is for terrain navigation.  a value is representing an elevation on a terrain and an indication of a peak or valley can be identified by a large differentiation of values surrounding any given point.  Peaks are represented by a large value and valleys are depicted with lower values.  For homework we were to write a program that will read the data file for elevation and then print out the number of peaks and their locations.  
(White board exercises on two dimensional arrays)

(more exercises going over two dimensional arrays)