Project MonitoringApp.py ViewData.py Project MonitoringApp.py ViewData.py Sensors and accessories to interface (BCM pins) RGB LED (output) (Red = 5, Green = 6, Blue = 13) Regular LED called “LED” from...


●RGB LED (output) (Red = 5, Green = 6, Blue = 13) ●Regular LED called “LED” from now on (output) (pin 14) ●Buzzer (PWM output) (pin 18) ●Ultrasonic Sensor (input) distance in cm (ECHO = 24, trig = 25) ●Potentiometer (input) (Pot): Record the position of the pot in Percentage (SPI bus for MCP3008) ○Use pins 7, 8 , 9, 10, 11 etc. based on number of bits you are using ○MCP3008 (use SPI0 with CE0) ●Push button (input) (pin 16)


Project MonitoringApp.py ViewData.py Project MonitoringApp.py ViewData.py Sensors and accessories to interface (BCM pins) RGB LED (output) (Red = 5, Green = 6, Blue = 13) Regular LED called “LED” from now on (output) (pin 14) Buzzer (PWM output) (pin 18) Ultrasonic Sensor (input) distance in cm (ECHO = 24, trig = 25) Potentiometer (input) (Pot): Record the position of the pot in Percentage (SPI bus for MCP3008) Use pins 7, 8 , 9, 10, 11 etc. based on number of bits you are using MCP3008 (use SPI0 with CE0) Push button (input) (pin 16) Note: The pins are BCM pins. Record Data from sensors at the following sampling rates The sampling rate should be followed within 10% margin. So for sonic sensor samples should show up every 90 to 110 ms and for pot, they should every 450 to 550 ms. SensorSampling rateWhat to record? Potentiometer0.5 second (10 % margin)Percentage turned (position) (2 decimal digits) Sonic (Distance) 0.1 seconds (10 % margin)cm (2 decimal digits) TimeFor every sensor sample recordedCurrent date and time (upto ms resolution) Button You can choose depending on the functionality explained further to experience non delay responseNo need to record data. Use for mode change Modes of operation Push button will be used to select three “modes of operation” (MoP). “MS: Monitor System mode”, “RDM: Record Data & Monitor mode”, “ORD: Only Record Data mode” MoPInvoked by / Stopped byIndicated byoperation MSWhen program runs first. Or when the button is pushed once (single click), invoke the mode on the button release.LED OFFExplained in next slides RDMPush button is pressed twice within 1 seconds. Like a double click. Invoke on the second release of the button.<= 1="" second="" led="" on="" records="" the="" data="" from="" the="" sensors="" stated="" in="" slides="" 3="" at="" the="" rate="" stated.="" monitor="" system="" still="" works="" during="" record="" data="" mode.="" ord="" push="" button="" pressed="" and="" held="" for="">= 2 sec. Invoke as soon as 2 seconds are passed. User may release the button after 2 seconds. ORD should still be operational.LED blinking (2 Hz)Only recording, No Monitor System Distance and Color (RGB LED) : Distance should be checked in cm every 0.1 seconds. RGB LED color (hue: R+G+B) should be related to the distance Please use human visible spectrum(https://en.wikipedia.org/wiki/Visible_spectrum) to map the LED color to the distance: Starting from Red to Violet corresponding to very close to very far (very close <= 3cm="" and="" very="" far=""> 20 cm) Beyond 20cm, the color should simply saturate to violet. Distance < 3c="" the="" led="" should="" blink="" red="" at="" 2="" hz="" hint:="" you="" should="" be="" able="" to="" find="" out="" rgb="" value="" of="" visible="" spectrum="" colors="" and="" map="" it="" linearly.)="" print="" the="" distance="" in="" cm="" and="" rgb="" value="" which="" you="" are="" generating="" on="" the="" console.="" potentiometer="" and="" sound:="" potentiometer="" %="" rotation="" should="" be="" monitored="" in="" percentage="" every="" 0.5="" seconds="" buzzer="" frequency="" (tone)="" should="" increase="" starting="" from="" 100="" hz="" to="" 2="" khz="" as="" the="" pot="" is="" rotated="" from="" position="" 0="" to="" 100%="" linearly="" &="" smoothly.="" so="" 0%="" ~="" 100="" hz="" and="" 100%~="" 2khz.="" print="" the="" potentiometer="" %="" and="" frequency="" which="" you="" are="" generating="" on="" the="" console="" with="" right="" units.="" ms="" mode:="" monitor="" system="" (led="" off)="" record="" data="" &="" monitor="" only="" record="" data="" rdm="" mode:="" record="" data="" &="" monitor="" system="" (indicated="" by="" led="" on)="" please="" record="" data="" with="" specifications="" stated="" on="" slide="" 3.="" data="" from="" the="" sonic="" and="" potentiometer="" will="" be="" recorded="" with="" the="" exact="" time="" it’s="" sampled.="" time="" should="" be="" system="" time="" (date,="" time="" to="" the="" ms)="" data="" may="" be="" stored="" in="" a="" text="" or="" csv="" format.="" file="" should="" be="" easily="" opened="" from="" the="" folder="" by="" double="" clicking="" on="" it="" and="" data="" should="" be="" manually="" verifiable="" including="" the="" time.="" (include="" a="" header)="" data="" being="" recorded="" should="" be="" indicated="" by="" messages="" “recording=""> ” and “stopped recording…” in the beginning and at the end of the recording mode session. Save the file at “/home/pi/Documents/” folder. Filename for the data recording should be unique for each recording session. (You can use time and date into the file name) System monitoring operation should work during this mode as described in the previous slide. ORD Mode: Only Record Data (LED blinking at 2 Hz) System monitor operation should stop (RGB LED off, Buzzer off) in ORD mode For recording data, everything applies exactly as in RDM mode ViewData.py: Reading records and plotting graphs ViewData.py needs to run on separate machine/laptop/computer This will have following command line arguments: Your Pi IP address (string) Whether to plot the data or not (“0”: simply transfer the file/s, “1”: transfer & plot the data) Filename: This argument can be used to decide which file should be transferred from the pi (/home/pi/Documents/) to your machine (./DataFiles) as well as during plotting which file record data should be plotted. When filename is not mentioned during transfer option all the recorded files should be transferred. But during plotting mode the filename option is necessary to decide which data to be plotted. During transfer operation if the file already exists then no need to overwrite it. Simply let user know that file already exists. (Remember that each file has unique name) Find out which OS your code is running and choose to have the local file path with correct slash sign. (./DataFiles vs .\DataFiles\) During plotting operation if the file doesn’t exist, transfer the file first and then plot it. Print appropriate messages to the console for the user to know what the system is doing. If the file doesn’t exist on the pi then print the warning message. While plotting create 2 subplots, one for potentiometer data and another for distance data. So example of how a program will run: Python ViewData.py 192.168.1.200 0 data200_0412.txt : Transfer file data200_0412.txt from pi to laptop Python ViewData.py 192.168.1.200 0 : Transfer all data files from /home/pi/Documents/ folder to your machine Python ViewData.py 192.168.1.200 1 data100_0412.txt : If the file exists, plot all sensor data from “data100_0412.txt” using subplots for each sensor data If the file doesn’t exist, transfer it from /home/pi/Documents/ and then plot the data. Plotting data contd... All plots / subplots should have appropriate x labels, y labels, xticks, yticks, legends and titles . All subplots should be scaled (xlim, ylim) appropriately to show the data legibly. Respective data should be plotted w.r.t time with right units. User should be given an option to save the plots. If the option is chosen the plots should be saved with the same name (different extension of course) as the filename from which the data is recorded. ---> Next page Hints and pointers: How to transfer data from pi to your machine Assume that your pi and the machine are on the same network. Find out the IP of the pi manually using “ifconfig”. Use this address as an argument in your viewdata.py code when you run it from command prompt. The /home/pi/Documents/ path will be used in the ViewData.py code (hardcoded) so that the code knows which folder to transfer the file from. You do not need client connection to transfer the files. You can transfer the files using ssh and scp. scp pi@: E.g. scp [email protected]:/home/pi/Documents/filename.csv .\DataFiles\ Do not hardcode the local folder path. It should be relative to your current folder (./DataFiles) Plotting: If the file format is not correct as expected because the user input a wrong file name, throw an error instead of going into infinite plotting loop. It may take a long time for the plots to show up if the file is large, have an estimate and print it for the user if possible. The data should be marked accurately as legibly. Make sure the y limits are adjusted to show all the data clearly. Program Sanity and efficiency Don’t leave the file open for the entire record operation. Better option is keep a small amount of data in buffer, open the file, write the buffer (only append), close the file. This will avoid file crashing errors. Avoid printing unnecessary information to the console to get the sampling rates as accurate as possible. If the user uses keyboard interrupt (ctrl+z, ctrl+a or ctrl+x) to stop the program, the program should not crash. It should gracefully stop the operation (LED off, buzzer off, save the file if applicable) and print an exit message. Manage exceptions to minimize common user errors such as wrong arguments, wrong format, wrong file format, file doesn’t exist, no network connection.
Jul 21, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here