├── Foundation Crash Course ├── Crash Course on Python │ ├── Python Fundamentals - A Crash Course for Beginners.ipynb │ ├── Self-paced Exercise Solution.ipynb │ └── objective.jpg └── Crash Course on Data Analytics │ ├── Data Analysis Using NumPy Library.ipynb │ ├── Data Manipulation Using Pandas Library.ipynb │ ├── Data Visualization Using Matplotlib Library.ipynb │ ├── airlines.csv │ └── nba.csv ├── Module-1 ├── Case-Study │ ├── Heart diseas.ipynb │ └── heart.csv ├── Unit-1 │ └── Lab 1 - Classroom Exercise.pdf ├── Unit-2 │ ├── 2.1 │ │ ├── Boston.csv │ │ ├── Lab 1 - Classroom Exercise_Linear Rgression .ipynb │ │ └── Lab 2 - Classroom Exercise-Lasso & Ridge Regression.ipynb │ ├── 2.2 │ │ └── Lab 1 - Classroom Exercise_Logistic Regression.ipynb │ ├── 2.3 │ │ ├── Lab-1 Classroom Excercise_KNN_Demo.ipynb │ │ └── teleCust1000t.csv │ ├── 2.4 │ │ └── Lab-1 Classroom Excercise_Decision_Tree_Demo.ipynb │ ├── 2.5 │ │ └── Lab 1 - Classroom Exercise_SVM_Demo.ipynb │ └── 2.6 │ │ ├── Lab 1 - Classroom Exercise_Random_Forest_Demo.ipynb │ │ ├── Lab 2 - Classroom Exercise_XGBoost_Demo.ipynb │ │ ├── Lab 3 - Classroom Exercise_Comparing_ADABoost-v-GBoost-v-XGBoost.ipynb │ │ ├── test.csv │ │ ├── titanic.csv │ │ └── train.csv └── Unit-3 │ ├── 3.2 │ ├── Lab 1 - Classroom Exercise_KMeans_Clustering.ipynb │ ├── Lab 1 - Self Paced Exercise_KMeans_Clustering.ipynb │ ├── Lab 1 - Self Paced Solution_KMeans_Clustering.ipynb │ └── Mall_Customers.csv │ ├── 3.3 │ ├── Lab 1 - Classroom Exercise_Hierarchical Clustering.ipynb │ └── Mall_Customers.csv │ ├── 3.4 │ └── Lab 1 - Classroom Exercise_DBScan_Notebook.ipynb │ └── 3.5 │ └── Lab 1 - Classroom Exercise_PCA.ipynb ├── Module-2 ├── Unit-2 │ ├── Practical-1Getting Started with Raspberry PI (Light Version Raspbian OS).pdf │ ├── Practical-2 Getting Started with Arduino Windows-Ubuntu (Arduino IDE Plug InPlay).pdf │ ├── Test_Arduino.c │ ├── Test_DFRobot.py │ ├── Test_GrovePi.py │ ├── Test_Node_MCU.c │ ├── practical-3 Getting Started with Node MCU ESP8266.pdf │ ├── practical-4Getting Started with GrovePI & Raspberry PI (Installation with Led blink).pdf │ └── practical-5 Getting Started with DFRobot Hat & Raspberry PI (Installation with Led blink)_.pdf ├── Unit-3 │ ├── DFRobot_IoT_Codes │ │ ├── 10_DFR_Hearbeat_Sensor.py │ │ ├── 11_DFR_conductivity_sensor.py │ │ ├── 12_DFR_Soil_Moisture_Sensor.py │ │ ├── 13_DFR_ultrasonic_distance_sensor.py │ │ ├── 14_DFR_touch_sensor.py │ │ ├── 15_DFR_ball_inclination_sensor.py │ │ ├── 16_DFR_magnetic_sensor.py │ │ ├── 17_DFR_minivibration_module.py │ │ ├── 18_DFR_I2C_color_sensor.py │ │ ├── 19_DFR_I2C_LCD_Interface.py │ │ ├── 1_led_control.py │ │ ├── 20_DFR_RGB_led.py │ │ ├── 21_DFR_motion_sensor.py │ │ ├── 2_led_button.py │ │ ├── 3_DFR_temperature_sensor.py │ │ ├── 4_DFR_rotation_angle_sensor.py │ │ ├── 5_DFR_DC_fan_control.py │ │ ├── 6_DFR_Joystick.py │ │ ├── 7_DFR_light_sensor.py │ │ ├── 8_DFR_digital_vibration_sensor.py │ │ ├── 9_DFR_Analog_Sound_Sensor.py │ │ ├── DFRobot_RaspberryPi_Expansion_Board.py │ │ ├── dfadc.py │ │ └── lcddf.py │ ├── GrovePI_Codes │ │ ├── 10_Analog_read_potentiometer.py │ │ ├── 11_Analog_Light_Sensor.py │ │ ├── 12_LCD_Interfacing.py │ │ ├── 13_LED_PWM_Control.py │ │ ├── 14_External_controlled_LED_Glow.py │ │ ├── 15_DC_Motor_Control.py │ │ ├── 16_Ultrasonic_GrovePI.py │ │ ├── 1_LED_Interfacing.py │ │ ├── 2_Buzzer_Control.py │ │ ├── 3_Vibration_Detection.py │ │ ├── 4_Heart_beat_sensor.py │ │ ├── 4x4_Matrix_with_library.py │ │ ├── 4x4_matrix_Keyboard.py │ │ ├── 5_Conductivity_Sensor.py │ │ ├── 6_Touch_Sensor.py │ │ ├── 7_Tilt_Sensor.py │ │ ├── 8_LM35_Temp_Sensor.py │ │ ├── 9_DHT_Sensor.py │ │ ├── Autotweet_GrovePI.py │ │ ├── DFRobot_RaspberryPi_Expansion_Board.py │ │ ├── DHT_22_DFR.py │ │ ├── Firebase_data_logging.py │ │ ├── MQTT_PWM_Control.py │ │ ├── MQTT_analog_data.py │ │ ├── MQTT_led_Control.py │ │ ├── New Sensors │ │ │ ├── 4x4_Matrix_with_library.py │ │ │ ├── 4x4_matrix_Keyboard.py │ │ │ ├── DFRobot_RaspberryPi_Expansion_Board.py │ │ │ ├── DHT_22_DFR.py │ │ │ ├── Motion_Detection_PIR.py │ │ │ ├── Rain_water_sensor.py │ │ │ ├── Resistive_Soil_Moisture_Sensor.py │ │ │ ├── Servo_Motor_Interfacing.py │ │ │ ├── Stepper_motor_interface.py │ │ │ ├── dfadc.py │ │ │ ├── lcddf.py │ │ │ ├── mq135_interface.py │ │ │ ├── mq135_usage2.py │ │ │ └── servo_GPIO.py │ │ ├── Sound_sensor_interface.py │ │ ├── Telegram_grovepi.py │ │ ├── dfadc.py │ │ ├── lcddf.py │ │ ├── mq135_interface.py │ │ ├── mq135_usage2.py │ │ └── thingspeak_grovepi.py │ ├── Lab 1 - Classroom Exercise_Digital_Sensor_Interfacing.pdf │ ├── Lab 2 - Classroom Exercise_Analog_Sensor_Interfacing.pdf │ ├── Lab 3 - Classroom Exercise_PWM_Interfacing.pdf │ └── Lab 4 - Classroom Exercise_I2C_Interfacing.pdf ├── Unit-4 │ ├── DFRobot_Practicals │ │ ├── 22_Thingspeak_cloud.py │ │ ├── DFRobot_RaspberryPi_Expansion_Board.py │ │ ├── DFRobot_firebase.py │ │ ├── RPiFireBaseDHT_working.py │ │ ├── autotweetDFRobot.py │ │ ├── dfadc.py │ │ ├── lcddf.py │ │ ├── mqtt_DFRObot.py │ │ ├── mqtt_DFRObot_PWM.py │ │ ├── mqtt_DFRObot_analog.py │ │ └── telegram_GPIO.py │ ├── GrovePi_Practicals │ │ ├── Autotweet_GrovePI.py │ │ ├── Firebase_data_logging.py │ │ ├── MQTT_PWM_Control.py │ │ ├── MQTT_PWM_Control_Sliding.py │ │ ├── MQTT_analog_data.py │ │ ├── MQTT_led_Control.py │ │ ├── Telegram_grovepi.py │ │ └── thingspeak_grovepi.py │ ├── Lab 1 - Classroom Exercise_Deployment of HTTPS protocol on IoT Devices.pdf │ ├── Lab 2 - Classroom Exercise_Deployment of MQTT protocol on IoT Devices.pdf │ ├── Lab 3 - Classroom Exercise_Deployment of Firebase Datalogging from IoT Devices.pdf │ ├── Lab 4 - Classroom Exercise_Post Tweets on Twitter using IoT Devices.pdf │ └── Lab 5 - Classroom Exercise_Remote Controlling of IoT Devices through Telegram.pdf └── Unit-5 │ ├── Lab 1 - Classroom Exercise_IOT_Cloud.pdf │ ├── Lab 2 - Classroom Exercise_RPi_to_Cloud.pdf │ ├── Lab 3 - Classroom Exercise_Collecting_sensor_data.pdf │ ├── Lab 4 - Classroom Exercise_Sensor_ML.ipynb │ └── mobile_data.csv ├── Module-3 ├── Unit-1 │ ├── LAB 1 Classroom Exercise(CNN).ipynb │ └── pima-indians-diabetes.csv ├── Unit-2 │ ├── Lab 1 Classroom Exercise (OpenCV).ipynb │ ├── Lab 2 Classroom Exercise Age-Gender.ipynb │ ├── Lab 3 Classroom Exercise Hand gesture.ipynb │ ├── Lab 4 Classroom Exercise Drowsiness detection.ipynb │ ├── Lab 5 Classroom Exercise Cat-Dog Classification using CNN.ipynb │ ├── Lab 6 Classroom Exercise Transfer_Learning_VGG_16.ipynb │ ├── age_deploy.prototxt │ ├── gender_deploy.prototxt │ ├── opencv_face_detector.pbtxt │ └── opencv_face_detector_uint8.pb ├── Unit-3 │ ├── face-detection-retail-0004.bin │ ├── face-detection-retail-0004.xml │ └── face_detection.py └── Unit-4 │ ├── .ipynb_checkpoints │ ├── Lab 1 classroom exercise Gpt using Python-checkpoint.ipynb │ └── Lab 2 Classroom Exercise - Pandas AI-checkpoint.ipynb │ ├── Lab 1 classroom exercise Gpt using Python.ipynb │ ├── Lab 2 Classroom Exercise - Pandas AI.ipynb │ ├── Lab 3 Classroom Exercise Hugging Face Model.ipynb │ ├── Lab 4 Classroom Exercise GAN.ipynb │ └── Lab 5 Classroom Exercise VAE.ipynb ├── Module-4 ├── Unit-2 │ ├── LAB-1_Classroom_Excercise_ABAP BTP Free Trial Initilization.pdf │ └── LAB-2_Classroom_Excercise_Prepare_Eclipse_for_ABAP.pdf ├── Unit-3 │ ├── Lab_1_Classroom_Excercise_Create the ABAP Package.pdf │ ├── Lab_2_Classroom_Excercise_Create The Class.pdf │ ├── Lab_3_Classroom_Excercise_WAP for Hello world.pdf │ ├── Lab_4_Classroom_Excercise_Perform verious Data Type Operation.pdf │ ├── Lab_5_Classroom_Excercise_ABAP for decision making.pdf │ ├── Lab_6_Classroom_Excercise_Loops in ABAP.pdf │ ├── Lab_7_Classroom_Excercise_Creating Database Table and Data insergen.pdf │ └── Lab_8_Classroom_Excercise_Perform query operations on table created in Lab 7.pdf └── Unit-4 │ ├── Lab-1_Classroom_Excercise_SAP Build Code Setup.pdf │ └── Lab-2_Classroom_Excercise_SAP Build Code With Joule Essentials.pdf ├── Module-5 └── Design_Engineering_Case_Study.pdf └── README.md /Foundation Crash Course/Crash Course on Python/objective.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Foundation Crash Course/Crash Course on Python/objective.jpg -------------------------------------------------------------------------------- /Module-1/Unit-1/Lab 1 - Classroom Exercise.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-1/Unit-1/Lab 1 - Classroom Exercise.pdf -------------------------------------------------------------------------------- /Module-1/Unit-3/3.2/Lab 1 - Self Paced Exercise_KMeans_Clustering.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "9d9a1708", 6 | "metadata": {}, 7 | "source": [ 8 | "EDUNET FOUNDATION-Classroom Exercise Notebook" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "473f1af5", 14 | "metadata": {}, 15 | "source": [ 16 | "# Lab 1 - Self Paced Exercise : Analyzing Iris Dataset " 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "9a199b71", 22 | "metadata": {}, 23 | "source": [ 24 | "# Dataset:\n", 25 | "Inbuild iris dataset " 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "id": "09584abe", 31 | "metadata": {}, 32 | "source": [ 33 | "# Problem Statement \n", 34 | "\n", 35 | "- The Iris dataset contains measurements of four features—sepal length, sepal width, petal length, and petal width—for three different species of iris flowers: Iris Setosa, Iris Versicolor, and Iris Virginica. \n", 36 | "- The goal of this analysis is to use the K-Means clustering algorithm to segment the iris flowers into clusters based on these four features. The assumption is that similar measurements among flowers might indicate similarities in species, though this is an unsupervised analysis and the algorithm will work without using species labels." 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "id": "2654f03f", 42 | "metadata": {}, 43 | "source": [ 44 | "# Objective:\n", 45 | "\n", 46 | "1. Load and preprocess the Iris dataset, which includes measurements of sepal and petal dimensions for a number of iris flowers.\n", 47 | "2. Normalize the feature values to ensure that each feature contributes equally to the clustering process.\n", 48 | "3. Determine the optimal number of clusters (K) using the Elbow Method.\n", 49 | "4. Apply the K-Means clustering algorithm to segment the iris flowers into K clusters based on their feature values.\n", 50 | "5. Visualize the resulting clusters using scatter plots of different feature pairs.\n", 51 | "6. Analyze and interpret the clusters to understand if they align with the actual species labels provided in the dataset.\n", 52 | "7. Discuss the insights gained from the clustering analysis and assess the effectiveness of K-Means for segmenting the iris flowers." 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "id": "45004b1e", 58 | "metadata": {}, 59 | "source": [ 60 | "# Steps:" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "id": "fc11df86", 66 | "metadata": {}, 67 | "source": [ 68 | "## Import necessary libraries" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "id": "460c8a4c", 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "id": "8a8f2d1b", 82 | "metadata": {}, 83 | "source": [ 84 | "## Load the dataset" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "id": "1ac03314", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "id": "2010be7a", 98 | "metadata": {}, 99 | "source": [ 100 | "## Data Preprocessing\n" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "id": "50e3b21d", 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "id": "df1bae61", 114 | "metadata": {}, 115 | "source": [ 116 | "## Choosing the Number of Clusters (K)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "id": "5f57f991", 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "id": "1c83c431", 130 | "metadata": {}, 131 | "source": [ 132 | "## Applying K-Means Clustering" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": null, 138 | "id": "e530c276", 139 | "metadata": {}, 140 | "outputs": [], 141 | "source": [] 142 | }, 143 | { 144 | "cell_type": "markdown", 145 | "id": "87ec37b3", 146 | "metadata": {}, 147 | "source": [ 148 | "## Visualize Clusters" 149 | ] 150 | }, 151 | { 152 | "cell_type": "code", 153 | "execution_count": null, 154 | "id": "6d2c80a7", 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "id": "38aca81f", 162 | "metadata": {}, 163 | "source": [ 164 | "## Interpretation and Analysis" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "id": "226eb8f0", 171 | "metadata": {}, 172 | "outputs": [], 173 | "source": [] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "id": "3ede9340", 178 | "metadata": {}, 179 | "source": [ 180 | "## Conclusion" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "id": "93d3c3be", 187 | "metadata": {}, 188 | "outputs": [], 189 | "source": [] 190 | } 191 | ], 192 | "metadata": { 193 | "kernelspec": { 194 | "display_name": "Python 3 (ipykernel)", 195 | "language": "python", 196 | "name": "python3" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": { 200 | "name": "ipython", 201 | "version": 3 202 | }, 203 | "file_extension": ".py", 204 | "mimetype": "text/x-python", 205 | "name": "python", 206 | "nbconvert_exporter": "python", 207 | "pygments_lexer": "ipython3", 208 | "version": "3.9.13" 209 | }, 210 | "toc": { 211 | "base_numbering": 1, 212 | "nav_menu": {}, 213 | "number_sections": true, 214 | "sideBar": true, 215 | "skip_h1_title": false, 216 | "title_cell": "Table of Contents", 217 | "title_sidebar": "Contents", 218 | "toc_cell": false, 219 | "toc_position": { 220 | "height": "calc(100% - 180px)", 221 | "left": "10px", 222 | "top": "150px", 223 | "width": "204.8px" 224 | }, 225 | "toc_section_display": true, 226 | "toc_window_display": true 227 | } 228 | }, 229 | "nbformat": 4, 230 | "nbformat_minor": 5 231 | } 232 | -------------------------------------------------------------------------------- /Module-1/Unit-3/3.2/Mall_Customers.csv: -------------------------------------------------------------------------------- 1 | CustomerID,Gender,Age,Annual Income (k$),Spending Score (1-100) 2 | 1,Male,19,15,39 3 | 2,Male,21,15,81 4 | 3,Female,20,16,6 5 | 4,Female,23,16,77 6 | 5,Female,31,17,40 7 | 6,Female,22,17,76 8 | 7,Female,35,18,6 9 | 8,Female,23,18,94 10 | 9,Male,64,19,3 11 | 10,Female,30,19,72 12 | 11,Male,67,19,14 13 | 12,Female,35,19,99 14 | 13,Female,58,20,15 15 | 14,Female,24,20,77 16 | 15,Male,37,20,13 17 | 16,Male,22,20,79 18 | 17,Female,35,21,35 19 | 18,Male,20,21,66 20 | 19,Male,52,23,29 21 | 20,Female,35,23,98 22 | 21,Male,35,24,35 23 | 22,Male,25,24,73 24 | 23,Female,46,25,5 25 | 24,Male,31,25,73 26 | 25,Female,54,28,14 27 | 26,Male,29,28,82 28 | 27,Female,45,28,32 29 | 28,Male,35,28,61 30 | 29,Female,40,29,31 31 | 30,Female,23,29,87 32 | 31,Male,60,30,4 33 | 32,Female,21,30,73 34 | 33,Male,53,33,4 35 | 34,Male,18,33,92 36 | 35,Female,49,33,14 37 | 36,Female,21,33,81 38 | 37,Female,42,34,17 39 | 38,Female,30,34,73 40 | 39,Female,36,37,26 41 | 40,Female,20,37,75 42 | 41,Female,65,38,35 43 | 42,Male,24,38,92 44 | 43,Male,48,39,36 45 | 44,Female,31,39,61 46 | 45,Female,49,39,28 47 | 46,Female,24,39,65 48 | 47,Female,50,40,55 49 | 48,Female,27,40,47 50 | 49,Female,29,40,42 51 | 50,Female,31,40,42 52 | 51,Female,49,42,52 53 | 52,Male,33,42,60 54 | 53,Female,31,43,54 55 | 54,Male,59,43,60 56 | 55,Female,50,43,45 57 | 56,Male,47,43,41 58 | 57,Female,51,44,50 59 | 58,Male,69,44,46 60 | 59,Female,27,46,51 61 | 60,Male,53,46,46 62 | 61,Male,70,46,56 63 | 62,Male,19,46,55 64 | 63,Female,67,47,52 65 | 64,Female,54,47,59 66 | 65,Male,63,48,51 67 | 66,Male,18,48,59 68 | 67,Female,43,48,50 69 | 68,Female,68,48,48 70 | 69,Male,19,48,59 71 | 70,Female,32,48,47 72 | 71,Male,70,49,55 73 | 72,Female,47,49,42 74 | 73,Female,60,50,49 75 | 74,Female,60,50,56 76 | 75,Male,59,54,47 77 | 76,Male,26,54,54 78 | 77,Female,45,54,53 79 | 78,Male,40,54,48 80 | 79,Female,23,54,52 81 | 80,Female,49,54,42 82 | 81,Male,57,54,51 83 | 82,Male,38,54,55 84 | 83,Male,67,54,41 85 | 84,Female,46,54,44 86 | 85,Female,21,54,57 87 | 86,Male,48,54,46 88 | 87,Female,55,57,58 89 | 88,Female,22,57,55 90 | 89,Female,34,58,60 91 | 90,Female,50,58,46 92 | 91,Female,68,59,55 93 | 92,Male,18,59,41 94 | 93,Male,48,60,49 95 | 94,Female,40,60,40 96 | 95,Female,32,60,42 97 | 96,Male,24,60,52 98 | 97,Female,47,60,47 99 | 98,Female,27,60,50 100 | 99,Male,48,61,42 101 | 100,Male,20,61,49 102 | 101,Female,23,62,41 103 | 102,Female,49,62,48 104 | 103,Male,67,62,59 105 | 104,Male,26,62,55 106 | 105,Male,49,62,56 107 | 106,Female,21,62,42 108 | 107,Female,66,63,50 109 | 108,Male,54,63,46 110 | 109,Male,68,63,43 111 | 110,Male,66,63,48 112 | 111,Male,65,63,52 113 | 112,Female,19,63,54 114 | 113,Female,38,64,42 115 | 114,Male,19,64,46 116 | 115,Female,18,65,48 117 | 116,Female,19,65,50 118 | 117,Female,63,65,43 119 | 118,Female,49,65,59 120 | 119,Female,51,67,43 121 | 120,Female,50,67,57 122 | 121,Male,27,67,56 123 | 122,Female,38,67,40 124 | 123,Female,40,69,58 125 | 124,Male,39,69,91 126 | 125,Female,23,70,29 127 | 126,Female,31,70,77 128 | 127,Male,43,71,35 129 | 128,Male,40,71,95 130 | 129,Male,59,71,11 131 | 130,Male,38,71,75 132 | 131,Male,47,71,9 133 | 132,Male,39,71,75 134 | 133,Female,25,72,34 135 | 134,Female,31,72,71 136 | 135,Male,20,73,5 137 | 136,Female,29,73,88 138 | 137,Female,44,73,7 139 | 138,Male,32,73,73 140 | 139,Male,19,74,10 141 | 140,Female,35,74,72 142 | 141,Female,57,75,5 143 | 142,Male,32,75,93 144 | 143,Female,28,76,40 145 | 144,Female,32,76,87 146 | 145,Male,25,77,12 147 | 146,Male,28,77,97 148 | 147,Male,48,77,36 149 | 148,Female,32,77,74 150 | 149,Female,34,78,22 151 | 150,Male,34,78,90 152 | 151,Male,43,78,17 153 | 152,Male,39,78,88 154 | 153,Female,44,78,20 155 | 154,Female,38,78,76 156 | 155,Female,47,78,16 157 | 156,Female,27,78,89 158 | 157,Male,37,78,1 159 | 158,Female,30,78,78 160 | 159,Male,34,78,1 161 | 160,Female,30,78,73 162 | 161,Female,56,79,35 163 | 162,Female,29,79,83 164 | 163,Male,19,81,5 165 | 164,Female,31,81,93 166 | 165,Male,50,85,26 167 | 166,Female,36,85,75 168 | 167,Male,42,86,20 169 | 168,Female,33,86,95 170 | 169,Female,36,87,27 171 | 170,Male,32,87,63 172 | 171,Male,40,87,13 173 | 172,Male,28,87,75 174 | 173,Male,36,87,10 175 | 174,Male,36,87,92 176 | 175,Female,52,88,13 177 | 176,Female,30,88,86 178 | 177,Male,58,88,15 179 | 178,Male,27,88,69 180 | 179,Male,59,93,14 181 | 180,Male,35,93,90 182 | 181,Female,37,97,32 183 | 182,Female,32,97,86 184 | 183,Male,46,98,15 185 | 184,Female,29,98,88 186 | 185,Female,41,99,39 187 | 186,Male,30,99,97 188 | 187,Female,54,101,24 189 | 188,Male,28,101,68 190 | 189,Female,41,103,17 191 | 190,Female,36,103,85 192 | 191,Female,34,103,23 193 | 192,Female,32,103,69 194 | 193,Male,33,113,8 195 | 194,Female,38,113,91 196 | 195,Female,47,120,16 197 | 196,Female,35,120,79 198 | 197,Female,45,126,28 199 | 198,Male,32,126,74 200 | 199,Male,32,137,18 201 | 200,Male,30,137,83 202 | -------------------------------------------------------------------------------- /Module-1/Unit-3/3.3/Mall_Customers.csv: -------------------------------------------------------------------------------- 1 | CustomerID,Gender,Age,Annual Income (k$),Spending Score (1-100) 2 | 1,Male,19,15,39 3 | 2,Male,21,15,81 4 | 3,Female,20,16,6 5 | 4,Female,23,16,77 6 | 5,Female,31,17,40 7 | 6,Female,22,17,76 8 | 7,Female,35,18,6 9 | 8,Female,23,18,94 10 | 9,Male,64,19,3 11 | 10,Female,30,19,72 12 | 11,Male,67,19,14 13 | 12,Female,35,19,99 14 | 13,Female,58,20,15 15 | 14,Female,24,20,77 16 | 15,Male,37,20,13 17 | 16,Male,22,20,79 18 | 17,Female,35,21,35 19 | 18,Male,20,21,66 20 | 19,Male,52,23,29 21 | 20,Female,35,23,98 22 | 21,Male,35,24,35 23 | 22,Male,25,24,73 24 | 23,Female,46,25,5 25 | 24,Male,31,25,73 26 | 25,Female,54,28,14 27 | 26,Male,29,28,82 28 | 27,Female,45,28,32 29 | 28,Male,35,28,61 30 | 29,Female,40,29,31 31 | 30,Female,23,29,87 32 | 31,Male,60,30,4 33 | 32,Female,21,30,73 34 | 33,Male,53,33,4 35 | 34,Male,18,33,92 36 | 35,Female,49,33,14 37 | 36,Female,21,33,81 38 | 37,Female,42,34,17 39 | 38,Female,30,34,73 40 | 39,Female,36,37,26 41 | 40,Female,20,37,75 42 | 41,Female,65,38,35 43 | 42,Male,24,38,92 44 | 43,Male,48,39,36 45 | 44,Female,31,39,61 46 | 45,Female,49,39,28 47 | 46,Female,24,39,65 48 | 47,Female,50,40,55 49 | 48,Female,27,40,47 50 | 49,Female,29,40,42 51 | 50,Female,31,40,42 52 | 51,Female,49,42,52 53 | 52,Male,33,42,60 54 | 53,Female,31,43,54 55 | 54,Male,59,43,60 56 | 55,Female,50,43,45 57 | 56,Male,47,43,41 58 | 57,Female,51,44,50 59 | 58,Male,69,44,46 60 | 59,Female,27,46,51 61 | 60,Male,53,46,46 62 | 61,Male,70,46,56 63 | 62,Male,19,46,55 64 | 63,Female,67,47,52 65 | 64,Female,54,47,59 66 | 65,Male,63,48,51 67 | 66,Male,18,48,59 68 | 67,Female,43,48,50 69 | 68,Female,68,48,48 70 | 69,Male,19,48,59 71 | 70,Female,32,48,47 72 | 71,Male,70,49,55 73 | 72,Female,47,49,42 74 | 73,Female,60,50,49 75 | 74,Female,60,50,56 76 | 75,Male,59,54,47 77 | 76,Male,26,54,54 78 | 77,Female,45,54,53 79 | 78,Male,40,54,48 80 | 79,Female,23,54,52 81 | 80,Female,49,54,42 82 | 81,Male,57,54,51 83 | 82,Male,38,54,55 84 | 83,Male,67,54,41 85 | 84,Female,46,54,44 86 | 85,Female,21,54,57 87 | 86,Male,48,54,46 88 | 87,Female,55,57,58 89 | 88,Female,22,57,55 90 | 89,Female,34,58,60 91 | 90,Female,50,58,46 92 | 91,Female,68,59,55 93 | 92,Male,18,59,41 94 | 93,Male,48,60,49 95 | 94,Female,40,60,40 96 | 95,Female,32,60,42 97 | 96,Male,24,60,52 98 | 97,Female,47,60,47 99 | 98,Female,27,60,50 100 | 99,Male,48,61,42 101 | 100,Male,20,61,49 102 | 101,Female,23,62,41 103 | 102,Female,49,62,48 104 | 103,Male,67,62,59 105 | 104,Male,26,62,55 106 | 105,Male,49,62,56 107 | 106,Female,21,62,42 108 | 107,Female,66,63,50 109 | 108,Male,54,63,46 110 | 109,Male,68,63,43 111 | 110,Male,66,63,48 112 | 111,Male,65,63,52 113 | 112,Female,19,63,54 114 | 113,Female,38,64,42 115 | 114,Male,19,64,46 116 | 115,Female,18,65,48 117 | 116,Female,19,65,50 118 | 117,Female,63,65,43 119 | 118,Female,49,65,59 120 | 119,Female,51,67,43 121 | 120,Female,50,67,57 122 | 121,Male,27,67,56 123 | 122,Female,38,67,40 124 | 123,Female,40,69,58 125 | 124,Male,39,69,91 126 | 125,Female,23,70,29 127 | 126,Female,31,70,77 128 | 127,Male,43,71,35 129 | 128,Male,40,71,95 130 | 129,Male,59,71,11 131 | 130,Male,38,71,75 132 | 131,Male,47,71,9 133 | 132,Male,39,71,75 134 | 133,Female,25,72,34 135 | 134,Female,31,72,71 136 | 135,Male,20,73,5 137 | 136,Female,29,73,88 138 | 137,Female,44,73,7 139 | 138,Male,32,73,73 140 | 139,Male,19,74,10 141 | 140,Female,35,74,72 142 | 141,Female,57,75,5 143 | 142,Male,32,75,93 144 | 143,Female,28,76,40 145 | 144,Female,32,76,87 146 | 145,Male,25,77,12 147 | 146,Male,28,77,97 148 | 147,Male,48,77,36 149 | 148,Female,32,77,74 150 | 149,Female,34,78,22 151 | 150,Male,34,78,90 152 | 151,Male,43,78,17 153 | 152,Male,39,78,88 154 | 153,Female,44,78,20 155 | 154,Female,38,78,76 156 | 155,Female,47,78,16 157 | 156,Female,27,78,89 158 | 157,Male,37,78,1 159 | 158,Female,30,78,78 160 | 159,Male,34,78,1 161 | 160,Female,30,78,73 162 | 161,Female,56,79,35 163 | 162,Female,29,79,83 164 | 163,Male,19,81,5 165 | 164,Female,31,81,93 166 | 165,Male,50,85,26 167 | 166,Female,36,85,75 168 | 167,Male,42,86,20 169 | 168,Female,33,86,95 170 | 169,Female,36,87,27 171 | 170,Male,32,87,63 172 | 171,Male,40,87,13 173 | 172,Male,28,87,75 174 | 173,Male,36,87,10 175 | 174,Male,36,87,92 176 | 175,Female,52,88,13 177 | 176,Female,30,88,86 178 | 177,Male,58,88,15 179 | 178,Male,27,88,69 180 | 179,Male,59,93,14 181 | 180,Male,35,93,90 182 | 181,Female,37,97,32 183 | 182,Female,32,97,86 184 | 183,Male,46,98,15 185 | 184,Female,29,98,88 186 | 185,Female,41,99,39 187 | 186,Male,30,99,97 188 | 187,Female,54,101,24 189 | 188,Male,28,101,68 190 | 189,Female,41,103,17 191 | 190,Female,36,103,85 192 | 191,Female,34,103,23 193 | 192,Female,32,103,69 194 | 193,Male,33,113,8 195 | 194,Female,38,113,91 196 | 195,Female,47,120,16 197 | 196,Female,35,120,79 198 | 197,Female,45,126,28 199 | 198,Male,32,126,74 200 | 199,Male,32,137,18 201 | 200,Male,30,137,83 202 | -------------------------------------------------------------------------------- /Module-2/Unit-2/Practical-1Getting Started with Raspberry PI (Light Version Raspbian OS).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-2/Practical-1Getting Started with Raspberry PI (Light Version Raspbian OS).pdf -------------------------------------------------------------------------------- /Module-2/Unit-2/Practical-2 Getting Started with Arduino Windows-Ubuntu (Arduino IDE Plug InPlay).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-2/Practical-2 Getting Started with Arduino Windows-Ubuntu (Arduino IDE Plug InPlay).pdf -------------------------------------------------------------------------------- /Module-2/Unit-2/Test_Arduino.c: -------------------------------------------------------------------------------- 1 | void setup() {​ 2 | 3 | // Start the serial communication with a baud rate of 9600​ 4 | 5 | Serial.begin(9600);​ 6 | 7 | 8 | // Give some time for the Serial Monitor to start​ 9 | 10 | delay(1000);​ 11 | 12 | // Print a message to the Serial Monitor​ 13 | 14 | Serial.println("Arduino is connected and working properly.");​ 15 | 16 | }​ 17 | 18 | void loop() {​ 19 | 20 | // Print a message every second​ 21 | 22 | Serial.println("Arduino is still connected.");​ 23 | 24 | delay(1000);​ 25 | 26 | }​ -------------------------------------------------------------------------------- /Module-2/Unit-2/Test_GrovePi.py: -------------------------------------------------------------------------------- 1 | import time​ 2 | 3 | from grovepi import *​ 4 | 5 | digital_ports = [2, 3, 4, 5, 6, 7, 8]​ 6 | 7 | def check_digital_ports():​ 8 | 9 | for port in digital_ports:​ 10 | 11 | try:​ 12 | 13 | pinMode(port, "OUTPUT")​ 14 | 15 | digitalWrite(port, 1)​ 16 | 17 | time.sleep(1)​ 18 | 19 | state = digitalRead(port)​ 20 | 21 | print(f"Digital Port {port} - HIGH state: {state}")​ 22 | 23 | digitalWrite(port, 0)​ 24 | 25 | time.sleep(1)​ 26 | 27 | state = digitalRead(port)​ 28 | 29 | print(f"Digital Port {port} - LOW state: {state}")​ 30 | 31 | except IOError:​ 32 | 33 | print(f"Error reading/writing Digital Port {port}") -------------------------------------------------------------------------------- /Module-2/Unit-2/Test_Node_MCU.c: -------------------------------------------------------------------------------- 1 | void setup() { ​ 2 | 3 | // initialize inbuilt LED pin as an output.​ 4 | 5 | pinMode(LED_BUILTIN, OUTPUT);​ 6 | 7 | }​ 8 | 9 | // loop function runs over and over again forever​ 10 | 11 | void loop() {​ 12 | 13 | digitalWrite(LED_BUILTIN, HIGH); // turn the LED on by making the pin 13 HIGH​ 14 | 15 | delay(500); // wait for a 0.5 second​ 16 | 17 | digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the pin 13 LOW​ 18 | 19 | delay(500); // wait for a 0.5 second​ 20 | 21 | } -------------------------------------------------------------------------------- /Module-2/Unit-2/practical-3 Getting Started with Node MCU ESP8266.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-2/practical-3 Getting Started with Node MCU ESP8266.pdf -------------------------------------------------------------------------------- /Module-2/Unit-2/practical-4Getting Started with GrovePI & Raspberry PI (Installation with Led blink).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-2/practical-4Getting Started with GrovePI & Raspberry PI (Installation with Led blink).pdf -------------------------------------------------------------------------------- /Module-2/Unit-2/practical-5 Getting Started with DFRobot Hat & Raspberry PI (Installation with Led blink)_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-2/practical-5 Getting Started with DFRobot Hat & Raspberry PI (Installation with Led blink)_.pdf -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/10_DFR_Hearbeat_Sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | LED=12 6 | Heart_Rate=8 7 | 8 | atexit.register(GPIO.cleanup) 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(LED,GPIO.OUT) 11 | GPIO.setup(Heart_Rate,GPIO.IN) 12 | 13 | while True: 14 | if GPIO.input(Heart_Rate): 15 | GPIO.output(LED,GPIO.HIGH) 16 | else : 17 | GPIO.output(LED,GPIO.LOW) 18 | time.sleep(0.1) 19 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/11_DFR_conductivity_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO # Import the python module provided by the Raspberry Pi 2 | import time # Import time package to control flicker 3 | 4 | LED=12 # Define the pin number to which the LED is connected 5 | sensor = 8 # Define the PIN to which the touch sensor is connected 6 | 7 | GPIO.setmode(GPIO.BCM) #Set GPIO mode, BCM mode is common to all RPI 8 | GPIO.setup(sensor,GPIO.IN) # Set GPIO12 to output mode 9 | GPIO.setup(LED,GPIO.OUT) # Set GPIO8 to input mode 10 | GPIO.output(LED,GPIO.HIGH) #Define LED original value 11 | 12 | while True: #Execute the following commands in an infinite loop 13 | key = GPIO.input(sensor) 14 | if (key ): # Judge whether the button is pressed 15 | GPIO.output(LED,GPIO.LOW) #Button pressed, start the micro vibrator 16 | else : # If GPIO8 is low (that is, the button is released), execute the following statement 17 | GPIO.output(LED,GPIO.HIGH) # Not start the micro vibrator 18 | time.sleep(0.01) #Delay one second, here is to control the frequency 19 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/12_DFR_Soil_Moisture_Sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 4 | 5 | 6 | while board.begin() != board.STA_OK: # Board begin and check board status 7 | print_board_status() 8 | print("board begin faild") 9 | time.sleep(2) 10 | print("board begin success") 11 | 12 | board.set_adc_enable() 13 | 14 | while True: 15 | humidity = board.get_adc_value(board.A0) # A0 channels read 16 | humid = (humidity/4096)* 100 17 | sf=f"Humidity = {humid} %" 18 | print(sf) 19 | print("") 20 | 21 | time.sleep(2) 22 | 23 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/13_DFR_ultrasonic_distance_sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() 4 | 5 | while board.begin() != board.STA_OK: 6 | print_board_status() 7 | print("board begin faild") 8 | time.sleep(2) 9 | print("board begin success") 10 | 11 | board.set_adc_enable() 12 | 13 | while True: 14 | val = board.get_adc_value(board.A0) # A0 channels read 15 | # Temperature = (val/4096)* 3300/10.24 16 | # print("Temperature = %d C" %Temperature) 17 | # val=val/4096*100 18 | print(val) 19 | 20 | dist = val * 1276/(1023.0*4)/4*2.5 21 | dist=round(dist) 22 | print("Distance--",dist) 23 | 24 | time.sleep(2) 25 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/14_DFR_touch_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time # Import time package for touch time detection 3 | 4 | LED=12 # Define the pin number to which the LED is connected 5 | touch_sensor=8 # Define the pin number to which the sensor is connected 6 | 7 | GPIO.setmode(GPIO.BCM) # Set GPIO mode, BCM mode is common 8 | GPIO.setup(LED,GPIO.OUT) # Set GPIO12 to output mode 9 | GPIO.setup(touch_sensor,GPIO.IN) # Set GPIO8 to input mode 10 | 11 | while True: # Execute the following commands in an infinite loop 12 | if GPIO.input(touch_sensor): # GPIO.input(touch_sensor)will return the state of GPIO and judge, if GPIO8 is high (i.e. The sensor received signal) 13 | GPIO.output(LED,GPIO.HIGH) #Set LED signal pin high (Light LED on) 14 | else : # If GPIO8 is low (Not receive signal) 15 | GPIO.output(LED,GPIO.LOW) #Set LED signal pin low (Turn LED off) 16 | time.sleep(0.1) # Delay one second. 17 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/15_DFR_ball_inclination_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | LED=12 # Define the pin number to which the LED is connected 5 | steel_ball_sensor=8 # Define the pin number to which the sensor is connected 6 | 7 | GPIO.setmode(GPIO.BCM) # Set GPIO mode, BCM mode is common to all Raspberry Pi 8 | GPIO.setup(LED,GPIO.OUT) # Set GPIO12 to output mode 9 | GPIO.setup(steel_ball_sensor,GPIO.IN) # Set GPIO8 to input mode 10 | 11 | while True: # Execute the following commands in an infinite loop 12 | if GPIO.input(steel_ball_sensor): # GPIO.input(steel_ball_sensor)will return the state of GPIO and judge, if GPIO8 is high (i.e. The sensor received signal) 13 | GPIO.output(LED,GPIO.HIGH) #Set LED signal pin high (Light LED on) 14 | else : # If GPIO8 is low (Not receive signal) 15 | GPIO.output(LED,GPIO.LOW) #Set LED signal pin low (Turn LED off) 16 | time.sleep(0.1) # Delay one second 17 | 18 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/16_DFR_magnetic_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO # Import the python module provided by the Raspberry Pi 2 | import time # Import time package for touch time detection 3 | 4 | LED=12 # Define the pin number to which the LED is connected 5 | magnetic_sensor=8 # Define the pin number to which the sensor is connected 6 | 7 | GPIO.setmode(GPIO.BCM) # Set GPIO mode, BCM mode is common to all Raspberry Pi 8 | GPIO.setup(LED,GPIO.OUT) # Set GPIO12 to output mode 9 | GPIO.setup(magnetic_sensor,GPIO.IN) # Set GPIO8 to input mode 10 | 11 | while True: # Execute the following commands in an infinite loop 12 | if GPIO.input(magnetic_sensor): # GPIO.input(KEY)will return the state of GPIO and judge, if GPIO8 is high (i.e. The sensor received signal) 13 | GPIO.output(LED,GPIO.HIGH) #Set LED signal pin high (Light LED on) 14 | else : # If GPIO8 is low (Not receive signal) 15 | GPIO.output(LED,GPIO.LOW) #Set LED signal pin low (Turn LED off) 16 | time.sleep(0.1) # Delay one second 17 | 18 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/17_DFR_minivibration_module.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | vibration_module=12 6 | Button=8 7 | 8 | atexit.register(GPIO.cleanup) 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(vibration_module,GPIO.OUT) 11 | GPIO.setup(Button,GPIO.IN) 12 | 13 | while True: 14 | if GPIO.input(Button): 15 | GPIO.output(vibration_module,GPIO.HIGH) 16 | else : 17 | GPIO.output(vibration_module,GPIO.LOW) 18 | time.sleep(0.1) 19 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/18_DFR_I2C_color_sensor.py: -------------------------------------------------------------------------------- 1 | import smbus 2 | import time 3 | bus = smbus.SMBus(1) 4 | 5 | addr = 0x29 6 | 7 | CDATAL = 0x94 8 | CDATAH = 0x95 9 | RDATAL = 0x96 10 | RDATAH = 0x97 11 | GDATAL = 0x98 12 | GDATAH = 0x99 13 | BDATAL = 0x9a 14 | BDATAH = 0x9b 15 | 16 | while True: 17 | ClearL = bus.read_byte_data(addr , CDATAL) 18 | ClearH = bus.read_byte_data(addr , CDATAH) 19 | Clear = ClearH * 0x100 + ClearL 20 | print("Clear = 0X%x" %Clear) 21 | 22 | RedL = bus.read_byte_data(addr , RDATAL) 23 | RedH = bus.read_byte_data(addr , RDATAH) 24 | Red = RedH * 0x100 + RedL 25 | print("Red = 0X%x" %Red) 26 | 27 | GreenL = bus.read_byte_data(addr , GDATAL) 28 | GreenH = bus.read_byte_data(addr , GDATAH) 29 | Green = GreenH * 0x100 + GreenL 30 | print("Green = 0X%x" %Green) 31 | 32 | BlueL = bus.read_byte_data(addr , BDATAL) 33 | BlueH = bus.read_byte_data(addr , BDATAH) 34 | Blue = BlueH * 0x100 + BlueL 35 | print("Blue = 0X%x" %Blue) 36 | print(f"R:{Red}, G:{Green}, B:{Blue}, Clear:{Clear}") 37 | 38 | print(" ") 39 | time.sleep(1) 40 | 41 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/19_DFR_I2C_LCD_Interface.py: -------------------------------------------------------------------------------- 1 | from lcddf import * 2 | setText("Hello world\nThis is an LCD test") 3 | setRGB(0,128,64) 4 | time.sleep(2) 5 | for c in range(0,255): 6 | setText_norefresh("Going to sleep in {}...".format(str(c))) 7 | setRGB(c,255-c,0) 8 | time.sleep(0.3) 9 | setRGB(0,255,0) 10 | setText("Bye bye, this should wrap onto next line") 11 | setText("Great, this ") 12 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/1_led_control.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | LED=12 6 | 7 | atexit.register(GPIO.cleanup) 8 | GPIO.setmode(GPIO.BCM) 9 | GPIO.setup(LED,GPIO.OUT) 10 | 11 | while True: 12 | GPIO.output(LED,GPIO.HIGH) 13 | time.sleep(1) 14 | GPIO.output(LED,GPIO.LOW) 15 | time.sleep(1) 16 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/20_DFR_RGB_led.py: -------------------------------------------------------------------------------- 1 | #sudo pip3 install rpi_ws281x 2 | #sudo pip3 install adafruit-circuitpython-neopixel 3 | #sudo python3 -m pip install --force-reinstall adafruit-blinka 4 | #include all neccessary packages to get LEDs to work with Raspberry Pi 5 | import time 6 | import board 7 | import neopixel 8 | import random 9 | 10 | 11 | #Initialise a strips variable, provide the GPIO Data Pin 12 | #utilised and the amount of LED Nodes on strip and brightness (0 to 1 value) 13 | pixels1 = neopixel.NeoPixel(board.D18, 1, brightness=0.5) 14 | 15 | #Also create an arbitary count variable 16 | x=0 17 | 18 | 19 | while True: 20 | p1=random.randint(0,255) 21 | p2=random.randint(0,255) 22 | p3=random.randint(0,255) 23 | pixels1.fill((p1, p2, p3)) 24 | time.sleep(0.5) 25 | # pixels1.fill((255, 0, 100)) 26 | #Below demonstrates how to individual address a colour to a LED Node, in this case 27 | #LED Node 10 and colour Blue was selected 28 | #pixels1[10] = (0, 20, 255) 29 | 30 | #Sleep for three seconds, You should now have all LEDs showing light with the first node 31 | #Showing a different colour 32 | #time.sleep(4) 33 | 34 | 35 | #Add a brief time delay to appreciate what has happened 36 | time.sleep(4) 37 | 38 | #Complete the script by returning all the LED to off 39 | pixels1.fill((0, 0, 0)) 40 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/21_DFR_motion_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | LED=12 6 | PIR=8 7 | 8 | 9 | atexit.register(GPIO.cleanup) 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setup(LED,GPIO.OUT) 12 | GPIO.setup(PIR,GPIO.IN) 13 | 14 | while True: 15 | if GPIO.input(PIR): 16 | GPIO.output(LED,GPIO.HIGH) 17 | else : 18 | GPIO.output(LED,GPIO.LOW) 19 | time.sleep(0.1) 20 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/2_led_button.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | LED=12 6 | Button=8 7 | 8 | atexit.register(GPIO.cleanup) 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(LED,GPIO.OUT) 11 | GPIO.setup(Button,GPIO.IN) 12 | 13 | while True: 14 | if GPIO.input(Button): 15 | GPIO.output(LED,GPIO.HIGH) 16 | else : 17 | GPIO.output(LED,GPIO.LOW) 18 | time.sleep(0.1) 19 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/3_DFR_temperature_sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() 4 | 5 | while board.begin() != board.STA_OK: 6 | print_board_status() 7 | print("board begin faild") 8 | time.sleep(2) 9 | print("board begin success") 10 | 11 | board.set_adc_enable() 12 | 13 | while True: 14 | val = board.get_adc_value(board.A0) # A0 channels read 15 | Temperature = (val/4096)* 3300/10.24 16 | print("Temperature = %d C" %Temperature) 17 | # val=val/4096*100 18 | # print(val) 19 | 20 | time.sleep(2) 21 | 22 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/4_DFR_rotation_angle_sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 4 | 5 | 6 | while board.begin() != board.STA_OK: # Board begin and check board status 7 | print_board_status() 8 | print("board begin faild") 9 | time.sleep(2) 10 | print("board begin success") 11 | 12 | board.set_adc_enable() 13 | 14 | while True: 15 | val = board.get_adc_value(board.A0) # A0 channels read 16 | #val = board.get_adc_value(board.A1) # A1 channels read 17 | #val = board.get_adc_value(board.A2) # A2 channels read 18 | #val = board.get_adc_value(board.A3) # A3 channels read 19 | print("channel: A0, value: %d" %val) 20 | print("") 21 | 22 | time.sleep(2) 23 | 24 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/5_DFR_DC_fan_control.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | from dfadc import * 3 | 4 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 5 | 6 | # Set board controler address, use it carefully, reboot module to make it effective 7 | 8 | while board.begin() != board.STA_OK:# Board begin and check board status 9 | print_board_status() 10 | print("board begin faild") 11 | time.sleep(2) 12 | print("board begin success") 13 | 14 | board.set_pwm_enable() # Pwm channel need external power 15 | board.set_adc_enable() 16 | board.set_pwm_frequency(1000) # Set frequency to 1000HZ, Attention: PWM voltage depends on independent power supply 17 | 18 | while True: 19 | val = board.get_adc_value(board.A0) 20 | val = val/4096 *100 21 | print("set all pwm channels duty to %d",val) 22 | board.set_pwm_duty(0,val) # Set all pwm channels duty 23 | time.sleep(0.2) 24 | 25 | #print("set part pwm channels duty to 100%") 26 | 27 | #board.set_pwm_duty(0, 50) # Set pwm0 channels duty 28 | #board.set_pwm_duty(1, 70) # Set pwm1 channels duty 29 | #board.set_pwm_duty(2, 80) # Set pwm2 channels duty 30 | #board.set_pwm_duty(3, 90) # Set pwm3 channels duty 31 | #time.sleep(5) 32 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/6_DFR_Joystick.py: -------------------------------------------------------------------------------- 1 | import time 2 | import RPi.GPIO as GPIO 3 | import atexit 4 | 5 | Button=8 6 | 7 | atexit.register(GPIO.cleanup) 8 | GPIO.setmode(GPIO.BCM) 9 | GPIO.setup(Button,GPIO.IN) 10 | 11 | 12 | from dfadc import * 13 | 14 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 15 | 16 | 17 | while board.begin() != board.STA_OK: # Board begin and check board status 18 | print_board_status() 19 | print("board begin faild") 20 | time.sleep(2) 21 | print("board begin success") 22 | 23 | board.set_adc_enable() 24 | # board.set_adc_disable() 25 | 26 | while True: 27 | X = board.get_adc_value(board.A1) # A0 channels read 28 | X = X - 2024 29 | print("X = %d" %X) 30 | 31 | Y = board.get_adc_value(board.A0) # A0 channels read 32 | Y = Y - 2024 33 | print("Y = %d" %Y) 34 | 35 | Z = GPIO.input(Button) 36 | print("Z = %d" %Z) 37 | print("") 38 | 39 | time.sleep(0.01) 40 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/7_DFR_light_sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() 4 | 5 | 6 | 7 | while board.begin() != board.STA_OK:# Board begin and check board status 8 | print_board_status() 9 | print("board begin faild") 10 | time.sleep(2) 11 | print("board begin success") 12 | 13 | board.set_pwm_enable() # Pwm channel need external power 14 | board.set_adc_enable() 15 | board.set_pwm_frequency(1000) # Set frequency to 1000HZ, Attention: PWM voltage depends on independent power supply 16 | 17 | while True: 18 | val = board.get_adc_value(board.A0) 19 | val = val/4096 *100 20 | print("set all pwm channels duty to %d",val) 21 | board.set_pwm_duty(0,val) # Connect DC motor to PWM0 22 | time.sleep(0.2) 23 | 24 | #print("set part pwm channels duty to 100%") 25 | 26 | #board.set_pwm_duty(0, 50) # Set pwm0 channels duty 27 | #board.set_pwm_duty(1, 70) # Set pwm1 channels duty 28 | #board.set_pwm_duty(2, 80) # Set pwm2 channels duty 29 | #board.set_pwm_duty(3, 90) # Set pwm3 channels duty 30 | #time.sleep(5) 31 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/8_DFR_digital_vibration_sensor.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | 5 | LED=12 6 | Vibration=8 7 | 8 | atexit.register(GPIO.cleanup) 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(LED,GPIO.OUT) 11 | GPIO.setup(Vibration,GPIO.IN) 12 | 13 | while True: 14 | if GPIO.input(Vibration): 15 | GPIO.output(LED,GPIO.HIGH) 16 | else : 17 | GPIO.output(LED,GPIO.LOW) 18 | time.sleep(0.1) 19 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/9_DFR_Analog_Sound_Sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | board_detect() 3 | while board.begin() != board.STA_OK:# Board begin and check board status 4 | print_board_status() 5 | print("board begin faild") 6 | time.sleep(2) 7 | print("board begin success") 8 | 9 | board.set_pwm_enable() # Pwm channel need external power 10 | board.set_adc_enable() 11 | board.set_pwm_frequency(1000) # Set frequency to 1000HZ, Attention: PWM voltage depends on independent power supply 12 | 13 | while True: 14 | val = board.get_adc_value(board.A0) 15 | val = val/4096 *100*5 16 | print("set all pwm channels duty to %d",val) 17 | board.set_pwm_duty(0,val) # Connect DC motor to PWM0 18 | time.sleep(0.2) 19 | 20 | #print("set part pwm channels duty to 100%") 21 | 22 | #board.set_pwm_duty(0, 50) # Set pwm0 channels duty 23 | #board.set_pwm_duty(1, 70) # Set pwm1 channels duty 24 | #board.set_pwm_duty(2, 80) # Set pwm2 channels duty 25 | #board.set_pwm_duty(3, 90) # Set pwm3 channels duty 26 | #time.sleep(5) 27 | 28 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/DFRobot_RaspberryPi_Expansion_Board.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | _PWM_CHAN_COUNT = 4 4 | _ADC_CHAN_COUNT = 4 5 | 6 | class DFRobot_Expansion_Board: 7 | 8 | _REG_SLAVE_ADDR = 0x00 9 | _REG_PID = 0x01 10 | _REG_VID = 0x02 11 | _REG_PWM_CONTROL = 0x03 12 | _REG_PWM_FREQ = 0x04 13 | _REG_PWM_DUTY1 = 0x06 14 | _REG_PWM_DUTY2 = 0x08 15 | _REG_PWM_DUTY3 = 0x0a 16 | _REG_PWM_DUTY4 = 0x0c 17 | _REG_ADC_CTRL = 0x0e 18 | _REG_ADC_VAL1 = 0x0f 19 | _REG_ADC_VAL2 = 0x11 20 | _REG_ADC_VAL3 = 0x13 21 | _REG_ADC_VAL4 = 0x15 22 | 23 | _REG_DEF_PID = 0xdf 24 | _REG_DEF_VID = 0x10 25 | 26 | ''' Enum board Analog channels ''' 27 | A0 = 0x00 28 | A1 = 0x01 29 | A2 = 0x02 30 | A3 = 0x03 31 | 32 | ''' Board status ''' 33 | STA_OK = 0x00 34 | STA_ERR = 0x01 35 | STA_ERR_DEVICE_NOT_DETECTED = 0x02 36 | STA_ERR_SOFT_VERSION = 0x03 37 | STA_ERR_PARAMETER = 0x04 38 | 39 | ''' last operate status, users can use this variable to determine the result of a function call. ''' 40 | last_operate_status = STA_OK 41 | 42 | ''' Global variables ''' 43 | ALL = 0xffffffff 44 | 45 | def _write_bytes(self, reg, buf): 46 | pass 47 | 48 | def _read_bytes(self, reg, len): 49 | pass 50 | 51 | def __init__(self, addr): 52 | self._addr = addr 53 | self._is_pwm_enable = False 54 | 55 | def begin(self): 56 | ''' 57 | @brief Board begin 58 | @return Board status 59 | ''' 60 | pid = self._read_bytes(self._REG_PID, 1) 61 | vid = self._read_bytes(self._REG_VID, 1) 62 | if self.last_operate_status == self.STA_OK: 63 | if pid[0] != self._REG_DEF_PID: 64 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 65 | elif vid[0] != self._REG_DEF_VID: 66 | self.last_operate_status = self.STA_ERR_SOFT_VERSION 67 | else: 68 | self.set_pwm_disable() 69 | self.set_pwm_duty(self.ALL, 0) 70 | self.set_adc_disable() 71 | return self.last_operate_status 72 | 73 | def set_addr(self, addr): 74 | ''' 75 | @brief Set board controler address, reboot module to make it effective 76 | @param address: int Address to set, range in 1 to 127 77 | ''' 78 | if addr < 1 or addr > 127: 79 | self.last_operate_status = self.STA_ERR_PARAMETER 80 | return 81 | self._write_bytes(self._REG_SLAVE_ADDR, [addr]) 82 | 83 | def _parse_id(self, limit, id): 84 | ld = [] 85 | if isinstance(id, list) == False: 86 | id = id + 1 87 | ld.append(id) 88 | else: 89 | ld = [i + 1 for i in id] 90 | if ld == self.ALL: 91 | return range(1, limit + 1) 92 | for i in ld: 93 | if i < 1 or i > limit: 94 | self.last_operate_status = self.STA_ERR_PARAMETER 95 | return [] 96 | return ld 97 | 98 | def set_pwm_enable(self): 99 | ''' 100 | @brief Set pwm enable, pwm channel need external power 101 | ''' 102 | self._write_bytes(self._REG_PWM_CONTROL, [0x01]) 103 | if self.last_operate_status == self.STA_OK: 104 | self._is_pwm_enable = True 105 | time.sleep(0.01) 106 | 107 | def set_pwm_disable(self): 108 | ''' 109 | @brief Set pwm disable 110 | ''' 111 | self._write_bytes(self._REG_PWM_CONTROL, [0x00]) 112 | if self.last_operate_status == self.STA_OK: 113 | self._is_pwm_enable = False 114 | time.sleep(0.01) 115 | 116 | def set_pwm_frequency(self, freq): 117 | ''' 118 | @brief Set pwm frequency 119 | @param freq: int Frequency to set, in range 1 - 1000 120 | ''' 121 | if freq < 1 or freq > 1000: 122 | self.last_operate_status = self.STA_ERR_PARAMETER 123 | return 124 | is_pwm_enable = self._is_pwm_enable 125 | self.set_pwm_disable() 126 | self._write_bytes(self._REG_PWM_FREQ, [freq >> 8, freq & 0xff]) 127 | time.sleep(0.01) 128 | if is_pwm_enable: 129 | self.set_pwm_enable() 130 | 131 | def set_pwm_duty(self, chan, duty): 132 | ''' 133 | @brief Set selected channel duty 134 | @param chan: list One or more channels to set, items in range 1 to 4, or chan = self.ALL 135 | @param duty: float Duty to set, in range 0.0 to 100.0 136 | ''' 137 | if duty < 0 or duty > 100: 138 | self.last_operate_status = self.STA_ERR_PARAMETER 139 | return 140 | for i in self._parse_id(_PWM_CHAN_COUNT, chan): 141 | self._write_bytes(self._REG_PWM_DUTY1 + (i - 1) * 2, [int(duty), int((duty * 10) % 10)]) 142 | 143 | def set_adc_enable(self): 144 | ''' 145 | @brief Set adc enable 146 | ''' 147 | self._write_bytes(self._REG_ADC_CTRL, [0x01]) 148 | 149 | def set_adc_disable(self): 150 | ''' 151 | @brief Set adc disable 152 | ''' 153 | self._write_bytes(self._REG_ADC_CTRL, [0x00]) 154 | 155 | def get_adc_value(self, chan): 156 | ''' 157 | @brief Get adc value 158 | @param chan: int Channel to get, in range 1 to 4, or self.ALL 159 | @return :list List of value 160 | ''' 161 | for i in self._parse_id(_ADC_CHAN_COUNT, chan): 162 | rslt = self._read_bytes(self._REG_ADC_VAL1 + (i - 1) * 2, 2) 163 | return ((rslt[0] << 8) | rslt[1]) 164 | 165 | def detecte(self): 166 | ''' 167 | @brief If you forget address you had set, use this to detecte them, must have class instance 168 | @return Board list conformed 169 | ''' 170 | l = [] 171 | back = self._addr 172 | for i in range(1, 127): 173 | self._addr = i 174 | if self.begin() == self.STA_OK: 175 | l.append(i) 176 | for i in range(0, len(l)): 177 | l[i] = hex(l[i]) 178 | self._addr = back 179 | self.last_operate_status = self.STA_OK 180 | return l 181 | 182 | class DFRobot_Epansion_Board_Digital_RGB_LED(): 183 | 184 | def __init__(self, board): 185 | ''' 186 | @param board: DFRobot_Expansion_Board Board instance to operate digital rgb led, test LED: https://www.dfrobot.com/product-1829.html 187 | Warning: LED must connect to pwm channel, otherwise may destory Pi IO 188 | ''' 189 | self._board = board 190 | self._chan_r = 0 191 | self._chan_g = 0 192 | self._chan_b = 0 193 | 194 | def begin(self, chan_r, chan_g, chan_b): 195 | ''' 196 | @brief Set digital rgb led color channel, these parameters not repeat 197 | @param chan_r: int Set color red channel id, in range 1 to 4 198 | @param chan_g: int Set color green channel id, in range 1 to 4 199 | @param chan_b: int Set color blue channel id, in range 1 to 4 200 | ''' 201 | if chan_r == chan_g or chan_r == chan_b or chan_g == chan_b: 202 | return 203 | if chan_r < _PWM_CHAN_COUNT and chan_g < _PWM_CHAN_COUNT and chan_b < _PWM_CHAN_COUNT: 204 | self._chan_r = chan_r 205 | self._chan_g = chan_g 206 | self._chan_b = chan_b 207 | self._board.set_pwm_enable() 208 | self._board.set_pwm_frequency(1000) 209 | self._board.set_pwm_duty(self._board.ALL, 100) 210 | 211 | def color888(self, r, g, b): 212 | ''' 213 | @brief Set LED to true-color 214 | @param r: int Color components red 215 | @param g: int Color components green 216 | @param b: int Color components blue 217 | ''' 218 | self._board.set_pwm_duty([self._chan_r], 100 - (r & 0xff) * 100 // 255) 219 | self._board.set_pwm_duty([self._chan_g], 100 - (g & 0xff) * 100 // 255) 220 | self._board.set_pwm_duty([self._chan_b], 100 - (b & 0xff) * 100 // 255) 221 | 222 | def color24(self, color): 223 | ''' 224 | @brief Set LED to 24-bits color 225 | @param color: int 24-bits color 226 | ''' 227 | color &= 0xffffff 228 | self.color888(color >> 16, (color >> 8) & 0xff, color & 0xff) 229 | 230 | def color565(self, color): 231 | ''' 232 | @brief Set LED to 16-bits color 233 | @param color: int 16-bits color 234 | ''' 235 | color &= 0xffff 236 | self.color888((color & 0xf800) >> 8, (color & 0x7e0) >> 3, (color & 0x1f) << 3) 237 | 238 | class DFRobot_Expansion_Board_Servo(): 239 | 240 | def __init__(self, board): 241 | ''' 242 | @param board: DFRobot_Expansion_Board Board instance to operate servo, test servo: https://www.dfrobot.com/product-255.html 243 | Warning: servo must connect to pwm channel, otherwise may destory Pi IO 244 | ''' 245 | self._board = board 246 | 247 | def begin(self): 248 | ''' 249 | @brief Board servo begin 250 | ''' 251 | self._board.set_pwm_enable() 252 | self._board.set_pwm_frequency(50) 253 | self._board.set_pwm_duty(self._board.ALL, 0) 254 | 255 | def move(self, id, angle): 256 | ''' 257 | @brief Servos move 258 | @param id: list One or more servos to set, items in range 1 to 4, or chan = self.ALL 259 | @param angle: int Angle to move, in range 0 to 180 260 | ''' 261 | if 0 <= angle <= 180: 262 | self._board.set_pwm_duty(id, (0.5 + (float(angle) / 90.0)) / 20 * 100) 263 | 264 | import smbus 265 | 266 | class DFRobot_Expansion_Board_IIC(DFRobot_Expansion_Board): 267 | 268 | def __init__(self, bus_id, addr): 269 | ''' 270 | @param bus_id: int Which bus to operate 271 | @oaram addr: int Board controler address 272 | ''' 273 | self._bus = smbus.SMBus(bus_id) 274 | DFRobot_Expansion_Board.__init__(self, addr) 275 | 276 | def _write_bytes(self, reg, buf): 277 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 278 | try: 279 | self._bus.write_i2c_block_data(self._addr, reg, buf) 280 | self.last_operate_status = self.STA_OK 281 | except: 282 | pass 283 | 284 | def _read_bytes(self, reg, len): 285 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 286 | try: 287 | rslt = self._bus.read_i2c_block_data(self._addr, reg, len) 288 | self.last_operate_status = self.STA_OK 289 | return rslt 290 | except: 291 | return [0] * len 292 | 293 | 294 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/dfadc.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board 4 | 5 | board = Board(1, 0x10) # Select i2c bus 1, set address to 0x10 6 | 7 | def board_detect(): 8 | l = board.detecte() 9 | print("Board list conform:") 10 | print(l) 11 | 12 | ''' print last operate status, users can use this variable to determine the result of a function call. ''' 13 | def print_board_status(): 14 | if board.last_operate_status == board.STA_OK: 15 | print("board status: everything ok") 16 | elif board.last_operate_status == board.STA_ERR: 17 | print("board status: unexpected error") 18 | elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED: 19 | print("board status: device not detected") 20 | elif board.last_operate_status == board.STA_ERR_PARAMETER: 21 | print("board status: parameter error") 22 | elif board.last_operate_status == board.STA_ERR_SOFT_VERSION: 23 | print("board status: unsupport board framware version") 24 | -------------------------------------------------------------------------------- /Module-2/Unit-3/DFRobot_IoT_Codes/lcddf.py: -------------------------------------------------------------------------------- 1 | import time,sys 2 | 3 | if sys.platform == 'uwp': 4 | import winrt_smbus as smbus 5 | bus = smbus.SMBus(1) 6 | else: 7 | import smbus 8 | import RPi.GPIO as GPIO 9 | rev = GPIO.RPI_REVISION 10 | if rev == 2 or rev == 3: 11 | bus = smbus.SMBus(1) 12 | else: 13 | bus = smbus.SMBus(0) 14 | 15 | # this device has two I2C addresses 16 | DISPLAY_RGB_ADDR = 0x2d 17 | DISPLAY_TEXT_ADDR = 0x3e 18 | 19 | # set backlight to (R,G,B) (values from 0..255 for each) 20 | def setRGB(r,g,b): 21 | bus.write_byte_data(DISPLAY_RGB_ADDR,0,0) 22 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,0) 23 | bus.write_byte_data(DISPLAY_RGB_ADDR,0x08,0xaa) 24 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,r) 25 | bus.write_byte_data(DISPLAY_RGB_ADDR,2,g) 26 | bus.write_byte_data(DISPLAY_RGB_ADDR,3,b) 27 | 28 | # send command to display (no need for external use) 29 | def textCommand(cmd): 30 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd) 31 | 32 | # set display text \n for second line(or auto wrap) 33 | def setText(text): 34 | textCommand(0x01) # clear display 35 | time.sleep(.05) 36 | textCommand(0x08 | 0x04) # display on, no cursor 37 | textCommand(0x28) # 2 lines 38 | time.sleep(.05) 39 | count = 0 40 | row = 0 41 | for c in text: 42 | if c == '\n' or count == 16: 43 | count = 0 44 | row += 1 45 | if row == 2: 46 | break 47 | textCommand(0xc0) 48 | if c == '\n': 49 | continue 50 | count += 1 51 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 52 | 53 | #Update the display without erasing the display 54 | def setText_norefresh(text): 55 | textCommand(0x02) # return home 56 | time.sleep(.05) 57 | textCommand(0x08 | 0x04) # display on, no cursor 58 | textCommand(0x28) # 2 lines 59 | time.sleep(.05) 60 | count = 0 61 | row = 0 62 | while len(text) < 32: #clears the rest of the screen 63 | text += ' ' 64 | for c in text: 65 | if c == '\n' or count == 16: 66 | count = 0 67 | row += 1 68 | if row == 2: 69 | break 70 | textCommand(0xc0) 71 | if c == '\n': 72 | continue 73 | count += 1 74 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 75 | 76 | # Create a custom character (from array of row patterns) 77 | def create_char(location, pattern): 78 | """ 79 | Writes a bit pattern to LCD CGRAM 80 | 81 | Arguments: 82 | location -- integer, one of 8 slots (0-7) 83 | pattern -- byte array containing the bit pattern, like as found at 84 | https://omerk.github.io/lcdchargen/ 85 | """ 86 | location &= 0x07 # Make sure location is 0-7 87 | textCommand(0x40 | (location << 3)) 88 | bus.write_i2c_block_data(DISPLAY_TEXT_ADDR, 0x40, pattern) 89 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/10_Analog_read_potentiometer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import grovepi 4 | 5 | from grove_rgb_lcd import * 6 | 7 | # Connect the Rotary Angle Sensor to analog port A2 8 | 9 | potentiometer = 2 10 | 11 | time.sleep(1) 12 | 13 | i = 0 14 | 15 | while True: 16 | 17 | i = grovepi.analogRead(potentiometer) 18 | 19 | print(i) 20 | 21 | setRGB(i//4,i//4,i//4) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/11_Analog_Light_Sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import grovepi 4 | 5 | from grove_rgb_lcd import * 6 | 7 | # Connect the Grove Light Sensor to analog port A0 8 | 9 | # SIG,NC,VCC,GND 10 | 11 | light_sensor = 0 12 | 13 | 14 | 15 | # Connect the LED to digital port D4 16 | 17 | # SIG,NC,VCC,GND 18 | 19 | led = 5 20 | 21 | 22 | 23 | # Turn on LED once sensor exceeds threshold resistance 24 | 25 | threshold = 100 26 | 27 | 28 | 29 | grovepi.pinMode(light_sensor,"INPUT") 30 | 31 | grovepi.pinMode(led,"OUTPUT") 32 | 33 | 34 | 35 | while True: 36 | 37 | try: 38 | 39 | # Get sensor value 40 | 41 | sensor_value = grovepi.analogRead(light_sensor) 42 | 43 | print(sensor_value) 44 | 45 | 46 | 47 | # Calculate resistance of sensor in K 48 | 49 | resistance = (float)(1023 - sensor_value) * 10 / (sensor_value + 0.001) 50 | 51 | setRGB(255-10*sensor_value,255-10*sensor_value,255-10*sensor_value) 52 | 53 | 54 | 55 | if sensor_value > threshold: 56 | 57 | # Send HIGH to switch on LED 58 | 59 | grovepi.digitalWrite(led,0) 60 | 61 | setText_norefresh("Turn off Smart Light") 62 | 63 | else: 64 | 65 | # Send LOW to switch off LED 66 | 67 | grovepi.digitalWrite(led,1) 68 | 69 | setText_norefresh("Turn on Smart Light") 70 | 71 | 72 | 73 | print("sensor_value = %d resistance = %.2f" %(sensor_value, resistance)) 74 | 75 | time.sleep(.5) 76 | 77 | 78 | 79 | except IOError: 80 | 81 | print ("Error") -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/12_LCD_Interfacing.py: -------------------------------------------------------------------------------- 1 | from grove_rgb_lcd import * 2 | 3 | import time 4 | 5 | import random 6 | 7 | while True: 8 | 9 | p1=random.randint(0,255) 10 | 11 | p2=random.randint(0,255) 12 | 13 | p3=random.randint(0,255) 14 | 15 | time.sleep(0.5) 16 | 17 | setRGB(p1,p2,p3) # (Green) RGB Pattern 18 | 19 | 20 | 21 | setText("Hi Welocme to Code Unnati") -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/13_LED_PWM_Control.py: -------------------------------------------------------------------------------- 1 | import time 2 | import grovepi 3 | 4 | # Connect the Grove LED to digital port D3 5 | led = 3 6 | 7 | # Digital ports that support Pulse Width Modulation (PWM) 8 | # D3, D5, D6 9 | 10 | # Digital ports that do not support PWM 11 | # D2, D4, D7, D8 12 | 13 | grovepi.pinMode(led,"OUTPUT") 14 | time.sleep(1) 15 | i = 0 16 | 17 | while True: 18 | try: 19 | # Reset 20 | if i > 255: 21 | i = 0 22 | 23 | # Current brightness 24 | print (i) 25 | 26 | # Give PWM output to LED 27 | grovepi.analogWrite(led,i) 28 | 29 | # Increment brightness for next iteration 30 | i = i + 20 31 | time.sleep(.3) 32 | 33 | except KeyboardInterrupt: 34 | grovepi.analogWrite(led,0) 35 | break 36 | except IOError: 37 | print ("Error") -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/14_External_controlled_LED_Glow.py: -------------------------------------------------------------------------------- 1 | import time 2 | import grovepi 3 | from grove_rgb_lcd import * 4 | # Connect the Rotary Angle Sensor to analog port A2 5 | potentiometer = 2 6 | 7 | # Connect the LED to digital port D5 8 | # Check for PWM pin 9 | led = 5 10 | 11 | grovepi.pinMode(led,"OUTPUT") 12 | time.sleep(1) 13 | i = 0 14 | 15 | while True: 16 | try: 17 | # Read resistance from Potentiometer 18 | i = grovepi.analogRead(potentiometer) 19 | print(i) 20 | 21 | # Send PWM signal to LED 22 | grovepi.analogWrite(led,i//4) 23 | setRGB(i//4,i//4,i//4) 24 | 25 | except IOError: 26 | print("Error") 27 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/15_DC_Motor_Control.py: -------------------------------------------------------------------------------- 1 | import time 2 | import grovepi 3 | from grove_rgb_lcd import * 4 | # Connect the Rotary Angle Sensor to analog port A2 5 | potentiometer = 2 6 | 7 | # Connect the dc_motor to digital port D5 8 | # Check for PWM pin 9 | dc_motor = 5 10 | 11 | grovepi.pinMode(dc_motor,"OUTPUT") 12 | time.sleep(1) 13 | i = 0 14 | 15 | while True: 16 | try: 17 | # Read resistance from Potentiometer 18 | i = grovepi.analogRead(potentiometer) 19 | print(i) 20 | 21 | # Send PWM signal to dc_motor 22 | grovepi.analogWrite(dc_motor,i//4) 23 | setRGB(i//4,i//4,i//4) 24 | 25 | except IOError: 26 | print("Error") 27 | 28 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/16_Ultrasonic_GrovePI.py: -------------------------------------------------------------------------------- 1 | from grovepi import * 2 | 3 | from grove_rgb_lcd import * 4 | 5 | import time 6 | 7 | 8 | ultrasonic_ranger = 7 9 | 10 | setRGB(0,100,0) 11 | 12 | 13 | while True: 14 | 15 | distant = ultrasonicRead(ultrasonic_ranger) 16 | 17 | print(distant,'cm') 18 | 19 | setText_norefresh(str(distant)+'cm') 20 | 21 | time.sleep(0.5) 22 | 23 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/1_LED_Interfacing.py: -------------------------------------------------------------------------------- 1 | from grovepi import * 2 | 3 | led = 7 4 | pinMode(led,"OUTPUT") 5 | 6 | ip = input() 7 | if ip == "H": 8 | digitalWrite(led,1) 9 | elif ip =="L": 10 | digitalWrite(led,0) 11 | 12 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/2_Buzzer_Control.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | buzzer_pin = 2 #Port for buzzer 5 | button = 4 6 | pinMode(buzzer_pin,"OUTPUT") 7 | pinMode(button,"INPUT") 8 | digitalWrite(buzzer_pin,0) 9 | while True: 10 | a=digitalRead(button) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(buzzer_pin,0) 14 | else: 15 | digitalWrite(buzzer_pin,1) 16 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/3_Vibration_Detection.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | buzzer_pin = 2 #Port for buzzer 5 | vibration_sensor = 4 6 | pinMode(buzzer_pin,"OUTPUT") 7 | pinMode(vibration_sensor,"INPUT") 8 | digitalWrite(buzzer_pin,0) 9 | while True: 10 | a=digitalRead(vibration_sensor) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(buzzer_pin,0) 14 | else: 15 | digitalWrite(buzzer_pin,1) 16 | 17 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/4_Heart_beat_sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | LED = 2 #Port for buzzer 5 | heart_beat_sensor = 4 6 | pinMode(LED,"OUTPUT") 7 | pinMode(heart_beat_sensor,"INPUT") 8 | digitalWrite(LED,0) 9 | while True: 10 | a=digitalRead(heart_beat_sensor) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(LED,0) 14 | else: 15 | digitalWrite(LED,1) 16 | 17 | 18 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/4x4_Matrix_with_library.py: -------------------------------------------------------------------------------- 1 | #pip3 install pad4pi 2 | from pad4pi import rpi_gpio 3 | 4 | import time 5 | 6 | KEYPAD = [ 7 | 8 | [1, 2, 3, "A"], 9 | 10 | [4, 5, 6, "B"], 11 | 12 | [7, 8, 9, "C"], 13 | 14 | ["*", 0, "#", "D"] 15 | 16 | ] 17 | 18 | ROW_PINS = [17, 27, 22, 5] # BCM numbering 19 | 20 | COL_PINS = [23, 24, 25, 16] # BCM numbering 21 | 22 | def print_key(key): 23 | 24 | print(f"Received key from interrupt:: {key}") 25 | 26 | try: 27 | 28 | factory = rpi_gpio.KeypadFactory() 29 | 30 | keypad = factory.create_keypad(keypad=KEYPAD,row_pins=ROW_PINS, col_pins=COL_PINS) # makes assumptions about keypad layout and GPIO pin numbers 31 | 32 | keypad.registerKeyPressHandler(print_key) 33 | 34 | print("Press buttons on your keypad. Ctrl+C to exit.") 35 | 36 | while True: 37 | 38 | time.sleep(1) 39 | 40 | except KeyboardInterrupt: 41 | 42 | print("Goodbye") 43 | 44 | finally: 45 | 46 | keypad.cleanup() 47 | 48 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/4x4_matrix_Keyboard.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | """ 4 | R1=4 5 | R2=5 6 | R3=6 7 | R4=7 8 | C1=8 9 | C2=9 10 | C3=10 11 | C4=11 12 | """ 13 | """ 14 | R1=5 15 | R2=6 16 | R3=13 17 | R4=19 18 | C1=12 19 | C2=16 20 | C3=20 21 | C4=21 22 | """ 23 | R1=17 24 | R2=27 25 | R3=22 26 | R4=5 27 | C1=23 28 | C2=24 29 | C3=25 30 | C4=16 31 | 32 | GPIO.setmode(GPIO.BCM) 33 | GPIO.setup(R1,GPIO.OUT) 34 | GPIO.setup(R2,GPIO.OUT) 35 | GPIO.setup(R3,GPIO.OUT) 36 | GPIO.setup(R4,GPIO.OUT) 37 | 38 | GPIO.setup(C1,GPIO.IN) 39 | GPIO.setup(C2,GPIO.IN) 40 | GPIO.setup(C3,GPIO.IN) 41 | GPIO.setup(C4,GPIO.IN) 42 | 43 | 44 | 45 | def readLine(line, characters): 46 | 47 | GPIO.output(line,GPIO.HIGH) 48 | 49 | if(GPIO.input(C1) == 1): 50 | print(characters[0]) 51 | if(GPIO.input(C2) == 1): 52 | print(characters[1]) 53 | if(GPIO.input(C3) == 1): 54 | print(characters[2]) 55 | if(GPIO.input(C4) == 1): 56 | print(characters[3]) 57 | 58 | GPIO.output(line,GPIO.LOW) 59 | 60 | 61 | while True: 62 | 63 | readLine(R1, ["1","2","3","A"]) 64 | 65 | readLine(R2, ["4","5","6","B"]) 66 | 67 | readLine(R3, ["7","8","9","C"]) 68 | 69 | readLine(R4, ["*","0","#","D"]) 70 | 71 | time.sleep(0.1) 72 | 73 | 74 | 75 | print("\nApplication stopped!") 76 | 77 | 78 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/5_Conductivity_Sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | buzzer_pin = 2 #Port for buzzer 5 | conductivity_sensor = 4 6 | pinMode(buzzer_pin,"OUTPUT") 7 | pinMode(conductivity_sensor,"INPUT") 8 | digitalWrite(buzzer_pin,0) 9 | while True: 10 | a=digitalRead(conductivity_sensor) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(buzzer_pin,0) 14 | else: 15 | digitalWrite(buzzer_pin,1) 16 | 17 | 18 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/6_Touch_Sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | buzzer_pin = 2 #Port for buzzer 5 | touch_sensor = 4 6 | pinMode(buzzer_pin,"OUTPUT") 7 | pinMode(touch_sensor,"INPUT") 8 | digitalWrite(buzzer_pin,0) 9 | while True: 10 | a=digitalRead(touch_sensor) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(buzzer_pin,0) 14 | else: 15 | digitalWrite(buzzer_pin,1) 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/7_Tilt_Sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | from grovepi import * 3 | import math 4 | LED = 2 #Port for buzzer 5 | Tilt_sensor = 4 6 | pinMode(LED,"OUTPUT") 7 | pinMode(Tilt_sensor,"INPUT") 8 | digitalWrite(LED,0) 9 | while True: 10 | a=digitalRead(Tilt_sensor) 11 | print(a) 12 | if (a==0): 13 | digitalWrite(LED,0) 14 | else: 15 | digitalWrite(LED,1) 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/8_LM35_Temp_Sensor.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | import grovepi 4 | 5 | from grove_rgb_lcd import * 6 | 7 | # Connect the LM35 Temp Sensor to analog port A2 8 | setRGB(255,0,0) 9 | temp_sensor = 2 10 | time.sleep(1) 11 | i = 0 12 | while True: 13 | i = grovepi.analogRead(temp_sensor) 14 | val= i 15 | print(i) 16 | # setText_norefresh("Temperature: {0}".format(temp) ) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/9_DHT_Sensor.py: -------------------------------------------------------------------------------- 1 | from grovepi import * 2 | 3 | from grove_rgb_lcd import * 4 | 5 | import time 6 | 7 | dht_sensor_port = 7 8 | 9 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 10 | 11 | setRGB(0,255,0) 12 | 13 | while True: 14 | 15 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 16 | 17 | print(f"Temp:{t} C Humidity:{h}%") 18 | 19 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 20 | 21 | time.sleep(2) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/Autotweet_GrovePI.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | from grovepi import * 3 | from grove_rgb_lcd import * 4 | import time 5 | from math import isnan 6 | from time import strftime 7 | import math 8 | 9 | consumer_key = '2IWlVt3Px1GtUfM7T6n1thTGC' 10 | consumer_secret = 'YasyTDfoMXRakvxLWLtyVXatC98T8lTIXdy96kiZyT7ClgXGad' 11 | access_token = '1043489874559397888-Ok5ZP06n6kaPIHHrgSk41fIhJPfArK' 12 | access_token_secret = 'gFmwTsr9lH7b5v8t8BR8mTpDwyJ7M7GttYMu4UL4zm6cz' 13 | 14 | client = tweepy.Client(consumer_key=consumer_key,consumer_secret=consumer_secret,access_token=access_token,access_token_secret=access_token_secret) 15 | 16 | location="Jaipur" 17 | #time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 18 | #print(time_stamp) 19 | dht_sensor_port = 7 20 | 21 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 22 | setRGB(0,255,0) 23 | while True: 24 | # Print the values to the serial port 25 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 26 | print(f"Temp:{t} C Humidity:{h}%") 27 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 28 | print(t) 29 | print(h) 30 | time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 31 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 32 | sd='Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h) 33 | sd=time_stamp+" "+sd 34 | print(sd) 35 | client.create_tweet(text=sd) 36 | print("Sent to Twitter") 37 | time.sleep(5.0) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/DFRobot_RaspberryPi_Expansion_Board.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | _PWM_CHAN_COUNT = 4 4 | _ADC_CHAN_COUNT = 4 5 | 6 | class DFRobot_Expansion_Board: 7 | 8 | _REG_SLAVE_ADDR = 0x00 9 | _REG_PID = 0x01 10 | _REG_VID = 0x02 11 | _REG_PWM_CONTROL = 0x03 12 | _REG_PWM_FREQ = 0x04 13 | _REG_PWM_DUTY1 = 0x06 14 | _REG_PWM_DUTY2 = 0x08 15 | _REG_PWM_DUTY3 = 0x0a 16 | _REG_PWM_DUTY4 = 0x0c 17 | _REG_ADC_CTRL = 0x0e 18 | _REG_ADC_VAL1 = 0x0f 19 | _REG_ADC_VAL2 = 0x11 20 | _REG_ADC_VAL3 = 0x13 21 | _REG_ADC_VAL4 = 0x15 22 | 23 | _REG_DEF_PID = 0xdf 24 | _REG_DEF_VID = 0x10 25 | 26 | ''' Enum board Analog channels ''' 27 | A0 = 0x00 28 | A1 = 0x01 29 | A2 = 0x02 30 | A3 = 0x03 31 | 32 | ''' Board status ''' 33 | STA_OK = 0x00 34 | STA_ERR = 0x01 35 | STA_ERR_DEVICE_NOT_DETECTED = 0x02 36 | STA_ERR_SOFT_VERSION = 0x03 37 | STA_ERR_PARAMETER = 0x04 38 | 39 | ''' last operate status, users can use this variable to determine the result of a function call. ''' 40 | last_operate_status = STA_OK 41 | 42 | ''' Global variables ''' 43 | ALL = 0xffffffff 44 | 45 | def _write_bytes(self, reg, buf): 46 | pass 47 | 48 | def _read_bytes(self, reg, len): 49 | pass 50 | 51 | def __init__(self, addr): 52 | self._addr = addr 53 | self._is_pwm_enable = False 54 | 55 | def begin(self): 56 | ''' 57 | @brief Board begin 58 | @return Board status 59 | ''' 60 | pid = self._read_bytes(self._REG_PID, 1) 61 | vid = self._read_bytes(self._REG_VID, 1) 62 | if self.last_operate_status == self.STA_OK: 63 | if pid[0] != self._REG_DEF_PID: 64 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 65 | elif vid[0] != self._REG_DEF_VID: 66 | self.last_operate_status = self.STA_ERR_SOFT_VERSION 67 | else: 68 | self.set_pwm_disable() 69 | self.set_pwm_duty(self.ALL, 0) 70 | self.set_adc_disable() 71 | return self.last_operate_status 72 | 73 | def set_addr(self, addr): 74 | ''' 75 | @brief Set board controler address, reboot module to make it effective 76 | @param address: int Address to set, range in 1 to 127 77 | ''' 78 | if addr < 1 or addr > 127: 79 | self.last_operate_status = self.STA_ERR_PARAMETER 80 | return 81 | self._write_bytes(self._REG_SLAVE_ADDR, [addr]) 82 | 83 | def _parse_id(self, limit, id): 84 | ld = [] 85 | if isinstance(id, list) == False: 86 | id = id + 1 87 | ld.append(id) 88 | else: 89 | ld = [i + 1 for i in id] 90 | if ld == self.ALL: 91 | return range(1, limit + 1) 92 | for i in ld: 93 | if i < 1 or i > limit: 94 | self.last_operate_status = self.STA_ERR_PARAMETER 95 | return [] 96 | return ld 97 | 98 | def set_pwm_enable(self): 99 | ''' 100 | @brief Set pwm enable, pwm channel need external power 101 | ''' 102 | self._write_bytes(self._REG_PWM_CONTROL, [0x01]) 103 | if self.last_operate_status == self.STA_OK: 104 | self._is_pwm_enable = True 105 | time.sleep(0.01) 106 | 107 | def set_pwm_disable(self): 108 | ''' 109 | @brief Set pwm disable 110 | ''' 111 | self._write_bytes(self._REG_PWM_CONTROL, [0x00]) 112 | if self.last_operate_status == self.STA_OK: 113 | self._is_pwm_enable = False 114 | time.sleep(0.01) 115 | 116 | def set_pwm_frequency(self, freq): 117 | ''' 118 | @brief Set pwm frequency 119 | @param freq: int Frequency to set, in range 1 - 1000 120 | ''' 121 | if freq < 1 or freq > 1000: 122 | self.last_operate_status = self.STA_ERR_PARAMETER 123 | return 124 | is_pwm_enable = self._is_pwm_enable 125 | self.set_pwm_disable() 126 | self._write_bytes(self._REG_PWM_FREQ, [freq >> 8, freq & 0xff]) 127 | time.sleep(0.01) 128 | if is_pwm_enable: 129 | self.set_pwm_enable() 130 | 131 | def set_pwm_duty(self, chan, duty): 132 | ''' 133 | @brief Set selected channel duty 134 | @param chan: list One or more channels to set, items in range 1 to 4, or chan = self.ALL 135 | @param duty: float Duty to set, in range 0.0 to 100.0 136 | ''' 137 | if duty < 0 or duty > 100: 138 | self.last_operate_status = self.STA_ERR_PARAMETER 139 | return 140 | for i in self._parse_id(_PWM_CHAN_COUNT, chan): 141 | self._write_bytes(self._REG_PWM_DUTY1 + (i - 1) * 2, [int(duty), int((duty * 10) % 10)]) 142 | 143 | def set_adc_enable(self): 144 | ''' 145 | @brief Set adc enable 146 | ''' 147 | self._write_bytes(self._REG_ADC_CTRL, [0x01]) 148 | 149 | def set_adc_disable(self): 150 | ''' 151 | @brief Set adc disable 152 | ''' 153 | self._write_bytes(self._REG_ADC_CTRL, [0x00]) 154 | 155 | def get_adc_value(self, chan): 156 | ''' 157 | @brief Get adc value 158 | @param chan: int Channel to get, in range 1 to 4, or self.ALL 159 | @return :list List of value 160 | ''' 161 | for i in self._parse_id(_ADC_CHAN_COUNT, chan): 162 | rslt = self._read_bytes(self._REG_ADC_VAL1 + (i - 1) * 2, 2) 163 | return ((rslt[0] << 8) | rslt[1]) 164 | 165 | def detecte(self): 166 | ''' 167 | @brief If you forget address you had set, use this to detecte them, must have class instance 168 | @return Board list conformed 169 | ''' 170 | l = [] 171 | back = self._addr 172 | for i in range(1, 127): 173 | self._addr = i 174 | if self.begin() == self.STA_OK: 175 | l.append(i) 176 | for i in range(0, len(l)): 177 | l[i] = hex(l[i]) 178 | self._addr = back 179 | self.last_operate_status = self.STA_OK 180 | return l 181 | 182 | class DFRobot_Epansion_Board_Digital_RGB_LED(): 183 | 184 | def __init__(self, board): 185 | ''' 186 | @param board: DFRobot_Expansion_Board Board instance to operate digital rgb led, test LED: https://www.dfrobot.com/product-1829.html 187 | Warning: LED must connect to pwm channel, otherwise may destory Pi IO 188 | ''' 189 | self._board = board 190 | self._chan_r = 0 191 | self._chan_g = 0 192 | self._chan_b = 0 193 | 194 | def begin(self, chan_r, chan_g, chan_b): 195 | ''' 196 | @brief Set digital rgb led color channel, these parameters not repeat 197 | @param chan_r: int Set color red channel id, in range 1 to 4 198 | @param chan_g: int Set color green channel id, in range 1 to 4 199 | @param chan_b: int Set color blue channel id, in range 1 to 4 200 | ''' 201 | if chan_r == chan_g or chan_r == chan_b or chan_g == chan_b: 202 | return 203 | if chan_r < _PWM_CHAN_COUNT and chan_g < _PWM_CHAN_COUNT and chan_b < _PWM_CHAN_COUNT: 204 | self._chan_r = chan_r 205 | self._chan_g = chan_g 206 | self._chan_b = chan_b 207 | self._board.set_pwm_enable() 208 | self._board.set_pwm_frequency(1000) 209 | self._board.set_pwm_duty(self._board.ALL, 100) 210 | 211 | def color888(self, r, g, b): 212 | ''' 213 | @brief Set LED to true-color 214 | @param r: int Color components red 215 | @param g: int Color components green 216 | @param b: int Color components blue 217 | ''' 218 | self._board.set_pwm_duty([self._chan_r], 100 - (r & 0xff) * 100 // 255) 219 | self._board.set_pwm_duty([self._chan_g], 100 - (g & 0xff) * 100 // 255) 220 | self._board.set_pwm_duty([self._chan_b], 100 - (b & 0xff) * 100 // 255) 221 | 222 | def color24(self, color): 223 | ''' 224 | @brief Set LED to 24-bits color 225 | @param color: int 24-bits color 226 | ''' 227 | color &= 0xffffff 228 | self.color888(color >> 16, (color >> 8) & 0xff, color & 0xff) 229 | 230 | def color565(self, color): 231 | ''' 232 | @brief Set LED to 16-bits color 233 | @param color: int 16-bits color 234 | ''' 235 | color &= 0xffff 236 | self.color888((color & 0xf800) >> 8, (color & 0x7e0) >> 3, (color & 0x1f) << 3) 237 | 238 | class DFRobot_Expansion_Board_Servo(): 239 | 240 | def __init__(self, board): 241 | ''' 242 | @param board: DFRobot_Expansion_Board Board instance to operate servo, test servo: https://www.dfrobot.com/product-255.html 243 | Warning: servo must connect to pwm channel, otherwise may destory Pi IO 244 | ''' 245 | self._board = board 246 | 247 | def begin(self): 248 | ''' 249 | @brief Board servo begin 250 | ''' 251 | self._board.set_pwm_enable() 252 | self._board.set_pwm_frequency(50) 253 | self._board.set_pwm_duty(self._board.ALL, 0) 254 | 255 | def move(self, id, angle): 256 | ''' 257 | @brief Servos move 258 | @param id: list One or more servos to set, items in range 1 to 4, or chan = self.ALL 259 | @param angle: int Angle to move, in range 0 to 180 260 | ''' 261 | if 0 <= angle <= 180: 262 | self._board.set_pwm_duty(id, (0.5 + (float(angle) / 90.0)) / 20 * 100) 263 | 264 | import smbus 265 | 266 | class DFRobot_Expansion_Board_IIC(DFRobot_Expansion_Board): 267 | 268 | def __init__(self, bus_id, addr): 269 | ''' 270 | @param bus_id: int Which bus to operate 271 | @oaram addr: int Board controler address 272 | ''' 273 | self._bus = smbus.SMBus(bus_id) 274 | DFRobot_Expansion_Board.__init__(self, addr) 275 | 276 | def _write_bytes(self, reg, buf): 277 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 278 | try: 279 | self._bus.write_i2c_block_data(self._addr, reg, buf) 280 | self.last_operate_status = self.STA_OK 281 | except: 282 | pass 283 | 284 | def _read_bytes(self, reg, len): 285 | self.last_operate_status = self.STA_ERR_DEVICE_NOT_DETECTED 286 | try: 287 | rslt = self._bus.read_i2c_block_data(self._addr, reg, len) 288 | self.last_operate_status = self.STA_OK 289 | return rslt 290 | except: 291 | return [0] * len 292 | 293 | 294 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/DHT_22_DFR.py: -------------------------------------------------------------------------------- 1 | #pip3 install adafruit-circuitpython-dht 2 | #sudo apt-get install libgpiod2 3 | 4 | import time 5 | import adafruit_dht 6 | import board 7 | 8 | dht_device = adafruit_dht.DHT22(board.D4) 9 | 10 | while True: 11 | try: 12 | temperature_c = dht_device.temperature 13 | temperature_f = temperature_c * (9 / 5) + 32 14 | 15 | humidity = dht_device.humidity 16 | 17 | print("Temp:{:.1f} C / {:.1f} F Humidity: {}%".format(temperature_c, temperature_f, humidity)) 18 | except RuntimeError as err: 19 | print(err.args[0]) 20 | 21 | time.sleep(2.0) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/Firebase_data_logging.py: -------------------------------------------------------------------------------- 1 | # pip3 install Pyrebase 2 | from grovepi import * 3 | from grove_rgb_lcd import * 4 | import time 5 | from math import isnan 6 | from time import strftime 7 | import math 8 | import pyrebase 9 | 10 | dht_sensor_port = 7 11 | 12 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 13 | 14 | setRGB(0,255,0) 15 | 16 | config = { 17 | "apiKey": "AIzaSyBLCJBhKJ6Gi1HN3QkqTqvlklMfdf8vBL4", 18 | "authDomain": "diwakarrpi.firebaseapp.com", 19 | "databaseURL": "https://diwakarrpi-default-rtdb.firebaseio.com/", 20 | "storageBucket": "diwakarrpi.appspot.com" 21 | } 22 | 23 | firebase = pyrebase.initialize_app(config) 24 | 25 | db = firebase.database() 26 | 27 | 28 | 29 | 30 | while True: 31 | try: 32 | # Print the values to the serial port 33 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 34 | print(f"Temp:{t} C Humidity:{h}%") 35 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 36 | print(t) 37 | print(h) 38 | data = {"Temperature" : t,"Humidity" : h} 39 | db.child("Status").push(data) 40 | db.update(data) 41 | print("Sent to Firebase") 42 | 43 | except RuntimeError as error: 44 | # Errors happen fairly often, DHT's are hard to read, just keep going 45 | print(error.args[0]) 46 | time.sleep(2.0) 47 | continue 48 | except Exception as error: 49 | dhtDevice.exit() 50 | raise error 51 | 52 | time.sleep(2.0) 53 | 54 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/MQTT_PWM_Control.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | from grove_rgb_lcd import * 6 | import time 7 | led = 3 8 | dht_sensor_port = 7 9 | 10 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 11 | 12 | setRGB(0,255,0) 13 | pinMode(led,"OUTPUT") 14 | 15 | 16 | def on_connect(client, userdata, flags, rc): 17 | print("Connected to broker. Return of connection: "+str(rc)) 18 | client.subscribe("Motor") 19 | 20 | # Callback - when a message is received 21 | def on_message(client, userdata, msg): 22 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 23 | df=msg.payload.decode('utf-8') 24 | print(df) 25 | print(type(df)) 26 | df=int(df) 27 | # df3=df.decode() 28 | 29 | if (df == 100): 30 | analogWrite(led,df) 31 | return 0 32 | 33 | if (df == 50): 34 | analogWrite(led,df) 35 | return 0 36 | 37 | if (df == 10): 38 | analogWrite(led,df) 39 | return 0 40 | 41 | 42 | def on_publish(client, userdata, mid): 43 | print("mid: " + str(mid)) 44 | 45 | 46 | def on_subscribe(client, userdata, mid, granted_qos): 47 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 48 | 49 | #main progra6m 50 | 51 | client = mqtt.Client() 52 | client.on_connect = on_connect # configure callback (from when the connection$ 53 | client.on_message = on_message # set callback (from when a message is receive$ 54 | client.on_publish = on_publish 55 | client.on_subscribe = on_subscribe 56 | client.connect("test.mosquitto.org", 1883, 60) 57 | 58 | rc = 0 59 | while rc == 0: 60 | 61 | rc = client.loop() 62 | # Use read_retry method. This will retry up to 15 times to 63 | # get a sensor reading (waiting 2 seconds between each retry). 64 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 65 | print(f"Temp:{t} C Humidity:{h}%") 66 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 67 | # Reading the DHT11 is very sensitive to timings and occasionally 68 | # the Pi might fail to get a valid reading. So check if readings are valid. 69 | if h is not None and t is not None: 70 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 71 | client.publish("humidity",str(h)) 72 | client.publish("Temp",str(t)) 73 | time.sleep(1) 74 | 75 | else: 76 | print('Failed to get reading. Try again!') 77 | 78 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/MQTT_analog_data.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | from grove_rgb_lcd import * 6 | 7 | import time 8 | 9 | dht_sensor_port = 7 10 | 11 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 12 | 13 | setRGB(0,255,0) 14 | 15 | led = 8 16 | 17 | pinMode(led,"OUTPUT") 18 | 19 | 20 | def on_connect(client, userdata, flags, rc): 21 | print("Connected to broker. Return of connection: "+str(rc)) 22 | client.subscribe("MQTTLed") 23 | 24 | # Callback - when a message is received 25 | def on_message(client, userdata, msg): 26 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 27 | df=msg.payload.decode('utf-8') 28 | print(df) 29 | # df3=df.decode() 30 | 31 | if (df == "ONLED1"): 32 | digitalWrite(led,1) 33 | return 0 34 | 35 | if (df == "OFFLED1"): 36 | digitalWrite(led,0) 37 | return 0 38 | 39 | 40 | def on_publish(client, userdata, mid): 41 | print("mid: " + str(mid)) 42 | 43 | 44 | def on_subscribe(client, userdata, mid, granted_qos): 45 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 46 | 47 | #main progra6m 48 | 49 | client = mqtt.Client() 50 | client.on_connect = on_connect # configure callback (from when the connection$ 51 | client.on_message = on_message # set callback (from when a message is receive$ 52 | client.on_publish = on_publish 53 | client.on_subscribe = on_subscribe 54 | client.connect("test.mosquitto.org", 1883, 60) 55 | 56 | rc = 0 57 | while rc == 0: 58 | 59 | rc = client.loop() 60 | # Use read_retry method. This will retry up to 15 times to 61 | # get a sensor reading (waiting 2 seconds between each retry). 62 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 63 | print(f"Temp:{t} C Humidity:{h}%") 64 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 65 | # Reading the DHT11 is very sensitive to timings and occasionally 66 | # the Pi might fail to get a valid reading. So check if readings are valid. 67 | if h is not None and t is not None: 68 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 69 | client.publish("humidity",str(h)) 70 | client.publish("Temp",str(t)) 71 | time.sleep(1) 72 | 73 | else: 74 | print('Failed to get reading. Try again!') 75 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/MQTT_led_Control.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | import time 6 | led = 7 7 | pinMode(led,"OUTPUT") 8 | def on_connect(client, userdata, flags, rc): 9 | print("Connected to broker. Return of connection: "+str(rc)) 10 | client.subscribe("MQTTLed") 11 | 12 | # Callback - when a message is received 13 | def on_message(client, userdata, msg): 14 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 15 | df=msg.payload.decode('utf-8') 16 | print(df) 17 | if (df == "ONLED1"): 18 | digitalWrite(led,1) 19 | return 0 20 | 21 | if (df == "OFFLED1"): 22 | digitalWrite(led,0) 23 | return 0 24 | 25 | #main program 26 | client = mqtt.Client() 27 | client.on_connect = on_connect # configure callback (from when the connection$ 28 | client.on_message = on_message # set callback (from when a message is receive$ 29 | 30 | client.connect("test.mosquitto.org", 1883, 60) 31 | 32 | # Endless loop waiting to receive messages. . 33 | client.loop_forever() -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/4x4_Matrix_with_library.py: -------------------------------------------------------------------------------- 1 | #pip3 install pad4pi 2 | from pad4pi import rpi_gpio 3 | 4 | import time 5 | 6 | KEYPAD = [ 7 | 8 | [1, 2, 3, "A"], 9 | 10 | [4, 5, 6, "B"], 11 | 12 | [7, 8, 9, "C"], 13 | 14 | ["*", 0, "#", "D"] 15 | 16 | ] 17 | 18 | ROW_PINS = [17, 27, 22, 5] # BCM numbering 19 | 20 | COL_PINS = [23, 24, 25, 16] # BCM numbering 21 | 22 | def print_key(key): 23 | 24 | print(f"Received key from interrupt:: {key}") 25 | 26 | try: 27 | 28 | factory = rpi_gpio.KeypadFactory() 29 | 30 | keypad = factory.create_keypad(keypad=KEYPAD,row_pins=ROW_PINS, col_pins=COL_PINS) # makes assumptions about keypad layout and GPIO pin numbers 31 | 32 | keypad.registerKeyPressHandler(print_key) 33 | 34 | print("Press buttons on your keypad. Ctrl+C to exit.") 35 | 36 | while True: 37 | 38 | time.sleep(1) 39 | 40 | except KeyboardInterrupt: 41 | 42 | print("Goodbye") 43 | 44 | finally: 45 | 46 | keypad.cleanup() 47 | 48 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/4x4_matrix_Keyboard.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | """ 4 | R1=4 5 | R2=5 6 | R3=6 7 | R4=7 8 | C1=8 9 | C2=9 10 | C3=10 11 | C4=11 12 | """ 13 | """ 14 | R1=5 15 | R2=6 16 | R3=13 17 | R4=19 18 | C1=12 19 | C2=16 20 | C3=20 21 | C4=21 22 | """ 23 | R1=17 24 | R2=27 25 | R3=22 26 | R4=5 27 | C1=23 28 | C2=24 29 | C3=25 30 | C4=16 31 | 32 | GPIO.setmode(GPIO.BCM) 33 | GPIO.setup(R1,GPIO.OUT) 34 | GPIO.setup(R2,GPIO.OUT) 35 | GPIO.setup(R3,GPIO.OUT) 36 | GPIO.setup(R4,GPIO.OUT) 37 | 38 | GPIO.setup(C1,GPIO.IN) 39 | GPIO.setup(C2,GPIO.IN) 40 | GPIO.setup(C3,GPIO.IN) 41 | GPIO.setup(C4,GPIO.IN) 42 | 43 | 44 | 45 | def readLine(line, characters): 46 | 47 | GPIO.output(line,GPIO.HIGH) 48 | 49 | if(GPIO.input(C1) == 1): 50 | print(characters[0]) 51 | if(GPIO.input(C2) == 1): 52 | print(characters[1]) 53 | if(GPIO.input(C3) == 1): 54 | print(characters[2]) 55 | if(GPIO.input(C4) == 1): 56 | print(characters[3]) 57 | 58 | GPIO.output(line,GPIO.LOW) 59 | 60 | 61 | while True: 62 | 63 | readLine(R1, ["1","2","3","A"]) 64 | 65 | readLine(R2, ["4","5","6","B"]) 66 | 67 | readLine(R3, ["7","8","9","C"]) 68 | 69 | readLine(R4, ["*","0","#","D"]) 70 | 71 | time.sleep(0.1) 72 | 73 | 74 | 75 | print("\nApplication stopped!") 76 | 77 | 78 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/DHT_22_DFR.py: -------------------------------------------------------------------------------- 1 | #pip3 install adafruit-circuitpython-dht 2 | #sudo apt install gpiod 3 | ## Can check installed library using apt show libgpiod2 4 | import time 5 | import adafruit_dht 6 | import board 7 | 8 | dht_device = adafruit_dht.DHT22(board.D4) 9 | 10 | while True: 11 | try: 12 | temperature_c = dht_device.temperature 13 | temperature_f = temperature_c * (9 / 5) + 32 14 | 15 | humidity = dht_device.humidity 16 | 17 | print("Temp:{:.1f} C / {:.1f} F Humidity: {}%".format(temperature_c, temperature_f, humidity)) 18 | except RuntimeError as err: 19 | print(err.args[0]) 20 | 21 | time.sleep(2.0) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/Motion_Detection_PIR.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | # pir at BCM port 23 5 | # PIR sensitivity (detect range) can be tuned by adjusting the 6 | # screw on the right side of the buuzzer 7 | pir_gpio = 23 8 | LED=12 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(pir_gpio, GPIO.IN) 11 | GPIO.setup(LED,GPIO.OUT) 12 | def no_motion(): 13 | print("Nothing moves …") 14 | GPIO.output(LED,GPIO.LOW) 15 | 16 | def motion_detected(): 17 | print("Motion detected at "+str(time.ctime())) 18 | GPIO.output(LED,GPIO.HIGH) 19 | 20 | try: 21 | while True: 22 | GPIO.output(LED,GPIO.LOW) 23 | if(GPIO.input(pir_gpio) == 0): 24 | no_motion() 25 | elif(GPIO.input(pir_gpio) == 1): 26 | motion_detected() 27 | time.sleep(0.1) 28 | except KeyboardInterrupt: 29 | print('interrupted!') 30 | GPIO.cleanup() -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/Rain_water_sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 4 | 5 | 6 | while board.begin() != board.STA_OK: # Board begin and check board status 7 | print_board_status() 8 | print("board begin faild") 9 | time.sleep(2) 10 | print("board begin success") 11 | 12 | board.set_adc_enable() 13 | 14 | while True: 15 | val = board.get_adc_value(board.A0) # A0 channels read 16 | #val = board.get_adc_value(board.A1) # A1 channels read 17 | #val = board.get_adc_value(board.A2) # A2 channels read 18 | #val = board.get_adc_value(board.A3) # A3 channels read 19 | # print("channel: A0, value: %d" %val) 20 | print("") 21 | if (val<1900): 22 | print("Rain Started") 23 | else: 24 | print("No Rain") 25 | 26 | time.sleep(2) 27 | 28 | 29 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/Resistive_Soil_Moisture_Sensor.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | 3 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 4 | 5 | 6 | while board.begin() != board.STA_OK: # Board begin and check board status 7 | print_board_status() 8 | print("board begin faild") 9 | time.sleep(2) 10 | print("board begin success") 11 | 12 | board.set_adc_enable() 13 | 14 | while True: 15 | val = board.get_adc_value(board.A0) # A0 channels read 16 | #val = board.get_adc_value(board.A1) # A1 channels read 17 | #val = board.get_adc_value(board.A2) # A2 channels read 18 | #val = board.get_adc_value(board.A3) # A3 channels read 19 | print("channel: A0, value: %d" %val) 20 | print("") 21 | 22 | 23 | time.sleep(2) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/Servo_Motor_Interfacing.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | from dfadc import * 3 | import time 4 | import atexit 5 | atexit.register(GPIO.cleanup) 6 | #GPIO.cleanup() 7 | board_detect() # If you forget address you had set, use this to detected them, must have class instance 8 | 9 | # Set board controler address, use it carefully, reboot module to make it effective 10 | 11 | while board.begin() != board.STA_OK:# Board begin and check board status 12 | print_board_status() 13 | print("board begin faild") 14 | time.sleep(2) 15 | print("board begin success") 16 | 17 | board.set_pwm_enable() # Pwm channel need external power 18 | board.set_pwm_frequency(50) 19 | board.set_pwm_duty(0,0) 20 | time.sleep(1) 21 | """ 22 | for duty in range(2,17,2): 23 | board.set_pwm_duty(0,duty) 24 | time.sleep(2) 25 | """ 26 | while True: 27 | board.set_pwm_duty(0,2) 28 | time.sleep(2) 29 | board.set_pwm_duty(0,15) 30 | time.sleep(2) 31 | # board.set_pwm_duty(0,7.0) 32 | # time.sleep(2) 33 | """ 34 | duty=2 35 | while duty<=17: 36 | board.set_pwm_duty(0,duty) 37 | time.sleep(2) 38 | duty=duty+1 39 | 40 | board.set_pwm_duty(0,2) 41 | board.set_pwm_duty(0,0) 42 | """ 43 | #GPIO.cleanup() -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/Stepper_motor_interface.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import RPi.GPIO as GPIO 3 | import time 4 | 5 | in1 = 17 6 | in2 = 18 7 | in3 = 27 8 | in4 = 22 9 | 10 | # careful lowering this, at some point you run into the mechanical limitation of how quick your motor can move 11 | step_sleep = 0.002 12 | 13 | step_count = 4096 # 5.625*(1/64) per step, 4096 steps is 360° 14 | 15 | direction = True # True for clockwise, False for counter-clockwise 16 | 17 | # defining stepper motor sequence (found in documentation http://www.4tronix.co.uk/arduino/Stepper-Motors.php) 18 | step_sequence = [[1,0,0,1], 19 | [1,0,0,0], 20 | [1,1,0,0], 21 | [0,1,0,0], 22 | [0,1,1,0], 23 | [0,0,1,0], 24 | [0,0,1,1], 25 | [0,0,0,1]] 26 | 27 | # setting up 28 | GPIO.setmode( GPIO.BCM ) 29 | GPIO.setup( in1, GPIO.OUT ) 30 | GPIO.setup( in2, GPIO.OUT ) 31 | GPIO.setup( in3, GPIO.OUT ) 32 | GPIO.setup( in4, GPIO.OUT ) 33 | 34 | # initializing 35 | GPIO.output( in1, GPIO.LOW ) 36 | GPIO.output( in2, GPIO.LOW ) 37 | GPIO.output( in3, GPIO.LOW ) 38 | GPIO.output( in4, GPIO.LOW ) 39 | 40 | motor_pins = [in1,in2,in3,in4] 41 | motor_step_counter = 0 ; 42 | 43 | def cleanup(): 44 | GPIO.output( in1, GPIO.LOW ) 45 | GPIO.output( in2, GPIO.LOW ) 46 | GPIO.output( in3, GPIO.LOW ) 47 | GPIO.output( in4, GPIO.LOW ) 48 | GPIO.cleanup() 49 | 50 | while True: 51 | 52 | try: 53 | direction = not direction 54 | i = 0 55 | for i in range(step_count): 56 | for pin in range(0, len(motor_pins)): 57 | GPIO.output( motor_pins[pin], step_sequence[motor_step_counter][pin] ) 58 | if direction==True: 59 | motor_step_counter = (motor_step_counter - 1) % 8 60 | elif direction==False: 61 | motor_step_counter = (motor_step_counter + 1) % 8 62 | else: # defensive programming 63 | print( "uh oh... direction should *always* be either True or False" ) 64 | cleanup() 65 | exit( 1 ) 66 | time.sleep( step_sleep ) 67 | 68 | except KeyboardInterrupt: 69 | cleanup() 70 | exit( 1 ) 71 | 72 | cleanup() 73 | exit( 0 ) -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/dfadc.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board 4 | 5 | board = Board(1, 0x10) # Select i2c bus 1, set address to 0x10 6 | 7 | def board_detect(): 8 | l = board.detecte() 9 | print("Board list conform:") 10 | print(l) 11 | 12 | ''' print last operate status, users can use this variable to determine the result of a function call. ''' 13 | def print_board_status(): 14 | if board.last_operate_status == board.STA_OK: 15 | print("board status: everything ok") 16 | elif board.last_operate_status == board.STA_ERR: 17 | print("board status: unexpected error") 18 | elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED: 19 | print("board status: device not detected") 20 | elif board.last_operate_status == board.STA_ERR_PARAMETER: 21 | print("board status: parameter error") 22 | elif board.last_operate_status == board.STA_ERR_SOFT_VERSION: 23 | print("board status: unsupport board framware version") 24 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/lcddf.py: -------------------------------------------------------------------------------- 1 | import time,sys 2 | 3 | if sys.platform == 'uwp': 4 | import winrt_smbus as smbus 5 | bus = smbus.SMBus(1) 6 | else: 7 | import smbus 8 | import RPi.GPIO as GPIO 9 | rev = GPIO.RPI_REVISION 10 | if rev == 2 or rev == 3: 11 | bus = smbus.SMBus(1) 12 | else: 13 | bus = smbus.SMBus(0) 14 | 15 | # this device has two I2C addresses 16 | DISPLAY_RGB_ADDR = 0x2d 17 | DISPLAY_TEXT_ADDR = 0x3e 18 | 19 | # set backlight to (R,G,B) (values from 0..255 for each) 20 | def setRGB(r,g,b): 21 | bus.write_byte_data(DISPLAY_RGB_ADDR,0,0) 22 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,0) 23 | bus.write_byte_data(DISPLAY_RGB_ADDR,0x08,0xaa) 24 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,r) 25 | bus.write_byte_data(DISPLAY_RGB_ADDR,2,g) 26 | bus.write_byte_data(DISPLAY_RGB_ADDR,3,b) 27 | 28 | # send command to display (no need for external use) 29 | def textCommand(cmd): 30 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd) 31 | 32 | # set display text \n for second line(or auto wrap) 33 | def setText(text): 34 | textCommand(0x01) # clear display 35 | time.sleep(.05) 36 | textCommand(0x08 | 0x04) # display on, no cursor 37 | textCommand(0x28) # 2 lines 38 | time.sleep(.05) 39 | count = 0 40 | row = 0 41 | for c in text: 42 | if c == '\n' or count == 16: 43 | count = 0 44 | row += 1 45 | if row == 2: 46 | break 47 | textCommand(0xc0) 48 | if c == '\n': 49 | continue 50 | count += 1 51 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 52 | 53 | #Update the display without erasing the display 54 | def setText_norefresh(text): 55 | textCommand(0x02) # return home 56 | time.sleep(.05) 57 | textCommand(0x08 | 0x04) # display on, no cursor 58 | textCommand(0x28) # 2 lines 59 | time.sleep(.05) 60 | count = 0 61 | row = 0 62 | while len(text) < 32: #clears the rest of the screen 63 | text += ' ' 64 | for c in text: 65 | if c == '\n' or count == 16: 66 | count = 0 67 | row += 1 68 | if row == 2: 69 | break 70 | textCommand(0xc0) 71 | if c == '\n': 72 | continue 73 | count += 1 74 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 75 | 76 | # Create a custom character (from array of row patterns) 77 | def create_char(location, pattern): 78 | """ 79 | Writes a bit pattern to LCD CGRAM 80 | 81 | Arguments: 82 | location -- integer, one of 8 slots (0-7) 83 | pattern -- byte array containing the bit pattern, like as found at 84 | https://omerk.github.io/lcdchargen/ 85 | """ 86 | location &= 0x07 # Make sure location is 0-7 87 | textCommand(0x40 | (location << 3)) 88 | bus.write_i2c_block_data(DISPLAY_TEXT_ADDR, 0x40, pattern) 89 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/mq135_usage2.py: -------------------------------------------------------------------------------- 1 | from mq135_interface import * 2 | import sys, time 3 | 4 | #filename = "mq_sensors_log.csv" 5 | 6 | # Create header row in new CSV file 7 | #csv = open(filename, 'w') 8 | #csv.write("Timestamp,Raw_value_MQ135, \n") 9 | #csv.close 10 | 11 | #mq135 = MQ135() 12 | #now_time = time.time() 13 | 14 | while True: 15 | 16 | mq135 = MQ135() 17 | now_time = time.time() 18 | 19 | perc135 = mq135.MQPercentage() 20 | 21 | print("MQ135 measurment") 22 | sys.stdout.write("\r") 23 | sys.stdout.write("\033[K") 24 | sys.stdout.write("Raw_value: %g, \nACETON: %g ppm, \nTOLUENO: %g ppm, \nALCOHOL: %g ppm, \nCO2: %g ppm, \nNH4: %g ppm, \nCO: %g ppm" % (perc135["RAW_VALUE"], perc135["ACETON"], perc135["TOLUENO"], perc135["ALCOHOL"], perc135["CO2"], perc135["NH4"], perc135["CO"])) 25 | sys.stdout.flush() 26 | print("\n\n") 27 | 28 | # Write values to csv file 29 | entry = str(round((time.time() - now_time) / 60)) 30 | entry = entry + "," + str(perc135["RAW_VALUE"]) + "\n" 31 | 32 | # Log (append) entry into file 33 | # csv = open(filename, 'a') 34 | # try: 35 | # csv.write(entry) 36 | # finally: 37 | # csv.close() 38 | 39 | time.sleep(2) 40 | 41 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/New Sensors/servo_GPIO.py: -------------------------------------------------------------------------------- 1 | # Raspberry Pi + MG90S Servo PWM Control Python Code 2 | # 3 | # 4 | import RPi.GPIO as GPIO 5 | import time 6 | 7 | # setup the GPIO pin for the servo 8 | servo_pin = 13 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(servo_pin,GPIO.OUT) 11 | 12 | # setup PWM process 13 | pwm = GPIO.PWM(servo_pin,50) # 50 Hz (20 ms PWM period) 14 | 15 | pwm.start(7) # start PWM by rotating to 90 degrees 16 | 17 | 18 | while True: 19 | pwm.ChangeDutyCycle(2.0) # rotate to 0 degrees 20 | time.sleep(0.5) 21 | pwm.ChangeDutyCycle(12.0) # rotate to 180 degrees 22 | time.sleep(0.5) 23 | pwm.ChangeDutyCycle(7.0) # rotate to 90 degrees 24 | time.sleep(0.5) 25 | 26 | 27 | pwm.ChangeDutyCycle(0) # this prevents jitter 28 | pwm.stop() # stops the pwm on 13 29 | GPIO.cleanup() # good practice when finished using a pin """ -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/Sound_sensor_interface.py: -------------------------------------------------------------------------------- 1 | import time 2 | import grovepi 3 | from grove_rgb_lcd import * 4 | # Connect the Grove Sound Sensor to analog port A0 5 | # SIG,NC,VCC,GND 6 | sound_sensor = 0 7 | 8 | # Connect the Grove LED to digital port D5 9 | # SIG,NC,VCC,GND 10 | led = 5 11 | 12 | grovepi.pinMode(sound_sensor,"INPUT") 13 | grovepi.pinMode(led,"OUTPUT") 14 | 15 | # The threshold to turn the led on 400.00 * 5 / 1024 = 1.95v 16 | threshold_value = 600 17 | 18 | while True: 19 | try: 20 | # Read the sound level 21 | sensor_value = grovepi.analogRead(sound_sensor) 22 | print(sensor_value) 23 | setRGB(sensor_value//2,sensor_value//2,sensor_value//2) 24 | 25 | # If loud, illuminate LED, otherwise dim 26 | if sensor_value > threshold_value: 27 | grovepi.digitalWrite(led,1) 28 | else: 29 | grovepi.digitalWrite(led,0) 30 | 31 | print("sensor_value = %d" %sensor_value) 32 | time.sleep(.5) 33 | 34 | except IOError: 35 | print ("Error") 36 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/Telegram_grovepi.py: -------------------------------------------------------------------------------- 1 | # pip3 install telepot 2 | import time, datetime 3 | 4 | import telepot 5 | 6 | from telepot.loop import MessageLoop 7 | 8 | from grovepi import * 9 | 10 | led = 2 #connect led grovepi module on D2 11 | 12 | now = datetime.datetime.now() 13 | 14 | #LED White 15 | 16 | pinMode(led,"OUTPUT") 17 | 18 | time.sleep(1) 19 | 20 | digitalWrite(led,0) #Off initially 21 | 22 | 23 | 24 | def action(msg): 25 | 26 | chat_id = msg['chat']['id'] 27 | 28 | command = msg['text'] 29 | 30 | print ('Received: %s' % command) 31 | 32 | if 'on' in command: 33 | 34 | message = "Turned on " 35 | 36 | if 'led' in command: 37 | 38 | message = message + "led " 39 | 40 | digitalWrite(led,1) 41 | 42 | 43 | 44 | if 'all' in command: 45 | 46 | message = message + "all " 47 | 48 | digitalWrite(led,1) 49 | 50 | 51 | 52 | message = message + "light(s)" 53 | 54 | telegram_bot.sendMessage (chat_id, message) 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | if 'off' in command: 63 | 64 | message = "Turned off " 65 | 66 | if 'led' in command: 67 | 68 | message = message + "led " 69 | 70 | digitalWrite(led,0) 71 | 72 | 73 | 74 | if 'all' in command: 75 | 76 | message = message + "all " 77 | 78 | digitalWrite(led,0) 79 | 80 | 81 | 82 | message = message + "light(s)" 83 | 84 | telegram_bot.sendMessage (chat_id, message) 85 | 86 | 87 | 88 | telegram_bot = telepot.Bot('6348232837:AAFdpKqwUkxmNnMi1ApBYwO54toVCPn0y6U') #use telegram access key API from telegram app of mobile 89 | 90 | print (telegram_bot.getMe()) 91 | 92 | MessageLoop(telegram_bot, action).run_as_thread() 93 | 94 | print ('Up and Running....') 95 | 96 | 97 | 98 | while 1: 99 | 100 | time.sleep(10) 101 | 102 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/dfadc.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board 4 | 5 | board = Board(1, 0x10) # Select i2c bus 1, set address to 0x10 6 | 7 | def board_detect(): 8 | l = board.detecte() 9 | print("Board list conform:") 10 | print(l) 11 | 12 | ''' print last operate status, users can use this variable to determine the result of a function call. ''' 13 | def print_board_status(): 14 | if board.last_operate_status == board.STA_OK: 15 | print("board status: everything ok") 16 | elif board.last_operate_status == board.STA_ERR: 17 | print("board status: unexpected error") 18 | elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED: 19 | print("board status: device not detected") 20 | elif board.last_operate_status == board.STA_ERR_PARAMETER: 21 | print("board status: parameter error") 22 | elif board.last_operate_status == board.STA_ERR_SOFT_VERSION: 23 | print("board status: unsupport board framware version") 24 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/lcddf.py: -------------------------------------------------------------------------------- 1 | import time,sys 2 | 3 | if sys.platform == 'uwp': 4 | import winrt_smbus as smbus 5 | bus = smbus.SMBus(1) 6 | else: 7 | import smbus 8 | import RPi.GPIO as GPIO 9 | rev = GPIO.RPI_REVISION 10 | if rev == 2 or rev == 3: 11 | bus = smbus.SMBus(1) 12 | else: 13 | bus = smbus.SMBus(0) 14 | 15 | # this device has two I2C addresses 16 | DISPLAY_RGB_ADDR = 0x2d 17 | DISPLAY_TEXT_ADDR = 0x3e 18 | 19 | # set backlight to (R,G,B) (values from 0..255 for each) 20 | def setRGB(r,g,b): 21 | bus.write_byte_data(DISPLAY_RGB_ADDR,0,0) 22 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,0) 23 | bus.write_byte_data(DISPLAY_RGB_ADDR,0x08,0xaa) 24 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,r) 25 | bus.write_byte_data(DISPLAY_RGB_ADDR,2,g) 26 | bus.write_byte_data(DISPLAY_RGB_ADDR,3,b) 27 | 28 | # send command to display (no need for external use) 29 | def textCommand(cmd): 30 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd) 31 | 32 | # set display text \n for second line(or auto wrap) 33 | def setText(text): 34 | textCommand(0x01) # clear display 35 | time.sleep(.05) 36 | textCommand(0x08 | 0x04) # display on, no cursor 37 | textCommand(0x28) # 2 lines 38 | time.sleep(.05) 39 | count = 0 40 | row = 0 41 | for c in text: 42 | if c == '\n' or count == 16: 43 | count = 0 44 | row += 1 45 | if row == 2: 46 | break 47 | textCommand(0xc0) 48 | if c == '\n': 49 | continue 50 | count += 1 51 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 52 | 53 | #Update the display without erasing the display 54 | def setText_norefresh(text): 55 | textCommand(0x02) # return home 56 | time.sleep(.05) 57 | textCommand(0x08 | 0x04) # display on, no cursor 58 | textCommand(0x28) # 2 lines 59 | time.sleep(.05) 60 | count = 0 61 | row = 0 62 | while len(text) < 32: #clears the rest of the screen 63 | text += ' ' 64 | for c in text: 65 | if c == '\n' or count == 16: 66 | count = 0 67 | row += 1 68 | if row == 2: 69 | break 70 | textCommand(0xc0) 71 | if c == '\n': 72 | continue 73 | count += 1 74 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 75 | 76 | # Create a custom character (from array of row patterns) 77 | def create_char(location, pattern): 78 | """ 79 | Writes a bit pattern to LCD CGRAM 80 | 81 | Arguments: 82 | location -- integer, one of 8 slots (0-7) 83 | pattern -- byte array containing the bit pattern, like as found at 84 | https://omerk.github.io/lcdchargen/ 85 | """ 86 | location &= 0x07 # Make sure location is 0-7 87 | textCommand(0x40 | (location << 3)) 88 | bus.write_i2c_block_data(DISPLAY_TEXT_ADDR, 0x40, pattern) 89 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/mq135_usage2.py: -------------------------------------------------------------------------------- 1 | from mq135_interface import * 2 | import sys, time 3 | 4 | #filename = "mq_sensors_log.csv" 5 | 6 | # Create header row in new CSV file 7 | #csv = open(filename, 'w') 8 | #csv.write("Timestamp,Raw_value_MQ135, \n") 9 | #csv.close 10 | 11 | #mq135 = MQ135() 12 | #now_time = time.time() 13 | 14 | while True: 15 | 16 | mq135 = MQ135() 17 | now_time = time.time() 18 | 19 | perc135 = mq135.MQPercentage() 20 | 21 | print("MQ135 measurment") 22 | sys.stdout.write("\r") 23 | sys.stdout.write("\033[K") 24 | sys.stdout.write("Raw_value: %g, \nACETON: %g ppm, \nTOLUENO: %g ppm, \nALCOHOL: %g ppm, \nCO2: %g ppm, \nNH4: %g ppm, \nCO: %g ppm" % (perc135["RAW_VALUE"], perc135["ACETON"], perc135["TOLUENO"], perc135["ALCOHOL"], perc135["CO2"], perc135["NH4"], perc135["CO"])) 25 | sys.stdout.flush() 26 | print("\n\n") 27 | 28 | # Write values to csv file 29 | entry = str(round((time.time() - now_time) / 60)) 30 | entry = entry + "," + str(perc135["RAW_VALUE"]) + "\n" 31 | 32 | # Log (append) entry into file 33 | # csv = open(filename, 'a') 34 | # try: 35 | # csv.write(entry) 36 | # finally: 37 | # csv.close() 38 | 39 | time.sleep(2) 40 | 41 | -------------------------------------------------------------------------------- /Module-2/Unit-3/GrovePI_Codes/thingspeak_grovepi.py: -------------------------------------------------------------------------------- 1 | #pip3 install thingspeak 2 | 3 | import thingspeak 4 | 5 | import time 6 | 7 | from grovepi import * 8 | 9 | dht_sensor_port = 7 10 | 11 | dht_sensor_type = 0 12 | 13 | channel_id = '2224094' 14 | 15 | write_key = 'IN6UY2EWBYPP1173' # PUT YOUR WRITE KEY HERE 16 | 17 | 18 | # PUT YOUR WRITE KEY HERE 19 | 20 | 21 | def measure(channel): 22 | 23 | try: 24 | 25 | [ t,h ] = dht(dht_sensor_port,dht_sensor_type) 26 | 27 | response = channel.update({'field1': t, 'field2': h}) 28 | 29 | print(f"Temp:{t} C Humidity:{h}%") 30 | 31 | except: 32 | 33 | print("connection failed") 34 | 35 | 36 | 37 | channel = thingspeak.Channel(id=channel_id,api_key=write_key) 38 | 39 | while True: 40 | 41 | measure(channel) # free account has an api limit of 15sec 42 | 43 | time.sleep(15) -------------------------------------------------------------------------------- /Module-2/Unit-3/Lab 1 - Classroom Exercise_Digital_Sensor_Interfacing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-3/Lab 1 - Classroom Exercise_Digital_Sensor_Interfacing.pdf -------------------------------------------------------------------------------- /Module-2/Unit-3/Lab 2 - Classroom Exercise_Analog_Sensor_Interfacing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-3/Lab 2 - Classroom Exercise_Analog_Sensor_Interfacing.pdf -------------------------------------------------------------------------------- /Module-2/Unit-3/Lab 3 - Classroom Exercise_PWM_Interfacing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-3/Lab 3 - Classroom Exercise_PWM_Interfacing.pdf -------------------------------------------------------------------------------- /Module-2/Unit-3/Lab 4 - Classroom Exercise_I2C_Interfacing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-3/Lab 4 - Classroom Exercise_I2C_Interfacing.pdf -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/22_Thingspeak_cloud.py: -------------------------------------------------------------------------------- 1 | from dfadc import * 2 | import thingspeak 3 | import time 4 | board_detect() 5 | channel_id = '2465172' 6 | write_key = 'VJMU8L2I7EWO13LK' # PUT YOUR WRITE KEY HERE 7 | while board.begin() != board.STA_OK: 8 | print_board_status() 9 | print("board begin faild") 10 | time.sleep(2) 11 | print("board begin success") 12 | 13 | board.set_adc_enable() 14 | channel = thingspeak.Channel(id=channel_id,api_key=write_key) 15 | while True: 16 | temp = board.get_adc_value(board.A0) # A0 channels read 17 | humidity = board.get_adc_value(board.A1) 18 | temperature = (temp/4096)* 100+20 19 | humid = (humidity/4096)* 100 20 | # print("Temperature = %d C" %Temperature) 21 | # val=val/4096*100 22 | print(temperature) 23 | print(humid) 24 | response = channel.update({'field1': temperature, 'field2': humid}) 25 | 26 | time.sleep(2) 27 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/DFRobot_firebase.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import atexit 4 | from dfadc import * 5 | board_detect() 6 | while board.begin() != board.STA_OK: 7 | print_board_status() 8 | print("board begin faild") 9 | time.sleep(2) 10 | print("board begin success") 11 | board.set_adc_enable() 12 | 13 | atexit.register(GPIO.cleanup) 14 | GPIO.setmode(GPIO.BCM) 15 | from time import sleep 16 | from math import isnan 17 | from time import strftime 18 | from firebase import firebase 19 | import math 20 | 21 | 22 | firebase= firebase.FirebaseApplication('https://diwakartest1-cc222-default-rtdb.firebaseio.com/') 23 | while True: 24 | # get the temperature and Humidity from the DHT sensor 25 | temp = board.get_adc_value(board.A0) # A0 channels read 26 | humidity = board.get_adc_value(board.A1) 27 | temperature = (temp/4096)* 100+20 28 | humidity = (humidity/4096)* 100 29 | location="Jaipur" 30 | time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) #reads the machine time 31 | t = str(temperature) 32 | h = str(humidity) 33 | data={"Location":location,"time_stamp":time_stamp,"Temperature":temperature,"Humidity":humidity} 34 | print(data) 35 | result=firebase.post('Weather Station', data) 36 | print(result) 37 | sleep(0.5) -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/RPiFireBaseDHT_working.py: -------------------------------------------------------------------------------- 1 | # 2022 Adesola Samuel 2 | import RPi.GPIO as GPIO 3 | import time 4 | import atexit 5 | from dfadc import * 6 | board_detect() 7 | while board.begin() != board.STA_OK: 8 | print_board_status() 9 | print("board begin faild") 10 | time.sleep(2) 11 | print("board begin success") 12 | board.set_adc_enable() 13 | 14 | atexit.register(GPIO.cleanup) 15 | GPIO.setmode(GPIO.BCM) 16 | from time import sleep 17 | from math import isnan 18 | from time import strftime 19 | import math 20 | import pyrebase 21 | 22 | config = { 23 | "apiKey": "AIzaSyBLCJBhKJ6Gi1HN3QkqTqvlklMfdf8vBL4", 24 | "authDomain": "diwakarrpi.firebaseapp.com", 25 | "databaseURL": "https://diwakarrpi-default-rtdb.firebaseio.com/", 26 | "storageBucket": "diwakarrpi.appspot.com" 27 | } 28 | 29 | firebase = pyrebase.initialize_app(config) 30 | 31 | db = firebase.database() 32 | 33 | 34 | 35 | 36 | while True: 37 | try: 38 | # Print the values to the serial port 39 | temp = board.get_adc_value(board.A0) # A0 channels read 40 | humidity = board.get_adc_value(board.A1) 41 | temperature = (temp/4096)* 100+20 42 | humidity = (humidity/4096)* 100 43 | print(temperature) 44 | print(humidity) 45 | data = {"Temperature" : temperature,"Humidity" : humidity} 46 | db.child("Status").push(data) 47 | db.update(data) 48 | print("Sent to Firebase") 49 | 50 | except RuntimeError as error: 51 | # Errors happen fairly often, DHT's are hard to read, just keep going 52 | print(error.args[0]) 53 | time.sleep(2.0) 54 | continue 55 | except Exception as error: 56 | dhtDevice.exit() 57 | raise error 58 | 59 | time.sleep(2.0) 60 | 61 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/autotweetDFRobot.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | import RPi.GPIO as GPIO 3 | import time 4 | import atexit 5 | from dfadc import * 6 | board_detect() 7 | while board.begin() != board.STA_OK: 8 | print_board_status() 9 | print("board begin faild") 10 | time.sleep(2) 11 | print("board begin success") 12 | board.set_adc_enable() 13 | 14 | atexit.register(GPIO.cleanup) 15 | GPIO.setmode(GPIO.BCM) 16 | from time import sleep 17 | from math import isnan 18 | from time import strftime 19 | import math 20 | 21 | consumer_key = '2IWlVt3Px1GtUfM7T6n1thTGC' 22 | consumer_secret = 'YasyTDfoMXRakvxLWLtyVXatC98T8lTIXdy96kiZyT7ClgXGad' 23 | access_token = '1043489874559397888-Ok5ZP06n6kaPIHHrgSk41fIhJPfArK' 24 | access_token_secret = 'gFmwTsr9lH7b5v8t8BR8mTpDwyJ7M7GttYMu4UL4zm6cz' 25 | 26 | client = tweepy.Client(consumer_key=consumer_key,consumer_secret=consumer_secret,access_token=access_token,access_token_secret=access_token_secret) 27 | 28 | location="Jaipur" 29 | #time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 30 | #print(time_stamp) 31 | 32 | while True: 33 | # Print the values to the serial port 34 | temp = board.get_adc_value(board.A0) # A0 channels read 35 | humidity = board.get_adc_value(board.A1) 36 | temperature = (temp/4096)* 100+20 37 | humidity = (humidity/4096)* 100 38 | print(temperature) 39 | print(humidity) 40 | time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 41 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 42 | sd='Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity) 43 | sd=time_stamp+" "+sd 44 | print(sd) 45 | client.create_tweet(text=sd) 46 | print("Sent to Twitter") 47 | time.sleep(5.0) -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/dfadc.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board 4 | 5 | board = Board(1, 0x10) # Select i2c bus 1, set address to 0x10 6 | 7 | def board_detect(): 8 | l = board.detecte() 9 | print("Board list conform:") 10 | print(l) 11 | 12 | ''' print last operate status, users can use this variable to determine the result of a function call. ''' 13 | def print_board_status(): 14 | if board.last_operate_status == board.STA_OK: 15 | print("board status: everything ok") 16 | elif board.last_operate_status == board.STA_ERR: 17 | print("board status: unexpected error") 18 | elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED: 19 | print("board status: device not detected") 20 | elif board.last_operate_status == board.STA_ERR_PARAMETER: 21 | print("board status: parameter error") 22 | elif board.last_operate_status == board.STA_ERR_SOFT_VERSION: 23 | print("board status: unsupport board framware version") 24 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/lcddf.py: -------------------------------------------------------------------------------- 1 | import time,sys 2 | 3 | if sys.platform == 'uwp': 4 | import winrt_smbus as smbus 5 | bus = smbus.SMBus(1) 6 | else: 7 | import smbus 8 | import RPi.GPIO as GPIO 9 | rev = GPIO.RPI_REVISION 10 | if rev == 2 or rev == 3: 11 | bus = smbus.SMBus(1) 12 | else: 13 | bus = smbus.SMBus(0) 14 | 15 | # this device has two I2C addresses 16 | DISPLAY_RGB_ADDR = 0x2d 17 | DISPLAY_TEXT_ADDR = 0x3e 18 | 19 | # set backlight to (R,G,B) (values from 0..255 for each) 20 | def setRGB(r,g,b): 21 | bus.write_byte_data(DISPLAY_RGB_ADDR,0,0) 22 | bus.write_byte_data(DISPLAY_RGB_ADDR,1,0) 23 | bus.write_byte_data(DISPLAY_RGB_ADDR,0x08,0xaa) 24 | bus.write_byte_data(DISPLAY_RGB_ADDR,4,r) 25 | bus.write_byte_data(DISPLAY_RGB_ADDR,3,g) 26 | bus.write_byte_data(DISPLAY_RGB_ADDR,2,b) 27 | 28 | # send command to display (no need for external use) 29 | def textCommand(cmd): 30 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x80,cmd) 31 | 32 | # set display text \n for second line(or auto wrap) 33 | def setText(text): 34 | textCommand(0x01) # clear display 35 | time.sleep(.05) 36 | textCommand(0x08 | 0x04) # display on, no cursor 37 | textCommand(0x28) # 2 lines 38 | time.sleep(.05) 39 | count = 0 40 | row = 0 41 | for c in text: 42 | if c == '\n' or count == 16: 43 | count = 0 44 | row += 1 45 | if row == 2: 46 | break 47 | textCommand(0xc0) 48 | if c == '\n': 49 | continue 50 | count += 1 51 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 52 | 53 | #Update the display without erasing the display 54 | def setText_norefresh(text): 55 | textCommand(0x02) # return home 56 | time.sleep(.05) 57 | textCommand(0x08 | 0x04) # display on, no cursor 58 | textCommand(0x28) # 2 lines 59 | time.sleep(.05) 60 | count = 0 61 | row = 0 62 | while len(text) < 32: #clears the rest of the screen 63 | text += ' ' 64 | for c in text: 65 | if c == '\n' or count == 16: 66 | count = 0 67 | row += 1 68 | if row == 2: 69 | break 70 | textCommand(0xc0) 71 | if c == '\n': 72 | continue 73 | count += 1 74 | bus.write_byte_data(DISPLAY_TEXT_ADDR,0x40,ord(c)) 75 | 76 | # Create a custom character (from array of row patterns) 77 | def create_char(location, pattern): 78 | """ 79 | Writes a bit pattern to LCD CGRAM 80 | 81 | Arguments: 82 | location -- integer, one of 8 slots (0-7) 83 | pattern -- byte array containing the bit pattern, like as found at 84 | https://omerk.github.io/lcdchargen/ 85 | """ 86 | location &= 0x07 # Make sure location is 0-7 87 | textCommand(0x40 | (location << 3)) 88 | bus.write_i2c_block_data(DISPLAY_TEXT_ADDR, 0x40, pattern) 89 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/mqtt_DFRObot.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | import RPi.GPIO as GPIO 5 | import time 6 | import atexit 7 | 8 | LED = 12 9 | 10 | atexit.register(GPIO.cleanup) 11 | GPIO.setmode(GPIO.BCM) 12 | GPIO.setup(LED,GPIO.OUT) 13 | 14 | 15 | def on_connect(client, userdata, flags, rc): 16 | print("Connected to broker. Return of connection: "+str(rc)) 17 | 18 | client.subscribe("MQTTLED") 19 | 20 | # Callback - when a message is received 21 | def on_message(client, userdata, msg): 22 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 23 | df=msg.payload.decode('utf-8') 24 | print(df) 25 | 26 | if (df == "ONLED1"): 27 | GPIO.output(LED,GPIO.HIGH) 28 | return 0 29 | 30 | if (df == "OFFLED1"): 31 | GPIO.output(LED,GPIO.LOW) 32 | return 0 33 | 34 | #main program 35 | client = mqtt.Client() 36 | client.on_connect = on_connect # configure callback (from when the connection$ 37 | client.on_message = on_message # set callback (from when a message is receive$ 38 | 39 | client.connect("broker.emqx.io", 1883, 60) 40 | 41 | # Endless loop waiting to receive messages. . 42 | client.loop_forever() 43 | 44 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/mqtt_DFRObot_PWM.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | import RPi.GPIO as GPIO 5 | import time 6 | import atexit 7 | 8 | from dfadc import * 9 | 10 | board_detect() 11 | 12 | while board.begin() != board.STA_OK: 13 | print_board_status() 14 | print("board begin faild") 15 | time.sleep(2) 16 | print("board begin success") 17 | board.set_adc_enable() 18 | board.set_pwm_enable() 19 | board.set_pwm_frequency(1000) 20 | LED = 12 21 | 22 | atexit.register(GPIO.cleanup) 23 | GPIO.setmode(GPIO.BCM) 24 | GPIO.setup(LED,GPIO.OUT) 25 | 26 | 27 | def on_connect(client, userdata, flags, rc): 28 | print("Connected to broker. Return of connection: "+str(rc)) 29 | client.subscribe("Motor") 30 | 31 | # Callback - when a message is received 32 | def on_message(client, userdata, msg): 33 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 34 | df=msg.payload.decode('utf-8') 35 | print(df) 36 | print(type(df)) 37 | df=int(df) 38 | # df3=df.decode() 39 | 40 | # if (df == 100): 41 | # board.set_pwm_duty(0,df) 42 | # return 0 43 | 44 | # if (df == 50): 45 | # board.set_pwm_duty(0,df) 46 | # return 0 47 | 48 | # if (df == 10): 49 | board.set_pwm_duty(0,df) 50 | return 0 51 | 52 | 53 | def on_publish(client, userdata, mid): 54 | print("mid: " + str(mid)) 55 | 56 | 57 | def on_subscribe(client, userdata, mid, granted_qos): 58 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 59 | 60 | #main progra6m 61 | 62 | client = mqtt.Client() 63 | client.on_connect = on_connect # configure callback (from when the connection$ 64 | client.on_message = on_message # set callback (from when a message is receive$ 65 | client.on_publish = on_publish 66 | client.on_subscribe = on_subscribe 67 | client.connect("broker.emqx.io", 1883, 60) 68 | 69 | rc = 0 70 | while rc == 0: 71 | 72 | rc = client.loop() 73 | # Use read_retry method. This will retry up to 15 times to 74 | # get a sensor reading (waiting 2 seconds between each retry). 75 | temp = board.get_adc_value(board.A0) # A0 channels read 76 | humidity = board.get_adc_value(board.A1) 77 | temperature = (temp/4096)* 100+20 78 | humidity = (humidity/4096)* 100 79 | # humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio) 80 | # Reading the DHT11 is very sensitive to timings and occasionally 81 | # the Pi might fail to get a valid reading. So check if readings are valid. 82 | if humidity is not None and temperature is not None: 83 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 84 | client.publish("humidity",str(humidity)) 85 | client.publish("Temp",str(temperature)) 86 | time.sleep(1) 87 | 88 | else: 89 | print('Failed to get reading. Try again!') 90 | 91 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/mqtt_DFRObot_analog.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | import RPi.GPIO as GPIO 5 | import time 6 | import atexit 7 | 8 | from dfadc import * 9 | 10 | board_detect() 11 | 12 | while board.begin() != board.STA_OK: 13 | print_board_status() 14 | print("board begin faild") 15 | time.sleep(2) 16 | print("board begin success") 17 | 18 | board.set_adc_enable() 19 | 20 | LED = 12 21 | 22 | atexit.register(GPIO.cleanup) 23 | GPIO.setmode(GPIO.BCM) 24 | GPIO.setup(LED,GPIO.OUT) 25 | 26 | 27 | def on_connect(client, userdata, flags, rc): 28 | print("Connected to broker. Return of connection: "+str(rc)) 29 | client.subscribe("MQTTLED") 30 | 31 | # Callback - when a message is received 32 | def on_message(client, userdata, msg): 33 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 34 | df=msg.payload.decode('utf-8') 35 | print(df) 36 | # df3=df.decode() 37 | 38 | if (df == "ONLED1"): 39 | GPIO.output(LED,GPIO.HIGH) 40 | return 0 41 | 42 | if (df == "OFFLED1"): 43 | GPIO.output(LED,GPIO.LOW) 44 | return 0 45 | 46 | 47 | def on_publish(client, userdata, mid): 48 | print("mid: " + str(mid)) 49 | 50 | 51 | def on_subscribe(client, userdata, mid, granted_qos): 52 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 53 | 54 | #main progra6m 55 | 56 | client = mqtt.Client() 57 | client.on_connect = on_connect # configure callback (from when the connection$ 58 | client.on_message = on_message # set callback (from when a message is receive$ 59 | client.on_publish = on_publish 60 | client.on_subscribe = on_subscribe 61 | client.connect("broker.emqx.io", 1883, 60) 62 | 63 | rc = 0 64 | while rc == 0: 65 | 66 | rc = client.loop() 67 | # Use read_retry method. This will retry up to 15 times to 68 | # get a sensor reading (waiting 2 seconds between each retry). 69 | temp = board.get_adc_value(board.A0) # A0 channels read 70 | humidity = board.get_adc_value(board.A1) 71 | temperature = (temp/4096)* 100+20 72 | humidity = (humidity/4096)* 100 73 | # humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio) 74 | # Reading the DHT11 is very sensitive to timings and occasionally 75 | # the Pi might fail to get a valid reading. So check if readings are valid. 76 | if humidity is not None and temperature is not None: 77 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity)) 78 | client.publish("humidity",str(humidity)) 79 | client.publish("Temp",str(temperature)) 80 | time.sleep(1) 81 | 82 | else: 83 | print('Failed to get reading. Try again!') 84 | -------------------------------------------------------------------------------- /Module-2/Unit-4/DFRobot_Practicals/telegram_GPIO.py: -------------------------------------------------------------------------------- 1 | import time, datetime 2 | 3 | import RPi.GPIO as GPIO 4 | 5 | import telepot 6 | 7 | from telepot.loop import MessageLoop 8 | 9 | led1 = 17 10 | 11 | led2 = 27 12 | 13 | led3 = 22 14 | 15 | buzzer = 23 16 | 17 | now = datetime.datetime.now() 18 | 19 | GPIO.setmode(GPIO.BCM) 20 | 21 | GPIO.setwarnings(False) 22 | 23 | #MYLED 24 | 25 | GPIO.setup(led1, GPIO.OUT) 26 | 27 | GPIO.output(led1, 0) #Off initially 28 | 29 | GPIO.setup(led2, GPIO.OUT) 30 | 31 | GPIO.output(led2, 0) #Off initially 32 | 33 | GPIO.setup(led3, GPIO.OUT) 34 | 35 | GPIO.output(led3, 0) #Off initially 36 | 37 | GPIO.setup(buzzer, GPIO.OUT) 38 | 39 | GPIO.output(buzzer, 0) #Off initially 40 | 41 | 42 | 43 | def action(msg): 44 | 45 | chat_id = msg['chat']['id'] 46 | 47 | command = msg['text'] 48 | 49 | print ('Received: %s' % command) 50 | 51 | if 'on' in command: 52 | 53 | message = "Turned on " 54 | 55 | if 'led1' in command: 56 | 57 | message = message + "led1 " 58 | 59 | GPIO.output(led1, 1) 60 | 61 | 62 | 63 | if 'led2' in command: 64 | 65 | message = message + "led2 " 66 | 67 | GPIO.output(led2, 1) 68 | 69 | 70 | 71 | if 'led3' in command: 72 | 73 | message = message + "led3 " 74 | 75 | GPIO.output(led3, 1) 76 | 77 | if 'buzzer' in command: 78 | 79 | message = message + "buzzer " 80 | 81 | GPIO.output(buzzer, 1) 82 | 83 | 84 | 85 | if 'all' in command: 86 | 87 | message = message + "all " 88 | 89 | GPIO.output(led1, 1) 90 | 91 | GPIO.output(led2, 1) 92 | 93 | GPIO.output(led3, 1) 94 | 95 | GPIO.output(buzzer, 1) 96 | 97 | message = message + "light(s)" 98 | 99 | telegram_bot.sendMessage (chat_id, message) 100 | 101 | 102 | 103 | if 'off' in command: 104 | 105 | message = "Turned off " 106 | 107 | if 'led1' in command: 108 | 109 | message = message + "led1 " 110 | 111 | GPIO.output(led1, 0) 112 | 113 | if 'led2' in command: 114 | 115 | message = message + "led2 " 116 | 117 | GPIO.output(led2, 0) 118 | 119 | if 'led3' in command: 120 | 121 | message = message + "led3 " 122 | 123 | GPIO.output(led3, 0) 124 | 125 | if 'buzzer' in command: 126 | 127 | message = message + "buzzer " 128 | 129 | 130 | 131 | GPIO.output(buzzer, 0) 132 | 133 | if 'all' in command: 134 | 135 | message = message + "all " 136 | 137 | GPIO.output(led1, 0) 138 | 139 | GPIO.output(led2, 0) 140 | 141 | GPIO.output(led3, 0) 142 | 143 | GPIO.output(buzzer, 0) 144 | 145 | message = message + "light(s)" 146 | 147 | telegram_bot.sendMessage (chat_id, message) 148 | 149 | 150 | 151 | telegram_bot = telepot.Bot('6565701289:AAF-zmPrM5GYC3I-4GtmshVMfVPizCyZ6vA') 152 | 153 | print (telegram_bot.getMe()) 154 | 155 | MessageLoop(telegram_bot, action).run_as_thread() 156 | 157 | print ('Code Unnati Home automation is Up and Running....') 158 | 159 | 160 | 161 | while 1: 162 | 163 | time.sleep(10) 164 | 165 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/Autotweet_GrovePI.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | from grovepi import * 3 | from grove_rgb_lcd import * 4 | import time 5 | from math import isnan 6 | from time import strftime 7 | import math 8 | 9 | consumer_key = '2IWlVt3Px1GtUfM7T6n1thTGC' 10 | consumer_secret = 'YasyTDfoMXRakvxLWLtyVXatC98T8lTIXdy96kiZyT7ClgXGad' 11 | access_token = '1043489874559397888-Ok5ZP06n6kaPIHHrgSk41fIhJPfArK' 12 | access_token_secret = 'gFmwTsr9lH7b5v8t8BR8mTpDwyJ7M7GttYMu4UL4zm6cz' 13 | 14 | client = tweepy.Client(consumer_key=consumer_key,consumer_secret=consumer_secret,access_token=access_token,access_token_secret=access_token_secret) 15 | 16 | location="Jaipur" 17 | #time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 18 | #print(time_stamp) 19 | dht_sensor_port = 7 20 | 21 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 22 | setRGB(0,255,0) 23 | while True: 24 | # Print the values to the serial port 25 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 26 | print(f"Temp:{t} C Humidity:{h}%") 27 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 28 | print(t) 29 | print(h) 30 | time_stamp=strftime("%d-%m-%y %H:%M:%S", time.localtime()) 31 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 32 | sd='Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h) 33 | sd=time_stamp+" "+sd 34 | print(sd) 35 | client.create_tweet(text=sd) 36 | print("Sent to Twitter") 37 | time.sleep(5.0) -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/Firebase_data_logging.py: -------------------------------------------------------------------------------- 1 | # pip3 install Pyrebase 2 | from grovepi import * 3 | from grove_rgb_lcd import * 4 | import time 5 | from math import isnan 6 | from time import strftime 7 | import math 8 | import pyrebase 9 | 10 | dht_sensor_port = 7 11 | 12 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 13 | 14 | setRGB(0,255,0) 15 | 16 | config = { 17 | "apiKey": "AIzaSyBLCJBhKJ6Gi1HN3QkqTqvlklMfdf8vBL4", 18 | "authDomain": "diwakarrpi.firebaseapp.com", 19 | "databaseURL": "https://diwakarrpi-default-rtdb.firebaseio.com/", 20 | "storageBucket": "diwakarrpi.appspot.com" 21 | } 22 | 23 | firebase = pyrebase.initialize_app(config) 24 | 25 | db = firebase.database() 26 | 27 | 28 | 29 | 30 | while True: 31 | try: 32 | # Print the values to the serial port 33 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 34 | print(f"Temp:{t} C Humidity:{h}%") 35 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 36 | print(t) 37 | print(h) 38 | data = {"Temperature" : t,"Humidity" : h} 39 | db.child("Status").push(data) 40 | db.update(data) 41 | print("Sent to Firebase") 42 | 43 | except RuntimeError as error: 44 | # Errors happen fairly often, DHT's are hard to read, just keep going 45 | print(error.args[0]) 46 | time.sleep(2.0) 47 | continue 48 | except Exception as error: 49 | dhtDevice.exit() 50 | raise error 51 | 52 | time.sleep(2.0) 53 | 54 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/MQTT_PWM_Control.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | from grove_rgb_lcd import * 6 | import time 7 | led = 3 8 | dht_sensor_port = 7 9 | 10 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 11 | 12 | setRGB(0,255,0) 13 | pinMode(led,"OUTPUT") 14 | 15 | 16 | def on_connect(client, userdata, flags, rc): 17 | print("Connected to broker. Return of connection: "+str(rc)) 18 | client.subscribe("Motor") 19 | 20 | # Callback - when a message is received 21 | def on_message(client, userdata, msg): 22 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 23 | df=msg.payload.decode('utf-8') 24 | print(df) 25 | print(type(df)) 26 | df=int(df) 27 | # df3=df.decode() 28 | 29 | if (df == 100): 30 | analogWrite(led,df) 31 | return 0 32 | 33 | if (df == 50): 34 | analogWrite(led,df) 35 | return 0 36 | 37 | if (df == 10): 38 | analogWrite(led,df) 39 | return 0 40 | 41 | 42 | def on_publish(client, userdata, mid): 43 | print("mid: " + str(mid)) 44 | 45 | 46 | def on_subscribe(client, userdata, mid, granted_qos): 47 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 48 | 49 | #main progra6m 50 | 51 | client = mqtt.Client() 52 | client.on_connect = on_connect # configure callback (from when the connection$ 53 | client.on_message = on_message # set callback (from when a message is receive$ 54 | client.on_publish = on_publish 55 | client.on_subscribe = on_subscribe 56 | #client.connect("test.mosquitto.org", 1883, 60) 57 | client.connect("broker.emqx.io", 1883, 60) 58 | 59 | rc = 0 60 | while rc == 0: 61 | 62 | rc = client.loop() 63 | # Use read_retry method. This will retry up to 15 times to 64 | # get a sensor reading (waiting 2 seconds between each retry). 65 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 66 | print(f"Temp:{t} C Humidity:{h}%") 67 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 68 | # Reading the DHT11 is very sensitive to timings and occasionally 69 | # the Pi might fail to get a valid reading. So check if readings are valid. 70 | if h is not None and t is not None: 71 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 72 | client.publish("humidity",str(h)) 73 | client.publish("Temp",str(t)) 74 | time.sleep(1) 75 | 76 | else: 77 | print('Failed to get reading. Try again!') 78 | 79 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/MQTT_PWM_Control_Sliding.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | from grove_rgb_lcd import * 6 | import time 7 | led = 3 # motor 8 | dht_sensor_port = 7 9 | 10 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 11 | 12 | setRGB(0,255,0) 13 | pinMode(led,"OUTPUT") 14 | 15 | 16 | def on_connect(client, userdata, flags, rc): 17 | print("Connected to broker. Return of connection: "+str(rc)) 18 | client.subscribe("Motor") 19 | 20 | # Callback - when a message is received 21 | def on_message(client, userdata, msg): 22 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 23 | df=msg.payload.decode('utf-8') 24 | print(df) 25 | print(type(df)) 26 | df=int(df) 27 | # df3=df.decode() 28 | analogWrite(led,df) 29 | return 0 30 | 31 | 32 | def on_publish(client, userdata, mid): 33 | print("mid: " + str(mid)) 34 | 35 | 36 | def on_subscribe(client, userdata, mid, granted_qos): 37 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 38 | 39 | #main progra6m 40 | 41 | client = mqtt.Client() 42 | client.on_connect = on_connect # configure callback (from when the connection$ 43 | client.on_message = on_message # set callback (from when a message is receive$ 44 | client.on_publish = on_publish 45 | client.on_subscribe = on_subscribe 46 | #client.connect("test.mosquitto.org", 1883, 60) 47 | client.connect("broker.emqx.io", 1883, 60) 48 | 49 | rc = 0 50 | while rc == 0: 51 | 52 | rc = client.loop() 53 | # Use read_retry method. This will retry up to 15 times to 54 | # get a sensor reading (waiting 2 seconds between each retry). 55 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 56 | print(f"Temp:{t} C Humidity:{h}%") 57 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 58 | # Reading the DHT11 is very sensitive to timings and occasionally 59 | # the Pi might fail to get a valid reading. So check if readings are valid. 60 | if h is not None and t is not None: 61 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 62 | client.publish("humidity",str(h)) 63 | client.publish("Temp",str(t)) 64 | time.sleep(1) 65 | 66 | else: 67 | print('Failed to get reading. Try again!') 68 | 69 | 70 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/MQTT_analog_data.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | from grove_rgb_lcd import * 6 | 7 | import time 8 | 9 | dht_sensor_port = 7 10 | 11 | dht_sensor_type = 0 # 0 for DHT11 and 1 for DHT22 12 | 13 | setRGB(0,255,0) 14 | 15 | led = 8 16 | 17 | pinMode(led,"OUTPUT") 18 | 19 | 20 | def on_connect(client, userdata, flags, rc): 21 | print("Connected to broker. Return of connection: "+str(rc)) 22 | client.subscribe("MQTTLed") 23 | 24 | # Callback - when a message is received 25 | def on_message(client, userdata, msg): 26 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 27 | df=msg.payload.decode('utf-8') 28 | print(df) 29 | # df3=df.decode() 30 | 31 | if (df == "ONLED1"): 32 | digitalWrite(led,1) 33 | return 0 34 | 35 | if (df == "OFFLED1"): 36 | digitalWrite(led,0) 37 | return 0 38 | 39 | 40 | def on_publish(client, userdata, mid): 41 | print("mid: " + str(mid)) 42 | 43 | 44 | def on_subscribe(client, userdata, mid, granted_qos): 45 | print("Subscribed: " + str(mid) + " " + str(granted_qos)) 46 | 47 | #main progra6m 48 | 49 | client = mqtt.Client() 50 | client.on_connect = on_connect # configure callback (from when the connection$ 51 | client.on_message = on_message # set callback (from when a message is receive$ 52 | client.on_publish = on_publish 53 | client.on_subscribe = on_subscribe 54 | client.connect("broker.emqx.io", 1883, 60) 55 | 56 | rc = 0 57 | while rc == 0: 58 | 59 | rc = client.loop() 60 | # Use read_retry method. This will retry up to 15 times to 61 | # get a sensor reading (waiting 2 seconds between each retry). 62 | [t,h] = dht(dht_sensor_port,dht_sensor_type) 63 | print(f"Temp:{t} C Humidity:{h}%") 64 | setText_norefresh(f"Temp:{t} C\nHumidity:{h}%") 65 | # Reading the DHT11 is very sensitive to timings and occasionally 66 | # the Pi might fail to get a valid reading. So check if readings are valid. 67 | if h is not None and t is not None: 68 | print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)) 69 | client.publish("humidity",str(h)) 70 | client.publish("Temp",str(t)) 71 | time.sleep(1) 72 | 73 | else: 74 | print('Failed to get reading. Try again!') 75 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/MQTT_led_Control.py: -------------------------------------------------------------------------------- 1 | #pip install paho-mqtt 2 | # Might not work for python 3(Use Python 2) 3 | import paho.mqtt.client as mqtt 4 | from grovepi import * 5 | import time 6 | led = 7 7 | pinMode(led,"OUTPUT") 8 | def on_connect(client, userdata, flags, rc): 9 | print("Connected to broker. Return of connection: "+str(rc)) 10 | client.subscribe("MQTTLed") 11 | 12 | # Callback - when a message is received 13 | def on_message(client, userdata, msg): 14 | print("Topic: "+msg.topic+" - Message Received: "+str(msg.payload)) 15 | df=msg.payload.decode('utf-8') 16 | print(df) 17 | if (df == "ONLED1"): 18 | digitalWrite(led,1) 19 | return 0 20 | 21 | if (df == "OFFLED1"): 22 | digitalWrite(led,0) 23 | return 0 24 | 25 | #main program 26 | client = mqtt.Client() 27 | client.on_connect = on_connect # configure callback (from when the connection$ 28 | client.on_message = on_message # set callback (from when a message is receive$ 29 | 30 | #client.connect("test.mosquitto.org", 1883, 60) 31 | client.connect("broker.emqx.io", 1883, 60) 32 | 33 | # Endless loop waiting to receive messages. . 34 | client.loop_forever() -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/Telegram_grovepi.py: -------------------------------------------------------------------------------- 1 | # pip3 install telepot 2 | import time, datetime 3 | 4 | import telepot 5 | 6 | from telepot.loop import MessageLoop 7 | 8 | from grovepi import * 9 | 10 | led = 2 #connect led grovepi module on D2 11 | 12 | now = datetime.datetime.now() 13 | 14 | #LED White 15 | 16 | pinMode(led,"OUTPUT") 17 | 18 | time.sleep(1) 19 | 20 | digitalWrite(led,0) #Off initially 21 | 22 | 23 | 24 | def action(msg): 25 | 26 | chat_id = msg['chat']['id'] 27 | 28 | command = msg['text'] 29 | 30 | print ('Received: %s' % command) 31 | 32 | if 'on' in command: 33 | 34 | message = "Turned on " 35 | 36 | if 'led' in command: 37 | 38 | message = message + "led " 39 | 40 | digitalWrite(led,1) 41 | 42 | 43 | 44 | if 'all' in command: 45 | 46 | message = message + "all " 47 | 48 | digitalWrite(led,1) 49 | 50 | 51 | 52 | message = message + "light(s)" 53 | 54 | telegram_bot.sendMessage (chat_id, message) 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | if 'off' in command: 63 | 64 | message = "Turned off " 65 | 66 | if 'led' in command: 67 | 68 | message = message + "led " 69 | 70 | digitalWrite(led,0) 71 | 72 | 73 | 74 | if 'all' in command: 75 | 76 | message = message + "all " 77 | 78 | digitalWrite(led,0) 79 | 80 | 81 | 82 | message = message + "light(s)" 83 | 84 | telegram_bot.sendMessage (chat_id, message) 85 | 86 | 87 | 88 | telegram_bot = telepot.Bot('6348232837:AAFdpKqwUkxmNnMi1ApBYwO54toVCPn0y6U') #use telegram access key API from telegram app of mobile 89 | 90 | print (telegram_bot.getMe()) 91 | 92 | MessageLoop(telegram_bot, action).run_as_thread() 93 | 94 | print ('Up and Running....') 95 | 96 | 97 | 98 | while 1: 99 | 100 | time.sleep(10) 101 | 102 | -------------------------------------------------------------------------------- /Module-2/Unit-4/GrovePi_Practicals/thingspeak_grovepi.py: -------------------------------------------------------------------------------- 1 | #pip3 install thingspeak 2 | 3 | import thingspeak 4 | 5 | import time 6 | 7 | from grovepi import * 8 | 9 | dht_sensor_port = 7 10 | 11 | dht_sensor_type = 0 12 | 13 | channel_id = '2224094' 14 | 15 | write_key = 'IN6UY2EWBYPP1173' # PUT YOUR WRITE KEY HERE 16 | 17 | 18 | # PUT YOUR WRITE KEY HERE 19 | 20 | 21 | def measure(channel): 22 | 23 | try: 24 | 25 | [ t,h ] = dht(dht_sensor_port,dht_sensor_type) 26 | 27 | response = channel.update({'field1': t, 'field2': h}) 28 | 29 | print(f"Temp:{t} C Humidity:{h}%") 30 | 31 | except: 32 | 33 | print("connection failed") 34 | 35 | 36 | 37 | channel = thingspeak.Channel(id=channel_id,api_key=write_key) 38 | 39 | while True: 40 | 41 | measure(channel) # free account has an api limit of 15sec 42 | 43 | time.sleep(15) -------------------------------------------------------------------------------- /Module-2/Unit-4/Lab 1 - Classroom Exercise_Deployment of HTTPS protocol on IoT Devices.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-4/Lab 1 - Classroom Exercise_Deployment of HTTPS protocol on IoT Devices.pdf -------------------------------------------------------------------------------- /Module-2/Unit-4/Lab 2 - Classroom Exercise_Deployment of MQTT protocol on IoT Devices.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-4/Lab 2 - Classroom Exercise_Deployment of MQTT protocol on IoT Devices.pdf -------------------------------------------------------------------------------- /Module-2/Unit-4/Lab 3 - Classroom Exercise_Deployment of Firebase Datalogging from IoT Devices.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-4/Lab 3 - Classroom Exercise_Deployment of Firebase Datalogging from IoT Devices.pdf -------------------------------------------------------------------------------- /Module-2/Unit-4/Lab 4 - Classroom Exercise_Post Tweets on Twitter using IoT Devices.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-4/Lab 4 - Classroom Exercise_Post Tweets on Twitter using IoT Devices.pdf -------------------------------------------------------------------------------- /Module-2/Unit-4/Lab 5 - Classroom Exercise_Remote Controlling of IoT Devices through Telegram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-4/Lab 5 - Classroom Exercise_Remote Controlling of IoT Devices through Telegram.pdf -------------------------------------------------------------------------------- /Module-2/Unit-5/Lab 1 - Classroom Exercise_IOT_Cloud.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-5/Lab 1 - Classroom Exercise_IOT_Cloud.pdf -------------------------------------------------------------------------------- /Module-2/Unit-5/Lab 2 - Classroom Exercise_RPi_to_Cloud.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-5/Lab 2 - Classroom Exercise_RPi_to_Cloud.pdf -------------------------------------------------------------------------------- /Module-2/Unit-5/Lab 3 - Classroom Exercise_Collecting_sensor_data.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-2/Unit-5/Lab 3 - Classroom Exercise_Collecting_sensor_data.pdf -------------------------------------------------------------------------------- /Module-2/Unit-5/mobile_data.csv: -------------------------------------------------------------------------------- 1 | X,Y,Z 2 | 0.014579001,-0.014945,1.007415058 3 | 0.014091,0.001891,1.008879025 4 | 0.014823,1.83E-04,1.011807056 5 | 0.014091,0.001159,1.011807056 6 | 0.014579001,-0.012749001,1.001071006 7 | 0.023119,0.002379,1.032546979 8 | 0.015067,0.001159,1.012051051 9 | 0.014579001,-6.10E-05,1.008879025 10 | 0.015799001,-6.10E-05,1.009855003 11 | 0.014823,-3.05E-04,1.009367014 12 | 0.014579001,4.27E-04,1.008391036 13 | 0.015067,6.71E-04,1.010586986 14 | 0.014823,9.15E-04,1.011074975 15 | 0.016287,-6.10E-05,1.007171063 16 | 0.015799001,-6.10E-05,1.010586986 17 | 0.015067,-3.05E-04,1.009123019 18 | 0.015067,9.15E-04,1.010586986 19 | 0.016043,6.71E-04,1.006926971 20 | 0.017263,0.001403,1.003267054 21 | 0.016043,4.27E-04,1.003267054 22 | 0.016531001,-7.93E-04,1.003511048 23 | 0.015555,4.27E-04,1.003023059 24 | 0.015799001,6.71E-04,1.003511048 25 | 0.015311,1.83E-04,1.003755043 26 | 0.016531001,-3.05E-04,1.00521901 27 | 0.015555,-6.10E-05,1.006438982 28 | 0.015067,-3.05E-04,1.007415058 29 | 0.015555,6.71E-04,1.005706999 30 | 0.016287,0.001159,1.009611008 31 | 0.015799001,4.27E-04,1.007415058 32 | 0.016775,6.71E-04,1.006438982 33 | 0.014823,-3.05E-04,1.006682977 34 | 0.015799001,-3.05E-04,1.007415058 35 | 0.015311,-5.49E-04,1.009855003 36 | 0.015555,4.27E-04,1.009367014 37 | 0.015067,6.71E-04,1.007903047 38 | 0.015311,6.71E-04,1.00863503 39 | 0.015555,1.83E-04,1.008879025 40 | 0.014579001,1.83E-04,1.007171063 41 | 0.015555,6.71E-04,1.007415058 42 | 0.013847001,6.71E-04,1.011807056 43 | 0.025315,-0.032025001,1.011563062 44 | 0.005063,0.0331535,1.01131897 45 | 0.016775,-3.05E-04,1.004975015 46 | 0.016287,6.71E-04,1.006194988 47 | 0.014823,0.001403,1.007659052 48 | 0.015311,-3.05E-04,1.009855003 49 | 0.014579001,6.71E-04,1.013271023 50 | 0.014091,4.27E-04,1.014978985 51 | 0.014579001,0.001159,1.013759012 52 | 0.015799001,4.27E-04,1.011563062 53 | 0.015067,9.15E-04,1.011807056 54 | 0.014579001,-6.10E-05,1.014247001 55 | 0.015067,4.27E-04,1.008391036 56 | 0.016043,0.001647,1.011074975 57 | 0.015067,-6.10E-05,1.012295045 58 | 0.015311,6.71E-04,1.010098997 59 | 0.014823,6.71E-04,1.007415058 60 | 0.015555,1.83E-04,1.00521901 61 | 0.015311,4.27E-04,1.006682977 62 | 0.015799001,-5.49E-04,1.00863503 63 | 0.015311,-3.05E-04,1.008391036 64 | 0.015311,-3.05E-04,1.009367014 65 | 0.014335,-7.93E-04,1.009123019 66 | 0.016043,4.27E-04,1.011563062 67 | 0.015067,9.15E-04,1.008391036 68 | 0.014335,1.83E-04,1.009611008 69 | 0.015799001,9.15E-04,1.012051051 70 | 0.015067,0.001403,1.01131897 71 | 0.015311,1.83E-04,1.011074975 72 | 0.014335,-6.10E-05,1.011563062 73 | 0.015067,1.83E-04,1.011807056 74 | 0.016531001,1.83E-04,1.009123019 75 | 0.015311,6.71E-04,1.011074975 76 | 0.015555,9.15E-04,1.027910986 77 | 0.014579001,-5.49E-04,1.009123019 78 | 0.017019001,0.001647,1.006194988 79 | 0.015555,1.83E-04,1.010342992 80 | 0.014579001,-5.49E-04,1.010586986 81 | 0.015067,4.27E-04,1.009611008 82 | 0.016775,1.83E-04,1.008147041 83 | 0.015799001,0.002135,1.009123019 84 | 0.015799001,4.27E-04,1.00863503 85 | 0.014091,4.27E-04,1.013027029 86 | 0.014823,0.001159,1.008147041 87 | 0.015799001,-6.10E-05,1.009855003 88 | 0.014091,0.001891,1.005950993 89 | 0.015311,6.71E-04,1.008147041 90 | 0.015311,6.71E-04,1.010098997 91 | 0.015555,1.83E-04,1.010098997 92 | 0.015067,-3.05E-04,1.011807056 93 | 0.016043,-6.10E-05,1.008391036 94 | 0.016775,6.71E-04,1.011563062 95 | 0.014823,4.27E-04,1.011074975 96 | 0.015555,-5.49E-04,1.011074975 97 | 0.015799001,1.83E-04,1.010586986 98 | 0.013847001,4.27E-04,1.01131897 99 | 0.016043,4.27E-04,1.012295045 100 | 0.014823,-7.93E-04,1.010586986 101 | 0.014823,1.83E-04,1.013027029 102 | -------------------------------------------------------------------------------- /Module-3/Unit-2/Lab 1 Classroom Exercise (OpenCV).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "d9908b61", 6 | "metadata": {}, 7 | "source": [ 8 | "# EDUNET FOUNDATION - Classroom Exercise Notebook" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "id": "7ebbb29e", 14 | "metadata": {}, 15 | "source": [ 16 | "## Lab - 1 Basic Operation on Image Using cv2 \n" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "id": "5b263466", 22 | "metadata": {}, 23 | "source": [ 24 | "## Exercise-1 Image Reading in Different Types" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 14, 30 | "id": "5c2006d1", 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import cv2\n", 35 | "import numpy as np" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 15, 41 | "id": "d4852ff2", 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "image = cv2.imread(\"image.jpeg\")" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "id": "2a368637", 51 | "metadata": {}, 52 | "source": [ 53 | "### In the Second Parameter of cv2.imread(\"Source of Image \", below 3 options)\n", 54 | "- cv2.IMREAD_COLOR: It specifies to load a color image. Any transparency of image will be neglected. It is the default flag. Alternatively, we can pass integer value 1 for this flag.\n", 55 | "- cv2.IMREAD_GRAYSCALE: It specifies to load an image in grayscale mode. Alternatively, we can pass integer value 0 for this flag.\n", 56 | "- cv2.IMREAD_UNCHANGED: It specifies to load an image as such including alpha channel. Alternatively, we can pass integer value -1 for this flag.\n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "id": "caf0e0f2", 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "cv2.imshow(\"image\", image)\n", 67 | "cv2.waitKey(0)\n", 68 | "cv2.destroyAllWindows()" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "id": "7f0e5cf7", 75 | "metadata": {}, 76 | "outputs": [], 77 | "source": [] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "id": "a71034c6", 82 | "metadata": {}, 83 | "source": [ 84 | "## Exercise-2 Starting Video Camera" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "id": "b1649ce1", 90 | "metadata": {}, 91 | "source": [ 92 | "### Steps to capture a video:\n", 93 | "\n", 94 | "- Use cv2.VideoCapture() to get a video capture object for the camera.\n", 95 | "- Set up an infinite while loop and use the read() method to read the frames using the above created object.\n", 96 | "- Use cv2.imshow() method to show the frames in the video.\n", 97 | "- Breaks the loop when the user clicks a specific key." 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "id": "33d7b22b", 104 | "metadata": {}, 105 | "outputs": [], 106 | "source": [ 107 | "# import the opencv library\n", 108 | "import cv2\n", 109 | " \n", 110 | " \n", 111 | "# define a video capture object\n", 112 | "vid = cv2.VideoCapture(0)\n", 113 | " \n", 114 | "while(True):\n", 115 | " \n", 116 | " # Capture the video frame\n", 117 | " # by frame\n", 118 | " ret, frame = vid.read()\n", 119 | " \n", 120 | " # Display the resulting frame\n", 121 | " cv2.imshow('frame', frame)\n", 122 | " \n", 123 | " # the 'q' button is set as the\n", 124 | " # quitting button you may use any\n", 125 | " # desired button of your choice\n", 126 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 127 | " break\n", 128 | " \n", 129 | "# After the loop release the cap object\n", 130 | "vid.release()\n", 131 | "# Destroy all the windows\n", 132 | "cv2.destroyAllWindows()" 133 | ] 134 | }, 135 | { 136 | "cell_type": "markdown", 137 | "id": "37a528cf", 138 | "metadata": {}, 139 | "source": [ 140 | "## Exercise-3 Image Filter" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": null, 146 | "id": "8df025bf", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "image = cv2.imread(\"image.jpeg\")\n", 151 | "\n", 152 | "# Print error message if image is null\n", 153 | "if image is None:\n", 154 | " print('Could not read image')\n", 155 | "\n", 156 | "# Apply identity kernel\n", 157 | "kernel1 = np.array([[-7, 0, 7],\n", 158 | " [-7, 0, 7],\n", 159 | " [-7, 0, 7]])\n", 160 | "\n", 161 | "identity = cv2.filter2D(src=image, ddepth=-1,kernel=kernel1)\n", 162 | "\n", 163 | "\n", 164 | "cv2.imshow('Original', image)\n", 165 | "cv2.imshow('Identity', identity)\n", 166 | " \n", 167 | "cv2.waitKey()\n", 168 | "cv2.imwrite('identity.jpg', identity)\n", 169 | "cv2.destroyAllWindows()" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "id": "bc5ace26", 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "# Apply blurring kernel\n", 180 | "kernel2 = np.ones((5, 5), np.float32) / 25\n", 181 | "img = cv2.filter2D(src=image, ddepth=-1, kernel=kernel2)\n", 182 | "\n", 183 | "cv2.imshow('Original', image)\n", 184 | "cv2.imshow('Kernel Blur', img)\n", 185 | " \n", 186 | "cv2.waitKey()\n", 187 | "cv2.imwrite('blur_kernel.jpg', img)\n", 188 | "cv2.destroyAllWindows()" 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": null, 194 | "id": "58491a3d", 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "b,g,r=cv2.split(image)" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "id": "8faf9000", 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "g=b//2" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": null, 214 | "id": "ff92316c", 215 | "metadata": {}, 216 | "outputs": [], 217 | "source": [ 218 | "g" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": null, 224 | "id": "b47239f9", 225 | "metadata": {}, 226 | "outputs": [], 227 | "source": [ 228 | "img=cv2.merge((b,g,r))" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": null, 234 | "id": "23016b21", 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "cv2.imshow('Original', img)\n", 239 | "cv2.waitKey()\n", 240 | "cv2.destroyAllWindows()\n" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": null, 246 | "id": "d0ce71c2", 247 | "metadata": {}, 248 | "outputs": [], 249 | "source": [] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "id": "c9325bac", 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [] 258 | } 259 | ], 260 | "metadata": { 261 | "kernelspec": { 262 | "display_name": "Python 3 (ipykernel)", 263 | "language": "python", 264 | "name": "python3" 265 | }, 266 | "language_info": { 267 | "codemirror_mode": { 268 | "name": "ipython", 269 | "version": 3 270 | }, 271 | "file_extension": ".py", 272 | "mimetype": "text/x-python", 273 | "name": "python", 274 | "nbconvert_exporter": "python", 275 | "pygments_lexer": "ipython3", 276 | "version": "3.11.5" 277 | } 278 | }, 279 | "nbformat": 4, 280 | "nbformat_minor": 5 281 | } 282 | -------------------------------------------------------------------------------- /Module-3/Unit-2/Lab 3 Classroom Exercise Hand gesture.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "dcfa812a", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "pip install mediapipe" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": null, 16 | "id": "edde1fd8", 17 | "metadata": {}, 18 | "outputs": [], 19 | "source": [ 20 | "pip install screen-brightness-control" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "id": "4af8e19c", 27 | "metadata": {}, 28 | "outputs": [], 29 | "source": [ 30 | "# Importing Libraries \n", 31 | "import cv2 \n", 32 | "import mediapipe as mp \n", 33 | "from math import hypot \n", 34 | "import screen_brightness_control as sbc \n", 35 | "import numpy as np \n" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "id": "0c36410d", 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "# Initializing the Model \n", 46 | "mpHands = mp.solutions.hands \n", 47 | "hands = mpHands.Hands( \n", 48 | "\tstatic_image_mode=False, \n", 49 | "\tmodel_complexity=1, \n", 50 | "\tmin_detection_confidence=0.75, \n", 51 | "\tmin_tracking_confidence=0.75, \n", 52 | "\tmax_num_hands=2) \n", 53 | "\n", 54 | "Draw = mp.solutions.drawing_utils \n" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "id": "40904830", 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [ 64 | "# Start capturing video from webcam \n", 65 | "cap = cv2.VideoCapture(0) \n", 66 | "\n", 67 | "while True: \n", 68 | "\t# Read video frame by frame \n", 69 | "\t_,frame = cap.read() \n", 70 | "\t\n", 71 | "\t#Flip image \n", 72 | "\tframe=cv2.flip(frame,1) \n", 73 | "\t\n", 74 | "\t# Convert BGR image to RGB image \n", 75 | "\tframeRGB = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB) \n", 76 | "\t\n", 77 | "\t# Process the RGB image \n", 78 | "\tProcess = hands.process(frameRGB) \n", 79 | "\t\n", 80 | "\tlandmarkList = [] \n", 81 | "\t# if hands are present in image(frame) \n", 82 | "\tif Process.multi_hand_landmarks: \n", 83 | "\t\t# detect handmarks \n", 84 | "\t\tfor handlm in Process.multi_hand_landmarks: \n", 85 | "\t\t\tfor _id,landmarks in enumerate(handlm.landmark): \n", 86 | "\t\t\t\t# store height and width of image \n", 87 | "\t\t\t\theight,width,color_channels = frame.shape \n", 88 | "\t\t\t\t\n", 89 | "\t\t\t\t# calculate and append x, y coordinates \n", 90 | "\t\t\t\t# of handmarks from image(frame) to lmList \n", 91 | "\t\t\t\tx,y = int(landmarks.x*width),int(landmarks.y*height)\t\t\t \n", 92 | "\t\t\t\tlandmarkList.append([_id,x,y]) \n", 93 | "\t\t\t\n", 94 | "\t\t\t# draw Landmarks \n", 95 | "\t\t\tDraw.draw_landmarks(frame,handlm,mpHands.HAND_CONNECTIONS) \n", 96 | "\t\n", 97 | "\t# If landmarks list is not empty \n", 98 | "\tif landmarkList != []: \n", 99 | "\t\t# store x,y coordinates of (tip of) thumb \n", 100 | "\t\tx_1,y_1 = landmarkList[4][1],landmarkList[4][2] \n", 101 | "\t\t\n", 102 | "\t\t# store x,y coordinates of (tip of) index finger \n", 103 | "\t\tx_2,y_2 = landmarkList[8][1],landmarkList[8][2] \n", 104 | "\t\t\n", 105 | "\t\t# draw circle on thumb and index finger tip \n", 106 | "\t\tcv2.circle(frame,(x_1,y_1),7,(0,255,0),cv2.FILLED) \n", 107 | "\t\tcv2.circle(frame,(x_2,y_2),7,(0,255,0),cv2.FILLED) \n", 108 | "\t\t\n", 109 | "\t\t# draw line from tip of thumb to tip of index finger \n", 110 | "\t\tcv2.line(frame,(x_1,y_1),(x_2,y_2),(0,255,0),3) \n", 111 | "\t\t\n", 112 | "\t\t# calculate square root of the sum \n", 113 | "\t\t# of squares of the specified arguments. \n", 114 | "\t\tL = hypot(x_2-x_1,y_2-y_1) \n", 115 | "\t\t\n", 116 | "\t\t# 1-D linear interpolant to a function \n", 117 | "\t\t# with given discrete data points \n", 118 | "\t\t# (Hand range 15 - 220, Brightness range 0 - 100), \n", 119 | "\t\t# evaluated at length. \n", 120 | "\t\tb_level = np.interp(L,[15,220],[0,100]) \n", 121 | "\t\n", 122 | "\t\t# set brightness \n", 123 | "\t\tsbc.set_brightness(int(b_level)) \n", 124 | "\n", 125 | "\t# Display Video and when 'q' is entered, \n", 126 | "\t# destroy the window \n", 127 | "\tcv2.imshow('Image', frame) \n", 128 | "\tif cv2.waitKey(1) & 0xff == ord('q'): \n", 129 | "\t\tbreak\n" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "id": "63bac0ef", 136 | "metadata": {}, 137 | "outputs": [], 138 | "source": [] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "id": "25d09c40", 144 | "metadata": {}, 145 | "outputs": [], 146 | "source": [] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "id": "70fa00f3", 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [] 155 | } 156 | ], 157 | "metadata": { 158 | "kernelspec": { 159 | "display_name": "39", 160 | "language": "python", 161 | "name": "39" 162 | }, 163 | "language_info": { 164 | "codemirror_mode": { 165 | "name": "ipython", 166 | "version": 3 167 | }, 168 | "file_extension": ".py", 169 | "mimetype": "text/x-python", 170 | "name": "python", 171 | "nbconvert_exporter": "python", 172 | "pygments_lexer": "ipython3", 173 | "version": "3.9.18" 174 | } 175 | }, 176 | "nbformat": 4, 177 | "nbformat_minor": 5 178 | } 179 | -------------------------------------------------------------------------------- /Module-3/Unit-2/Lab 4 Classroom Exercise Drowsiness detection.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "4443876c", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import cv2\n", 11 | "import dlib\n", 12 | "import pyttsx3\n", 13 | "from scipy.spatial import distance\n", 14 | "\n", 15 | "# INITIALIZING THE pyttsx3 SO THAT \n", 16 | "# ALERT AUDIO MESSAGE CAN BE DELIVERED\n", 17 | "engine = pyttsx3.init()\n", 18 | "\n", 19 | "# SETTING UP OF CAMERA TO 1 YOU CAN\n", 20 | "# EVEN CHOOSE 0 IN PLACE OF 1\n", 21 | "cap = cv2.VideoCapture(0)\n", 22 | "\n", 23 | "# FACE DETECTION OR MAPPING THE FACE TO\n", 24 | "# GET THE Eye AND EYES DETECTED\n", 25 | "face_detector = dlib.get_frontal_face_detector()\n", 26 | "\n", 27 | "# PUT THE LOCATION OF .DAT FILE (FILE FOR\n", 28 | "# PREDECTING THE LANDMARKS ON FACE )\n", 29 | "dlib_facelandmark = dlib.shape_predictor(\n", 30 | "\t\"D:\\\\Edunet\\\\Gen-AI\\\\shape_predictor_68_face_landmarks.dat\\\\shape_predictor_68_face_landmarks.dat\")\n", 31 | "\n", 32 | "# FUNCTION CALCULATING THE ASPECT RATIO FOR\n", 33 | "# THE Eye BY USING EUCLIDEAN DISTANCE FUNCTION\n", 34 | "def Detect_Eye(eye):\n", 35 | "\tpoi_A = distance.euclidean(eye[1], eye[5])\n", 36 | "\tpoi_B = distance.euclidean(eye[2], eye[4])\n", 37 | "\tpoi_C = distance.euclidean(eye[0], eye[3])\n", 38 | "\taspect_ratio_Eye = (poi_A+poi_B)/(2*poi_C)\n", 39 | "\treturn aspect_ratio_Eye\n", 40 | "\n", 41 | "\n", 42 | "# MAIN LOOP IT WILL RUN ALL THE UNLESS AND \n", 43 | "# UNTIL THE PROGRAM IS BEING KILLED BY THE USER\n", 44 | "while True:\n", 45 | "\tnull, frame = cap.read()\n", 46 | "\tgray_scale = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n", 47 | "\n", 48 | "\tfaces = face_detector(gray_scale)\n", 49 | "\n", 50 | "\tfor face in faces:\n", 51 | "\t\tface_landmarks = dlib_facelandmark(gray_scale, face)\n", 52 | "\t\tleftEye = [] \n", 53 | "\t\trightEye = [] \n", 54 | "\n", 55 | "\t\t# THESE ARE THE POINTS ALLOCATION FOR THE \n", 56 | "\t\t# LEFT EYES IN .DAT FILE THAT ARE FROM 42 TO 47\n", 57 | "\t\tfor n in range(42, 48):\n", 58 | "\t\t\tx = face_landmarks.part(n).x\n", 59 | "\t\t\ty = face_landmarks.part(n).y\n", 60 | "\t\t\trightEye.append((x, y))\n", 61 | "\t\t\tnext_point = n+1\n", 62 | "\t\t\tif n == 47:\n", 63 | "\t\t\t\tnext_point = 42\n", 64 | "\t\t\tx2 = face_landmarks.part(next_point).x\n", 65 | "\t\t\ty2 = face_landmarks.part(next_point).y\n", 66 | "\t\t\tcv2.line(frame, (x, y), (x2, y2), (0, 255, 0), 1)\n", 67 | "\n", 68 | "\t\t# THESE ARE THE POINTS ALLOCATION FOR THE \n", 69 | "\t\t# RIGHT EYES IN .DAT FILE THAT ARE FROM 36 TO 41\n", 70 | "\t\tfor n in range(36, 42):\n", 71 | "\t\t\tx = face_landmarks.part(n).x\n", 72 | "\t\t\ty = face_landmarks.part(n).y\n", 73 | "\t\t\tleftEye.append((x, y))\n", 74 | "\t\t\tnext_point = n+1\n", 75 | "\t\t\tif n == 41:\n", 76 | "\t\t\t\tnext_point = 36\n", 77 | "\t\t\tx2 = face_landmarks.part(next_point).x\n", 78 | "\t\t\ty2 = face_landmarks.part(next_point).y\n", 79 | "\t\t\tcv2.line(frame, (x, y), (x2, y2), (255, 255, 0), 1)\n", 80 | "\n", 81 | "\t\t# CALCULATING THE ASPECT RATIO FOR LEFT \n", 82 | "\t\t# AND RIGHT EYE\n", 83 | "\t\tright_Eye = Detect_Eye(rightEye)\n", 84 | "\t\tleft_Eye = Detect_Eye(leftEye)\n", 85 | "\t\tEye_Rat = (left_Eye+right_Eye)/2\n", 86 | "\n", 87 | "\t\t# NOW ROUND OF THE VALUE OF AVERAGE MEAN \n", 88 | "\t\t# OF RIGHT AND LEFT EYES\n", 89 | "\t\tEye_Rat = round(Eye_Rat, 2)\n", 90 | "\n", 91 | "\t\t# THIS VALUE OF 0.25 (YOU CAN EVEN CHANGE IT) \n", 92 | "\t\t# WILL DECIDE WHETHER THE PERSONS'S EYES ARE CLOSE OR NOT\n", 93 | "\t\tif Eye_Rat < 0.25:\n", 94 | "\t\t\tcv2.putText(frame, \"DROWSINESS DETECTED\", (50, 100),\n", 95 | "\t\t\t\t\t\tcv2.FONT_HERSHEY_PLAIN, 2, (21, 56, 210), 3)\n", 96 | "\t\t\tcv2.putText(frame, \"Alert!!!! WAKE UP DUDE\", (50, 450),\n", 97 | "\t\t\t\t\t\tcv2.FONT_HERSHEY_PLAIN, 2, (21, 56, 212), 3)\n", 98 | "\n", 99 | "\t\t\t# CALLING THE AUDIO FUNCTION OF TEXT TO \n", 100 | "\t\t\t# AUDIO FOR ALERTING THE PERSON\n", 101 | "\t\t\tengine.say(\"Alert!!!! WAKE UP DUDE\")\n", 102 | "\t\t\tengine.runAndWait()\n", 103 | "\n", 104 | "\tcv2.imshow(\"Drowsiness DETECTOR IN OPENCV2\", frame)\n", 105 | "\tkey = cv2.waitKey(9)\n", 106 | "\tif key == 20:\n", 107 | "\t\tbreak\n", 108 | "cap.release()\n", 109 | "cv2.destroyAllWindows()\n" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "id": "ecfc8460", 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "!pip install pyttsx3" 120 | ] 121 | } 122 | ], 123 | "metadata": { 124 | "kernelspec": { 125 | "display_name": "Python 3 (ipykernel)", 126 | "language": "python", 127 | "name": "python3" 128 | }, 129 | "language_info": { 130 | "codemirror_mode": { 131 | "name": "ipython", 132 | "version": 3 133 | }, 134 | "file_extension": ".py", 135 | "mimetype": "text/x-python", 136 | "name": "python", 137 | "nbconvert_exporter": "python", 138 | "pygments_lexer": "ipython3", 139 | "version": "3.7.13" 140 | } 141 | }, 142 | "nbformat": 4, 143 | "nbformat_minor": 5 144 | } 145 | -------------------------------------------------------------------------------- /Module-3/Unit-2/age_deploy.prototxt: -------------------------------------------------------------------------------- 1 | name: "CaffeNet" 2 | input: "data" 3 | input_dim: 1 4 | input_dim: 3 5 | input_dim: 227 6 | input_dim: 227 7 | layers { 8 | name: "conv1" 9 | type: CONVOLUTION 10 | bottom: "data" 11 | top: "conv1" 12 | convolution_param { 13 | num_output: 96 14 | kernel_size: 7 15 | stride: 4 16 | } 17 | } 18 | layers { 19 | name: "relu1" 20 | type: RELU 21 | bottom: "conv1" 22 | top: "conv1" 23 | } 24 | layers { 25 | name: "pool1" 26 | type: POOLING 27 | bottom: "conv1" 28 | top: "pool1" 29 | pooling_param { 30 | pool: MAX 31 | kernel_size: 3 32 | stride: 2 33 | } 34 | } 35 | layers { 36 | name: "norm1" 37 | type: LRN 38 | bottom: "pool1" 39 | top: "norm1" 40 | lrn_param { 41 | local_size: 5 42 | alpha: 0.0001 43 | beta: 0.75 44 | } 45 | } 46 | layers { 47 | name: "conv2" 48 | type: CONVOLUTION 49 | bottom: "norm1" 50 | top: "conv2" 51 | convolution_param { 52 | num_output: 256 53 | pad: 2 54 | kernel_size: 5 55 | } 56 | } 57 | layers { 58 | name: "relu2" 59 | type: RELU 60 | bottom: "conv2" 61 | top: "conv2" 62 | } 63 | layers { 64 | name: "pool2" 65 | type: POOLING 66 | bottom: "conv2" 67 | top: "pool2" 68 | pooling_param { 69 | pool: MAX 70 | kernel_size: 3 71 | stride: 2 72 | } 73 | } 74 | layers { 75 | name: "norm2" 76 | type: LRN 77 | bottom: "pool2" 78 | top: "norm2" 79 | lrn_param { 80 | local_size: 5 81 | alpha: 0.0001 82 | beta: 0.75 83 | } 84 | } 85 | layers { 86 | name: "conv3" 87 | type: CONVOLUTION 88 | bottom: "norm2" 89 | top: "conv3" 90 | convolution_param { 91 | num_output: 384 92 | pad: 1 93 | kernel_size: 3 94 | } 95 | } 96 | layers{ 97 | name: "relu3" 98 | type: RELU 99 | bottom: "conv3" 100 | top: "conv3" 101 | } 102 | layers { 103 | name: "pool5" 104 | type: POOLING 105 | bottom: "conv3" 106 | top: "pool5" 107 | pooling_param { 108 | pool: MAX 109 | kernel_size: 3 110 | stride: 2 111 | } 112 | } 113 | layers { 114 | name: "fc6" 115 | type: INNER_PRODUCT 116 | bottom: "pool5" 117 | top: "fc6" 118 | inner_product_param { 119 | num_output: 512 120 | } 121 | } 122 | layers { 123 | name: "relu6" 124 | type: RELU 125 | bottom: "fc6" 126 | top: "fc6" 127 | } 128 | layers { 129 | name: "drop6" 130 | type: DROPOUT 131 | bottom: "fc6" 132 | top: "fc6" 133 | dropout_param { 134 | dropout_ratio: 0.5 135 | } 136 | } 137 | layers { 138 | name: "fc7" 139 | type: INNER_PRODUCT 140 | bottom: "fc6" 141 | top: "fc7" 142 | inner_product_param { 143 | num_output: 512 144 | } 145 | } 146 | layers { 147 | name: "relu7" 148 | type: RELU 149 | bottom: "fc7" 150 | top: "fc7" 151 | } 152 | layers { 153 | name: "drop7" 154 | type: DROPOUT 155 | bottom: "fc7" 156 | top: "fc7" 157 | dropout_param { 158 | dropout_ratio: 0.5 159 | } 160 | } 161 | layers { 162 | name: "fc8" 163 | type: INNER_PRODUCT 164 | bottom: "fc7" 165 | top: "fc8" 166 | inner_product_param { 167 | num_output: 8 168 | } 169 | } 170 | layers { 171 | name: "prob" 172 | type: SOFTMAX 173 | bottom: "fc8" 174 | top: "prob" 175 | } -------------------------------------------------------------------------------- /Module-3/Unit-2/gender_deploy.prototxt: -------------------------------------------------------------------------------- 1 | name: "CaffeNet" 2 | input: "data" 3 | input_dim: 10 4 | input_dim: 3 5 | input_dim: 227 6 | input_dim: 227 7 | layers { 8 | name: "conv1" 9 | type: CONVOLUTION 10 | bottom: "data" 11 | top: "conv1" 12 | convolution_param { 13 | num_output: 96 14 | kernel_size: 7 15 | stride: 4 16 | } 17 | } 18 | layers { 19 | name: "relu1" 20 | type: RELU 21 | bottom: "conv1" 22 | top: "conv1" 23 | } 24 | layers { 25 | name: "pool1" 26 | type: POOLING 27 | bottom: "conv1" 28 | top: "pool1" 29 | pooling_param { 30 | pool: MAX 31 | kernel_size: 3 32 | stride: 2 33 | } 34 | } 35 | layers { 36 | name: "norm1" 37 | type: LRN 38 | bottom: "pool1" 39 | top: "norm1" 40 | lrn_param { 41 | local_size: 5 42 | alpha: 0.0001 43 | beta: 0.75 44 | } 45 | } 46 | layers { 47 | name: "conv2" 48 | type: CONVOLUTION 49 | bottom: "norm1" 50 | top: "conv2" 51 | convolution_param { 52 | num_output: 256 53 | pad: 2 54 | kernel_size: 5 55 | } 56 | } 57 | layers { 58 | name: "relu2" 59 | type: RELU 60 | bottom: "conv2" 61 | top: "conv2" 62 | } 63 | layers { 64 | name: "pool2" 65 | type: POOLING 66 | bottom: "conv2" 67 | top: "pool2" 68 | pooling_param { 69 | pool: MAX 70 | kernel_size: 3 71 | stride: 2 72 | } 73 | } 74 | layers { 75 | name: "norm2" 76 | type: LRN 77 | bottom: "pool2" 78 | top: "norm2" 79 | lrn_param { 80 | local_size: 5 81 | alpha: 0.0001 82 | beta: 0.75 83 | } 84 | } 85 | layers { 86 | name: "conv3" 87 | type: CONVOLUTION 88 | bottom: "norm2" 89 | top: "conv3" 90 | convolution_param { 91 | num_output: 384 92 | pad: 1 93 | kernel_size: 3 94 | } 95 | } 96 | layers{ 97 | name: "relu3" 98 | type: RELU 99 | bottom: "conv3" 100 | top: "conv3" 101 | } 102 | layers { 103 | name: "pool5" 104 | type: POOLING 105 | bottom: "conv3" 106 | top: "pool5" 107 | pooling_param { 108 | pool: MAX 109 | kernel_size: 3 110 | stride: 2 111 | } 112 | } 113 | layers { 114 | name: "fc6" 115 | type: INNER_PRODUCT 116 | bottom: "pool5" 117 | top: "fc6" 118 | inner_product_param { 119 | num_output: 512 120 | } 121 | } 122 | layers { 123 | name: "relu6" 124 | type: RELU 125 | bottom: "fc6" 126 | top: "fc6" 127 | } 128 | layers { 129 | name: "drop6" 130 | type: DROPOUT 131 | bottom: "fc6" 132 | top: "fc6" 133 | dropout_param { 134 | dropout_ratio: 0.5 135 | } 136 | } 137 | layers { 138 | name: "fc7" 139 | type: INNER_PRODUCT 140 | bottom: "fc6" 141 | top: "fc7" 142 | inner_product_param { 143 | num_output: 512 144 | } 145 | } 146 | layers { 147 | name: "relu7" 148 | type: RELU 149 | bottom: "fc7" 150 | top: "fc7" 151 | } 152 | layers { 153 | name: "drop7" 154 | type: DROPOUT 155 | bottom: "fc7" 156 | top: "fc7" 157 | dropout_param { 158 | dropout_ratio: 0.5 159 | } 160 | } 161 | layers { 162 | name: "fc8" 163 | type: INNER_PRODUCT 164 | bottom: "fc7" 165 | top: "fc8" 166 | inner_product_param { 167 | num_output: 2 168 | } 169 | } 170 | layers { 171 | name: "prob" 172 | type: SOFTMAX 173 | bottom: "fc8" 174 | top: "prob" 175 | } -------------------------------------------------------------------------------- /Module-3/Unit-2/opencv_face_detector_uint8.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-3/Unit-2/opencv_face_detector_uint8.pb -------------------------------------------------------------------------------- /Module-3/Unit-3/face-detection-retail-0004.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Code-Unnati/Advance-Course/37a8cc36809d96f0b242fc23a1ed0027a5260239/Module-3/Unit-3/face-detection-retail-0004.bin -------------------------------------------------------------------------------- /Module-3/Unit-3/face_detection.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | MODEL_FPATH = "face-detection-retail-0004.bin" 4 | ARCH_FPATH = "face-detection-retail-0004.xml" 5 | CONF_THRESH = 0.5 # confidence of each object detected 6 | 7 | net = cv2.dnn.readNet(ARCH_FPATH, MODEL_FPATH) 8 | 9 | net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE) 10 | net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD) 11 | 12 | vid_cap = cv2.VideoCapture(0) 13 | if not vid_cap.isOpened(): 14 | raise IOError("Webcam cannot be opened!") 15 | 16 | while True: 17 | # Capture frames 18 | ret, frame = vid_cap.read() 19 | 20 | # Prepare input blob and perform inference 21 | blob = cv2.dnn.blobFromImage(frame, size=(300, 300), ddepth=cv2.CV_8U) 22 | net.setInput(blob) 23 | out = net.forward() 24 | 25 | # Draw detected faces 26 | for detect in out.reshape(-1, 7): 27 | conf = float(detect[2]) 28 | xmin = int(detect[3] * frame.shape[1]) 29 | ymin = int(detect[4] * frame.shape[0]) 30 | xmax = int(detect[5] * frame.shape[1]) 31 | ymax = int(detect[6] * frame.shape[0]) 32 | 33 | if conf > CONF_THRESH: 34 | cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0), thickness=2) 35 | 36 | cv2.imshow('Input', frame) 37 | 38 | # Press "ESC" key to stop webcam 39 | if cv2.waitKey(1) == 27: 40 | break 41 | 42 | # Release video capture object and close the window 43 | vid_cap.release() 44 | cv2.destroyAllWindows() 45 | cv2.waitKey(1) -------------------------------------------------------------------------------- /Module-3/Unit-4/.ipynb_checkpoints/Lab 1 classroom exercise Gpt using Python-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "952c0959", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 3, 14 | "id": "024696e7", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "Requirement already satisfied: transformers in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (4.30.2)\n", 22 | "Requirement already satisfied: torch in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (1.13.1)\n", 23 | "Requirement already satisfied: requests in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (2.28.1)\n", 24 | "Requirement already satisfied: packaging>=20.0 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (21.3)\n", 25 | "Requirement already satisfied: regex!=2019.12.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (2024.4.16)\n", 26 | "Requirement already satisfied: importlib-metadata in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (4.11.3)\n", 27 | "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (6.0)\n", 28 | "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.13.3)\n", 29 | "Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.16.4)\n", 30 | "Requirement already satisfied: numpy>=1.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (1.21.4)\n", 31 | "Requirement already satisfied: filelock in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (3.12.2)\n", 32 | "Requirement already satisfied: tqdm>=4.27 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (4.65.0)\n", 33 | "Requirement already satisfied: safetensors>=0.3.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.4.3)\n", 34 | "Requirement already satisfied: typing-extensions in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from torch) (4.7.1)\n", 35 | "Requirement already satisfied: fsspec in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from huggingface-hub<1.0,>=0.14.1->transformers) (2022.11.0)\n", 36 | "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from packaging>=20.0->transformers) (3.0.9)\n", 37 | "Requirement already satisfied: colorama in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from tqdm>=4.27->transformers) (0.4.6)\n", 38 | "Requirement already satisfied: zipp>=0.5 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from importlib-metadata->transformers) (3.6.0)\n", 39 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (2022.6.15)\n", 40 | "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (3.4)\n", 41 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (1.26.12)\n", 42 | "Requirement already satisfied: charset-normalizer<3,>=2 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (2.1.1)\n", 43 | "Note: you may need to restart the kernel to use updated packages.\n" 44 | ] 45 | }, 46 | { 47 | "name": "stderr", 48 | "output_type": "stream", 49 | "text": [ 50 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 51 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 52 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 53 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 54 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 55 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "pip install transformers torch\n" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "id": "7990b99d", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stderr", 71 | "output_type": "stream", 72 | "text": [ 73 | "C:\\Users\\Hp\\Anaconda3\\envs\\idp\\lib\\site-packages\\huggingface_hub\\file_download.py:133: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\Hp\\.cache\\huggingface\\hub. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n", 74 | "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n", 75 | " warnings.warn(message)\n" 76 | ] 77 | }, 78 | { 79 | "data": { 80 | "application/vnd.jupyter.widget-view+json": { 81 | "model_id": "d415f9beac5440b194a0d02a8429c144", 82 | "version_major": 2, 83 | "version_minor": 0 84 | }, 85 | "text/plain": [ 86 | "Downloading model.safetensors: 0%| | 0.00/548M [00:00=20.0 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (21.3)\n", 25 | "Requirement already satisfied: regex!=2019.12.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (2024.4.16)\n", 26 | "Requirement already satisfied: importlib-metadata in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (4.11.3)\n", 27 | "Requirement already satisfied: pyyaml>=5.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (6.0)\n", 28 | "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.13.3)\n", 29 | "Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.16.4)\n", 30 | "Requirement already satisfied: numpy>=1.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (1.21.4)\n", 31 | "Requirement already satisfied: filelock in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (3.12.2)\n", 32 | "Requirement already satisfied: tqdm>=4.27 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (4.65.0)\n", 33 | "Requirement already satisfied: safetensors>=0.3.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from transformers) (0.4.3)\n", 34 | "Requirement already satisfied: typing-extensions in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from torch) (4.7.1)\n", 35 | "Requirement already satisfied: fsspec in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from huggingface-hub<1.0,>=0.14.1->transformers) (2022.11.0)\n", 36 | "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from packaging>=20.0->transformers) (3.0.9)\n", 37 | "Requirement already satisfied: colorama in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from tqdm>=4.27->transformers) (0.4.6)\n", 38 | "Requirement already satisfied: zipp>=0.5 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from importlib-metadata->transformers) (3.6.0)\n", 39 | "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (2022.6.15)\n", 40 | "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (3.4)\n", 41 | "Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (1.26.12)\n", 42 | "Requirement already satisfied: charset-normalizer<3,>=2 in c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages (from requests->transformers) (2.1.1)\n", 43 | "Note: you may need to restart the kernel to use updated packages.\n" 44 | ] 45 | }, 46 | { 47 | "name": "stderr", 48 | "output_type": "stream", 49 | "text": [ 50 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 51 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 52 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 53 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 54 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n", 55 | "WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\hp\\anaconda3\\envs\\idp\\lib\\site-packages)\n" 56 | ] 57 | } 58 | ], 59 | "source": [ 60 | "pip install transformers torch\n" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 4, 66 | "id": "7990b99d", 67 | "metadata": {}, 68 | "outputs": [ 69 | { 70 | "name": "stderr", 71 | "output_type": "stream", 72 | "text": [ 73 | "C:\\Users\\Hp\\Anaconda3\\envs\\idp\\lib\\site-packages\\huggingface_hub\\file_download.py:133: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\Hp\\.cache\\huggingface\\hub. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n", 74 | "To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n", 75 | " warnings.warn(message)\n" 76 | ] 77 | }, 78 | { 79 | "data": { 80 | "application/vnd.jupyter.widget-view+json": { 81 | "model_id": "d415f9beac5440b194a0d02a8429c144", 82 | "version_major": 2, 83 | "version_minor": 0 84 | }, 85 | "text/plain": [ 86 | "Downloading model.safetensors: 0%| | 0.00/548M [00:00