Corning Community College
ENGR1050 C for Engineers
Create circuitry and configure software to discover and demonstrate the functionality of some as-yet unutilized component from your electronics kit.
Be sure to contribute useful background and operational information to this project documentation, to serve as a reference for others.
Your task is to:
Example:
To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.
lab46:~/src/SEMESTER/DESIG$ grabit DESIG PROJECT
You will want to go here to edit and fill in the various sections of the document:
https://www.youtube.com/watch?v=qjP3HpbPJTM&list=PLOkhax8xuWu0Yj-jJAzSNiDJfHfXVaY9_&index=14
A Joystick is a kind of input sensor used with your fingers. It can receive input on two axes (Y and or X) at the same time (usually used to control direction on a two dimensional plane). And it also has a third direction capability by pressing down (Z axis/direction).
Hard Wiring
Parts Needed: Raspberry Pi, Ribbon cable, Breadboard, Joysick, 10k Resistor, ADC module, Wires
Enable I2C
The I2C interface in Raspberry Pi is disabled by default. You will need to open it manually and enable the I2C interface as follows: Type command in the Terminal: sudo raspi-config Then open the following dialog box: Choose “5 Interfacing Options” then “P5 I2C” then “Yes” and then “Finish” in this order and restart your RaspberryPi.The I2C module will then be started. Type a command to check whether the I2C module is started: lsmod | grep i2c If the I2C module has been started, the following content will be shown. Install I2C-Tools Next, type the command to install I2C-Tools. It is available with the Raspberry Pi OS by default. sudo apt-get install i2c-tools I2C device address detection: i2cdetect -y 1 When you are using the PCF8591 Module, the result should look like this: Install Smbus Module sudo apt-get install python-smbus sudo apt-get install python3-smbus
C Code 7.1.1 ADC
For C code for the ADC Device, a custom library needs to be installed.
1. Use cd command to enter folder of the ADC Device library. cd ~/Freenove_Kit/Libs/C-Libs/ADCDevice
2. Execute command below to install the library. sh ./build.sh A successful installation, without error prompts, is shown below:
Joystick code
1. Use cd command to enter 12.1.1_Joystick directory of C code. cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/12.1.1_Joystick/
2. Use following command to compile “Joystick.cpp” and generate executable file “Joystick”. g++ Joystick.cpp -o Joystick -lwiringPi -lADCDevice
A Keypad Matrix is a device that integrates a number of keys in one package. As is shown below, a 4×4 Keypad Matrix integrates 16 keys (think of this as 16 Push Button Switches in one module). The 4×4 Keypad Matrix has each row of keys connected with one pin and this is the same for the columns. Such efficient connections reduce the number of processor ports required.
The method of usage is by using a row or column scanning method to detect the state of each key’s position by column and row. Take column scanning method as an example, send low level to the first 1 column (Pin 1), detect level state of row 5, 6, 7, 8 to judge whether the key A, B, C, D are pressed. Then send low level to column 2, 3, 4 in turn to detect whether other keys are pressed. Therefore, you can get the state of all of the keys.
The Keypad Matrix is best used when there is a need for a large number of buttons. Such a component can be used for something such as a pin code, but it is basically just a grid of 16 buttons that function the same way a single button does, and a button is a component that, when pressed, sends an electrical signal to some sort of output.
A great way to demonstrate the Keypad Matrix is a program that prints a message telling the user when a button has been pushed, and which button.
The first thing that someone would need to do to do this is to go to
https://github.com/Freenove/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi
and download the files here onto their raspberry pi. Once in the command terminal for your raspberry pi, you can type a series of commands to run the sample code provided in these files.
cd ~/Freenove_Kit/Code/C_Code/22.1.1_MatrixKeypad
g++ -o MatrixKeypad.cpp Keypad.cpp Key.cpp MatrixKeypad -lwiringPi
./MatrixKeypad
After the program is executed, pressing any key on the Keypad Matrix, will display the corresponding key code on the Terminal:
It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.
In order to generate the ultrasound you need to set the Trig on a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in microseconds the sound wave traveled.
For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.
using the prox sensor i was able to use the data the is produces and use it to project on a lcd screen
The distance sensor basically uses echolocation to detect distances. So on wonky surfaces the distance sensor struggles. The distance sensor likes to read against flat surfaces.
Basically my code reads a distance inputted by the distance sensor. Then, uses fprintf to display the distance.
An LED light is an electronic device that emits light when an electric current flows through it. So, an LED converts electrical energy into a light source. LED lights can also be used as an ON/OFF switch for a specific duration of code.
A proximity sensor is a device that can detect or sense the approach or presence of nearby objects without touching it. These sensors also convert the information that is received from the approach or presence of the objects into an electrical signal.
Parts Needed: Arduino Uno, LED x3, Breadboard, Ultrasonic Distance Sensor - HC-SR04, Wires.
Side Note: Even though there is a buzzer in the diagram, it was not used for the project. However, the buzzer, if wanted, is easy to add to the breadboard for the project. Just some of the code would need to be changed since there will be sound to the buzzer, showing that the buzzer is passive.
The proximity sensor reads an object placed in front of it and the LED lights tell how close the object is to the proximity sensor. The red LED flashes when an object is very close to the proximity sensor. The yellow LED flashes when an object is halfway from the proximity sensor. The green LED flashes when an object is very faraway from the proximity sensor.
Another way to think about the colors connecting with the distance from the proximity sensor is through the amount of risk each color is. The green LED represents that there is little to no risk where the object is to the proximity sensor. The yellow LED represents that there is a medium amount of risk where the object is to the proximity sensor. The red LED represents that there is a large amount of risk where the object is to the proximity sensor.
If an object is extremely close to the proximity sensor, then the distance will be between 0 and 10. If an object is somewhat close or halfway from the proximity sensor, then the distance will be between 11 and 31. If an object is very far away from the proximity sensor, then the distance will be between 32 and beyond to a never ending stopping number.
A Stepper motor is a brushless DC motor that divides a full rotation into a series of equal steps and can be used to hold a specific position. The steps remove the need for a position sensor as the computer already knows the number of steps said motor has taken and therefore it can calculate its position. In order for a stepper motor to spin the pins must be powered ON and OFF in a specific sequence. the sequence for the stepper motor in the kit is
SEQ# - [ [IN1],[IN2],[IN3],[IN4] ]
step 0 - [1,0,0,0]
step 1 - [1,1,0,0]
step 2 - [0,1,0,0]
step 3 - [0,1,1,0]
step 4 - [0,0,1,0]
step 5 - [0,0,1,1]
step 6 - [0,0,0,1]
step 7 - [1,0,0,1]
the following sequence will move the stepper motor 1/64 of a full rotation because the stepper motor in the kit has a 1:64 gear reduction so it will take 512 step to make a full rotation with this stepper motor or 64 sequences of the steps given above.
Stepper motors have a wide variety of uses and are commonly used in.
-3D printers
-slot machines
-paper printers
-CNC machines
-camera lenses
-disc drives
The LED bar graph component is comprised of 10 separate LED light circuits. Each LED require both power and ground similarly to single LED bulbs.
The LED bar graph can be used in a multitude of different applications.
Its applications include;
-Feedback of potentiometer position
-Motor speed feedback
-Sound level
-Distance from proximity sensor }
Programming a simple function of sequencing the lights down and then back up the LED Bar Graph is rather simple. If you follow the diagram depicted above, you will command the pin low to turn on the LED since we are wiring the GPIO to the cathode side of the LED.
For the code, we will use an array with our wiringPi pin assignments and ensure we set the pins as outputs. Then we will use index to cycle through the array and light our LED's in sequence
The PIR sensor allows you to detect when a person or animal moves in or out of sensor range. This sensor is what you’ll find in most modern security systems, automatic light switches, garage door openers and similar applications where we want to react to motion.
Common applications include automatic house or garden light, burglar alarms, security cameras and motion detectors, tracking animal movements. For my project, i started with hooking up the PIR sensor just to detect motion. After that was successful, i wired an LED to the sensor. Every time there is motion being detected, the LED lights up. I am currently making a “smart door” that opens every time it is motion activated. This will also include a servo motor to open the door.
This device requires nothing but the display itself and 11 wires to attach the the breadboards pins. There is no ground or voltage pins require either. There are 12 pins on the display but 11 of them are used to attach to the pins of the breadboard. 7 of the pins will control the segments that light up on the display to create the number desired. The other 4 pins will control the position of the number displayed because the display is up to 4 digits. The display should be positioned in a specific direction for it to work and the pins on the wiringPi should exactly match the pins from the Arduino example.
This device allows for 4 digit counting, similar to the LED counting we did weeks ago. This device clearly shows the numbers being displayed however and can count down or up to any number depending on the code written.
The LCD display contains 2 lines of 16 characters that can display any string of letters, number, or any ascii character. It can be used to display many data inputs such as time or temperature reading from a temperature sensor. It requires four pins: 5v in on the VCC pin, ground to the GND pin, a data connection to from an SDA pin on the pi to the SDA pin on the display, and finally a clock connection from an SCL pin on the pi to the SCL pin on the display.
The library I used was made by the user TheRaspberryPiGuy on github and is a very useful library for running the display. However, it requires the code to be written in python, but he provides many sample programs for learning.
All of the proceeding steps should be executed on your pi, not Lab46.
1. Download the library
Run:
git clone https://github.com/the-raspberry-pi-guy/lcd.git
2. Enter the newly created directory
cd lcd
3. Install the library
sudo ./install.sh
if you are given the error 'permission denied' run:
chmod a+x setup.sh
to give setup.sh permission to excecute
4. Reboot your pi
5. View or run any demos
You can view or run any of the programs labeled demo after running ls. Programs can be excecuted by running:
python FILENAME.py
The code can also be viewed by using nano.
Gyroscope (GY-521)
Description The GY-521 contains both a 3-Axis Gyroscope and a 3-Axis accelerometer allowing measurements of both independently, but all based around the same axes, thus eliminating the problems of cross-axis errors when using separate devices.
Specification Accelerometer ranges: ±2, ±4, ±8, ±16g Gyroscope ranges: ± 250, 500, 1000, 2000 °/s Voltage range: 3.3V - 5V (the module include a low drop-out voltage regulator) This simple module contains everything required to interface to the Arduino and other controllers via I2C (use the Wire Arduino library) and give motion sensing information for 3 axes - X, Y and Z.
The GY-521 can be used to measure the orientation of the device. It can sense motion including vertical and horizontal rotation. There are a lot of practical uses of gyroscope especially in aerospace. It can be used as a stability assistance device to make sure that a rocket, a spacecraft, or an aircraft maintains the correct orientation.
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:
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:
65:fso0:final tally of results (65/65) *:fso0:used grabit to obtain project by the Sunday prior to duedate [13/13] *:fso0:picture of connected circuit to project page with description [13/13] *:fso0:clean compile, no compiler messages [13/13] *:fso0:program conforms to project specifications [13/13] *:fso0:code tracked in lab46 semester repo [13/13]