Skip to main content

Posts

Day 17: Pointers in Functions | Joystick and Robot Car

Lab The baud needed to be changed manually in the serial monitor to the correct baud set in Serial.begin, otherwise strange symbols like this would show up: Once corrected, this is how it looked Programming Homework Our homework was to get the robot car working and responding to the joystick. Once Anthony and I successfully did this, we took the robot for a walk down the hall.
Recent posts

Day 16: More Pointers | HBridge Motor Control

Hardware Main Code:  const int en=A0; const int mc1=7; const int mc2=8; const int pot=A1; const int pwm=5; int val=0; int velocity=0; void setup() {   // put your setup code here, to run once:   pinMode(en,OUTPUT);   pinMode(mc1,OUTPUT);   pinMode(mc2,OUTPUT);   pinMode(pwm,OUTPUT);   brake(); } void loop() {   // put your main code here, to run repeatedly:   val=analogRead(pot);   if(val>562)   {     velocity=map(val,563,1023,0,255);     forward(velocity);   }   else if(val < 462)   {     velocity=map(val, 461, 0, 0, 255);     reverse(velocity);   }   else   {     brake();   } } void forward(int rate) {   digitalWrite(en,LOW);   digitalWrite(mc1,HIGH);   digitalWrite(mc2,LOW);   analogWrite(pwm,rate);   digitalWrite(en,HI...

Day 25: Python, Graphing, 3D Visualization and Inertial Measurement

Python Arduino Code int trigPin=13; //Sensor Trig pin connected to Arduino pin 13 int echoPin=11; //Sensor Echo pin connected to Arduino pin 11 float pingTime; //time for ping to travel from sensor to target and return float targetDistance; //Distance to Target in inches float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees. void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trigPin, LOW); //Set trigger pin low delayMicroseconds(2000); //Let signal settle digitalWrite(trigPin, HIGH); //Set trigPin high delayMicroseconds(15); //Delay in high state digitalWrite(trigPin, LOW); //ping has now been sent delayMicroseconds(10); //Delay in low state pingTime = pulseIn(echoPin, HIGH); //pingTime is presented in microceconds pingTime=pingTime/1000000; //convert pin...

Day 22: More with Timers | Dynamic Data Structures

Hardware: Using Timer Interrupts Software: Dynamic Data Structures Anything that stores data can be called as a data strucutre. "Dynamic data structures are data structures that can grow and shrink during the execution of a program."  Linked Lists Linear data structure which consists of a group of nodes in a sequence which is divided in two parts. Each node consists of its own data and the address of the next node and forms a chain. Advantages Dynamic, allocates memory when required insertion and deletion easily implemented Stacks and queues easily executed Reduces access time Disadvantages Memory wasted by pointers (require extra memory) No element can be accessed randomly reverse traversing difficult Applications Used to implement stacks, queues, graphs, etc.  Allows you to insert elements at beginning and end of list Don't need to know size in advance Head is pointer that points to the first node in linked list.  To access, us...

Day 18: Dynamic Memory Allocation | Bluetooth

Lab Background Info/Notes Standardized protocol for sending/receiving data via 2.4GHz wireless link Good for short-range, low-power, low-cost, wireless transmissions How it Works Use master/slave model Master can send and request data from slaves Slaves can only transmit to and receive from master Can't talk to other slaves Addresses and Names Each device has unique 48-bit address That's all theoretical. No matter what I did, I couldn't get the bluetooth to connect to my laptop. I tried resetting stuff, restarting my computer, using different code, using different hardware, nothing worked. I even took my laptop outside to try to connect it, but it simply wouldn't connect.  Software: Dynamic Memory Allocation Dynamic memory allocation allows for allocation of memory when program is executed instead of when it is compiled. Especially important when program uses array whose size is not determined until program is executed. It is specified w...

Day 27: Live Telemetry and MPU 9255 | C++ Classes with Overloaded Operators

Hardware: Live Telemetry and MPU 9255 Real Time Telemetry Telemetry seemed complicated, but it was a simple matter of hooking up the sensors correctly and getting Putty to communicate with the serial port. This portion was done fairly quickly. MPU 9255 + BMP280 Software: C++ Classes with Overloaded Operators Complex Class with Overloaded Operators Complex numbers needed to solve many problems in science and engineering, esp. physics and electrical engineering, therefore useful to define complex class in C++ Recall: complex number has form  a+bi where i=sqrt(-1) and a and b are real numbers Figure 1.1 Real and imaginary axis X is real axis and Y is imaginary axis Complex Class Definition Class declaration must include private members for real and imaginary components of complex number Public members include a function to input complex number from keyboard and function to print complex number on screen Also need member functions to define arit...

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 ...