Corning Community College
ENGR1050 C for Engineers
Explore some new component from the electronics kit: construct and test a circuit, demonstrate operations with software.
We are now onto part 3, where you will complete the finished product.
Do note, the productive way to go about this project involves taking the following steps:
If you start too late, and do not ask questions, and do not have enough time and don't know what is going on, you are not doing the project correctly.
This is part one of a sequence: decide on some project you’d like to pursue, this project lays the groundwork of understanding of individual components.
Peruse the Freenove tutorial PDF, generate ideas, don’t bite off more than you can chew (considering you have about 3 weeks).
And document your selection, progress, and final results on the project documentation page!
No grabit for this project: you should be able to reference previous project demos and create working programs from what you’ve used and what you’ve learned.
It would be highly recommended to create a eap0/ directory in your repository, alongside your other projects, and perhaps to call your program eap0.c
The Makefile from other projects can be adapted to work with your current endeavour (would only need to change perhaps one line near the top of the Makefile in a text editor).
You will want to go here to edit and fill in the various sections of the document:
Edit your section here and provide a description of what it is you’d like to build by the end of this endeavour.
From the tutorial or other resources, identify what components from your electronics kit you are going to be testing, and provide any pertinent information regarding its operation (ie not entire programs, but succinct nuggets of information that could be useful to others wanting to get up and running).
Edit your section here and provide that pertinent information.
My plan is to control a stepper motor using two buttons. One button will make the stepper motor rotate some fixed amount clockwise. The other button will make the stepper motor rotate the same fixed amount counterclockwise. The rotation amount will be hard-coded into the program. Perhaps if everything else goes smoothly, I'll try to use a potentiometer to control the motor rotation amount.
For the first week I started with wiring and coding a stepper motor. I have a program which continuously moves the stepper motor either clockwise or counterclockwise. Next I need to expand the program to rotate a certain fixed amount and also use the states of the buttons to control direction.
The buttons have been added in to the wiring. The feedback from the buttons has also been incorporated into the program. Currently, the stepper motor rotates continuously one direction while one button is pressed, and continuously in the other direction while the other button is pressed. Next I need to program the motor to rotate a fixed amount upon each button press.
The stepper motor system works well. There are two buttons. When one of the buttons is pressed, the motor rotates clockwise. When the other button is pressed, the motor rotates counterclockwise. The amount that the motor rotates is set within the program. 20231108_204902.jpg
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
I want to use joystick to change the color of a 4 legged light.
I used the following code to read the x,y & z values of the joystick as it moves.
#include <wiringPi.h> #include <stdio.h> #include <stdlib.h> #include <softPwm.h> #include “ADCDevice.cpp” #include <time.h> /
#define Z_Pin 1 define pin for axis Z ADCDevice *adc; Define an ADC Device class object
/
int main(void){ adc = new ADCDevice(); printf("Program is starting ... \n");if(adc->detectI2C(0x48)){ // Detect the pcf8591. delete adc; // Free previously pointed memory adc = new PCF8591(); // If detected, create an instance of PCF8591. }else if(adc->detectI2C(0x4b)){// Detect the ads7830 delete adc; // Free previously pointed memory adc = new ADS7830(); // If detected, create an instance of ADS7830. }else{ printf("No correct I2C address found, \n" "Please use command 'i2cdetect -y 1' to check the I2C address! \n" "Program Exit. \n");return -1; }
wiringPiSetup(); pinMode(Z_Pin,INPUT); //set Z_Pin as input pin and pull-up mode pullUpDnControl(Z_Pin,PUD_UP); while(1){ int val_Z = digitalRead(Z_Pin); //read digital value of axis Z int val_Y = adc->analogRead(0); //read analog value of axis X and Y int val_X = adc->analogRead(1); printf("val_X: %d ,\tval_Y: %d ,\tval_Z: %d \n",val_X,val_Y,val_Z); delay(100);} return 0; }
I set up the leds circuit and using softPwmWrite made it so the lights numerical sate coresponded to the x,y or z value it was linked to. Although the z value can only be 1 or 0 so when it equaled 0 the third pin to the light would equal 100.
val_Z = digitalRead(Z_Pin); read digital value of axis Z if(val_Z == 0){ softPwmWrite(HREPIN, 100); } else{ softPwmWrite(HREPIN, 0); } / val_Y = adc→analogRead(0); read analog value of axis X and Y
softPwmWrite(TWOPIN , val_Y);///////////////////////////////////////////////////////////// val_X = adc->analogRead(1);softPwmWrite(ONEPIN , val_X);
When moving the joystick around the light changes color and when any of the values hit their max one of the single led's will turn on.
/
val_Z = digitalRead(Z_Pin); //read digital value of axis Zif(val_Z == 0){ softPwmWrite(HREPIN, 100); digitalWrite (GRNLED, 1); } else{ softPwmWrite(HREPIN, 0); digitalWrite (GRNLED, 0); } ///////////////////////////////////////////////////////////// val_Y = adc->analogRead(0); //read analog value of axis X and YsoftPwmWrite(TWOPIN , val_Y);if (val_Y == 247){ digitalWrite (REDLED, 1); } else{ digitalWrite (REDLED, 0); } /////////////////////////////////////////////////////////////
https://www.youtube.com/playlist?list=PLpR-bDNsxP5swtO5DQ5bhKbo7tLxqU75V
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
for the project, i plan on creating a circuit utilizing the ultrasonic sensor, 3 leds , and a buzzer. The overall goal is to make it so that at a certain distance an object is from the sensor, the leds will fill up, and when the leds are all on, a buzzer will go off.
I understand the premise of the circuit, and believe this will be an easy but tedious task.
ULTRASONIC SENSOR - a sensor that measures distance based on how long a sound wave takes to bounce back
ACTIVE BUZZER - a buzzer that makes noise when power is sent to it
LED - a light emitting diode
all that had to be done, was grab the c code downloaded with the starter manual for the pi, then add a couple if statements to compare the distance to a set distance, and if the distance was smaller, to turn on each light and then the buzzer, all of which were put into an array
the sensor needed to be hooked up to two different pins, with the echo pin needing 3 1kohm resistors also leading to our ground
the buzzer only needed a 1kohm resistor leading to a transistor, which ultimatly controls the buzzer
each led needed a 220ohm resistor.
looks like a piece of junk, but the closer you move your hand, the more lights pop up. the lights are put out of the way of the wires so its easier to see. Essentially, the pi is generating distance info with the sonar, then comparing that to a set distance, and turning on and off pins as it exceeds or fails to exceed those set distances
I want to use the seven segment display as a counter of some kind. I will probably use it with a button and a switch that makes the number displayed increase or decrease.
I am testing the Seven Segment Display, which uses the 74HC595 chip to display a variety of symbols. It can be used in counting, and I want to test its ability to count in hexadecimal.
In this part, I wanted to test how I could use the button with the seven segment display. I decided to have the button change the speed at which the display counted. Pressing the button more, means that the counter will slow down, since the delay is greater. I could also use another button or a switch to make it speed up as well, but this was mostly to confirm that the button could work and affect the seven segment display
For the finished product, I have a seven segment display that shows a hexadecimal counter that can be slowed down or sped back up to regular speed. Pressing the blue button slows the counter down the more you press it. Pressing the red button sets the speed at which it counts back to normal. These two buttons can be used to slow or speed up the counter in a way, without having to worry about a negative delay happening.
For my project I will be working with the 7-Segment Display and learning more about its functions along with 74HC595 chip. The display allows you to see an actual number or letter.
I left enough room at the bottom to test out using a button to control the display, one button to count up and another button to count down. Thats not definite.
I would like to explore using the 74HC595 chip with the seven segment display. I would like to program it to count even, odd then 0-9 number.
description of finished project details (not full source code), but present your finished product
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
The end project will be a timer that is turned on and off with a button and utilizes the 4 digit 7-segment display
I have decided to start with testing out the single digit 7-segment display and trying to display numbers 0 through 9
Now I will be using to 4 digit seven segment display as opposed to the 1 digit display. My main goal for this segment of the project is to get the numbers to both display and to change.
description of finished project details (not full source code), but present your finished product
Use a proximity sensor to determine the distance and display on an lcd screen.
I will be using a proximity sensor or ultrasonic sensor and an lcd screen for this project.
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
In my project, I would like to control some servos using data from the mpu6050. Ultimately, these will be attached to control surfaces in an “autopiloted” glider. Eventually, I would also like to use an ultrasonic sensor to detect how far this system is from the ground and initiate a landing sequence.
The components I have selected are the mpu6050 and servos attached to an Arduino Nano. The mpu6050 is a “motion tracking” device that provides accelerometer and gyroscope data necessary for this project. The mpu6050 only needs to be connected through SDA and SCL to provide data to our microcontroller (and of course power/gnd).
The servos are motors that can be used to precisely control our glider's control surfaces. The servos can be controlled via data line and must be connected to a PWM pin on the Arduino Nano. There is a handy-dandy Arduino library called “Servo.h” that simplifies the process of controlling servos greatly. You can initialize servos as objects in the code and easily write angles to servos without needing to worry about PWM (Pulse-Width Modulation).
The Arduino Nano is the microcontroller I am using to control the components in this circuit. Using the Arduino IDE we can load “sketches” (instructions) onto the Arduino Nano. The Arduino IDE uses its own modification of C/C++. The Arduino can be provided power (and sketches) through its mini USB port, or can be powered by a battery up to 12V (recommended). Before submitting code sketches to the Arduino Nano, you can click the verification button in the IDE to compile the code and see any errors.
The MPU6050, Arduino Nano, and Servos have all been integrated on a circuit together. The servo meant to control the rudder has been fixed. Instead of using accelerometer data from the MPU6050, registers ACCEL_ZOUT_H (0x3F) and ACCEL_ZOUT_L (0x40) as specified on the register map, the code has been updated to use the gyroscopic data located at registers GYRO_ZOUT_H (0x47) and GYRO_ZOUT_L (0x48).
After initial setup (everything outside of the “main” loop() function); where we create our Servo objects and attach them (via Servo.h), initialize important variables, and set up communications to our mpu6050; the remaining code simply reads data from the MPU6050, scales down the data by a factor of 180, and delivers that “angle” in degrees to our servos.
This process is repeated for each Euler angle necessary (yaw, pitch, roll), so we need only to dissect one block to understand the rest:
//// X-axis: "Yaw", although this would normally be the Z-axis Wire.beginTransmission(mpu6050); Wire.write(0x47); // gyroscope instead of accelerometer Wire.endTransmission(false); Wire.requestFrom(mpu6050, 4, true); AcX = Wire.read() << 8 | Wire.read(); x_ang = AcX/180;
The first 3 lines of this block,
Wire.beginTransmission(mpu6050); Wire.write(0x47); // gyroscope instead of accelerometer Wire.endTransmission(false);
are mostly self-explanatory.
On the first line, we're starting an I2C connection to the MPU6050 using it's address (0x68). From the second line, we queue up the information we want to send; namely, the register we're trying to access. And the third line ends the transmission, sending that information on its merry way over to the MPU6050.
The next three lines of code:
Wire.requestFrom(mpu6050, 4, true); AcX = Wire.read() << 8 | Wire.read(); x_ang = AcX/180;
On the first, we're requesting bytes at the register address 0x47 (as previously set up) from the MPU6050. Specifically, we're requesting 4 bytes. Our final argument, true, releases the MPU6050 from the connection.
On the second line, we read the bytes we requested on the previous line. We left shift a byte to read the data from the adjacent register, 0x48, and OR those bytes together to retrieve the full information we need.
The final line is simply our scaling factor and a variable assignment.
As shown in the video above, all of the electronics are attached to a glider, with the main components (Arduino Nano, MPU6050, breadboard, etc.) stored in the fuselage. Wires have been ran under the red material on the wings from the “brain” in the fuselage to each aileron servo. As seen in the video, there are also wires wrapped around the black rod (arrow shaft) reaching to the servos on the tail.
There are two servos on the tail, one for the elevator and the other for the rudder. The rudder (yaw) is the “X-axis” as described in the code, but this is due to the mpu6050 being setup in an atypical way. That is to say, the relative orientation of the mpu6050 was arbitrarily chosen and the axes were programmed for that perspective.
The servos on the ailerons both function using the “Y-axis” (roll), and the elevator servo uses the “Z-axis.”
The glider is set on a flat surface before receiving power. As soon as the microcontroller, our Arduino Nano, receives power, the code starts. When the Arduino Nano turns on and supplies power to the MPU6050, the whole system calibrates itself to the orientation it currently sits at. This is why we need to make the glider level before supplying power.
Once the glider is calibrated, it can be freely moved wherever it needs to be moved before launching. Each of the servos will attempt to maintain a neutral position of all control surfaces. This results in a glider that maintains stabilization and heads straight (no rudder/aileron movement for turning).
The factors used to maintain these angles are described extensively in part 2.
This was a really fun project that I was more than happy to take part in. There are so many features that I imagine for future iterations that were beyond the scope, like having the glider follow a GPS-based path for a true “autopilot” system.
Currently I am exploring the LCD screen component to use as my project, I don't exactly know the functionality of it yet or how to use it.
LCD Module: A compact electronic component that consists of an LCD screen, a driver circuit, and a control interface (meaning very basic, not like a standard flat screen television with far better resolution & image processing).
A liquid-crystal display (LCD) is a flat-panel display or other electronically modulated optical device that uses the light-modulating properties of liquid crystals combined with polarizers. Liquid crystals do not emit light directly but instead use a backlight or reflector to produce images in color or monochrome. LCDs are available to display arbitrary images (as in a general-purpose computer display) or fixed images with low information content, which can be displayed or hidden: preset words, digits, and seven-segment displays (as in a digital clock) are all examples of devices with these displays. They use the same basic technology, except that arbitrary images are made from a matrix of small pixels, while other displays have larger elements. LCDs can either be normally on (positive) or off (negative), depending on the polarizer arrangement. For example, a character positive LCD with a backlight will have black lettering on a background that is the color of the backlight, and a character negative LCD will have a black background with the letters being of the same color as the backlight. Optical filters are added to white on blue LCDs to give them their characteristic appearance.
The only additions made, was a Blinking REDLED, which indicated whenever the CPU temperature would update. The interesting thing about it is you have to use one of the pin slots on the LCD module D7.
eap2 is the finished program, where the lcd module outputs the pi's CPU temperature and the time stamp associated with the temp readout. The temperature output is in Celsius and was 2 decimal places XX.XX. The program for the CPU temp updates every second, so I added a blinking led program for whenever the LCD display updates, giving a visual indicator.
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
The objective is to create code that will make the ultra-sonic sensor detect motions in front of it.
To start you will need 5 wires,3 1k ohm resistors, and an ultrasonic motion sensor. Have one wire hooked to a 5V power source and the other end attached to the VCC Pin, a wire in a GPIO pin going to “TRIG” and another GPIO pin connected with a wire leading to a 1k ohm resistor, and the GND pin should be connected to a wire going to ground.
The objective in eap1 is to make 3 leds flash for different distances. So for example I will have a red, blue and green LED all hooked up. When the ultra-sonic sensor reads any distance below 25cm the red LED will flash red. When the distance is between 26-50 the blue LED will flash up and the red one will turn off. When the distance exceeds 50cm the green LED will create a flash and the blue one will turn off.
My finished product consist of the ultrasonic Ranger, 3 LEDs and a buzzer. The LEDs turn on and off with certain distances. So the red will do 0-25, blue 26-50 and green 51-100. When the distance reads over 50 centimeters, the buzzer will begin to BUZZ! Using if and else statements for my lights and buzzer made this whole thing possible.
description of what you are looking to do
description of what component(s) you have selected and are testing
description of changes made and construction pursuits, and some details of C program interaction
description of finished project details (not full source code), but present your finished product
To be successful in this project, the following criteria (or their equivalent) must be met:
Let's say you have completed work on the project, and are ready to submit, you would do the following (assuming you have a program called uom0.c):
lab46:~/src/SEMESTER/DESIG/PROJECT$ make submit
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
I'll be evaluating the project based on the following criteria:
104:eap2:final tally of results (104/104) *:eap2:clean compile of code, no compiler messages [13/13] *:eap2:picture or short video of finished product to class chat [13/13] *:eap2:completed code using components to accomplish target [52/52] *:eap2:code tracked in lab46 semester repo [13/13] *:eap2:project documentation page updated with pertinent information [13/13]