Skip to content

Commit 3ae01d1

Browse files
tech_talk_open_source_codes
1 parent d4b021e commit 3ae01d1

File tree

788 files changed

+65030
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

788 files changed

+65030
-0
lines changed
1.68 MB
Binary file not shown.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#written by Vikrant Thakur
2+
#license : open source
3+
import datetime
4+
import time
5+
import picamera
6+
import RPi.GPIO as GPIO
7+
from time import sleep
8+
import paho.mqtt.client as mqtt
9+
broker="localhost"
10+
decode="hello"
11+
GPIO.setmode(GPIO.BCM)
12+
Trig=14
13+
Echo=15
14+
Motor1= 18
15+
Motor2= 23
16+
Motor3= 24
17+
Motor4= 25
18+
GPIO.setup(Motor1,GPIO.OUT)
19+
GPIO.setup(Motor2,GPIO.OUT)
20+
GPIO.setup(Motor3,GPIO.OUT)
21+
GPIO.setup(Motor4,GPIO.OUT)
22+
GPIO.setup(Trig,GPIO.OUT)
23+
GPIO.setup(Echo,GPIO.IN)
24+
25+
try:
26+
27+
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
28+
while True:
29+
def on_connect(client, userdata, message, buf):
30+
time.sleep(1)
31+
print("log: "+ buf)
32+
def on_message(client,userdata,msg):
33+
topic=msg.topic
34+
print("message topic=",topic)
35+
globals()['decode']=str(msg.payload.decode("utf-8"))
36+
print("message received",decode)
37+
with picamera.PiCamera() as camera:
38+
camera.start_preview()
39+
camera.start_recording("/home/pi/"+ date + "video.h264")
40+
camera.wait_recording(30)
41+
camera.stop_recording()
42+
camera.stop_preview()
43+
client= mqtt.Client("vikrant")
44+
client.on_message = on_message
45+
print("connecting to broker ",broker)
46+
client.connect(broker)
47+
client.loop_start()
48+
client.subscribe("hello")
49+
time.sleep(1)
50+
client.loop_stop()
51+
client.disconnect()
52+
GPIO.output(Trig,False)
53+
time.sleep(1)
54+
GPIO.output(Trig,True)
55+
time.sleep(0.00001)
56+
GPIO.output(Trig,False)
57+
58+
while GPIO.input(Echo)==False:
59+
end=time.time()
60+
61+
while GPIO.input(Echo)==True:
62+
start=time.time()
63+
64+
sig_time=start-end
65+
distance=165*100*sig_time
66+
67+
if(distance>20.0):
68+
while(decode=='f'):
69+
70+
GPIO.output(Motor1,GPIO.LOW)
71+
GPIO.output(Motor2,GPIO.HIGH)
72+
GPIO.output(Motor3,GPIO.LOW)
73+
GPIO.output(Motor4,GPIO.HIGH)
74+
print('Move Forward')
75+
time.sleep(1)
76+
if(decode=='r'):
77+
78+
GPIO.output(Motor1,GPIO.LOW)
79+
GPIO.output(Motor2,GPIO.HIGH)
80+
GPIO.output(Motor3,GPIO.LOW)
81+
GPIO.output(Motor4,GPIO.LOW)
82+
time.sleep(2)
83+
print('Move Right')
84+
break
85+
86+
if(decode=='l'):
87+
88+
GPIO.output(Motor1,GPIO.LOW)
89+
GPIO.output(Motor2,GPIO.LOW)
90+
GPIO.output(Motor3,GPIO.LOW)
91+
GPIO.output(Motor4,GPIO.HIGH)
92+
time.sleep(2)
93+
print('Move left')
94+
break
95+
96+
if(decode=='s'):
97+
98+
GPIO.output(Motor1,GPIO.LOW)
99+
GPIO.output(Motor2,GPIO.LOW)
100+
GPIO.output(Motor3,GPIO.LOW)
101+
GPIO.output(Motor4,GPIO.LOW)
102+
time.sleep(0.1)
103+
print('Move Stop')
104+
print('distance from object is:() cm',format(distance))
105+
except KeyboardInterrupt:
106+
107+
GPIO.cleanup()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1. Install VLC player on the Laptop/PC
2+
2. Install MQTT broker on your laptop /PC
3+
3. The video will be processed through https at local server and it can be manually using laptop/PC keys
4+
4. Client is "Vikrant" and subscribe topic is "hello".
5+
5. Download picamera module in raspberry pi
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <Wire.h>
2+
#define DEVICE (0x53) //address of the module
3+
byte value[6]; //every axis return 2 bit data
4+
char output[512];
5+
void setup()
6+
{
7+
Wire.begin(); //12c protocol
8+
Serial.begin(9600); //UART protocol
9+
10+
Wire.beginTransmission(DEVICE);
11+
Wire.write(0x2D);
12+
Wire.write(0); //clear register
13+
Wire.beginTransmission(DEVICE);
14+
Wire.write(0x2D);
15+
Wire.write(16);
16+
Wire.beginTransmission(DEVICE);
17+
Wire.write(0x2D);
18+
Wire.write(8);
19+
Wire.endTransmission();
20+
}
21+
22+
void loop()
23+
{
24+
int xyz=0x32;
25+
int x[2],y[2],z[2];
26+
int values[6];
27+
Wire.beginTransmission(DEVICE);
28+
Wire.write(xyz);
29+
Wire.endTransmission();
30+
Wire.beginTransmission(DEVICE);
31+
Wire.requestFrom(DEVICE,6);
32+
int i=0;
33+
while(Wire.available())
34+
{
35+
values[i]= Wire.read();
36+
i++;
37+
}
38+
for(i=0;i++;i<2)
39+
{
40+
x[i]=values[i];
41+
Serial.println(x[i]);
42+
}
43+
delay(100);
44+
for(i=2;i++;i<=4)
45+
{
46+
y[i]=values[i];
47+
Serial.println(y[i]);
48+
}
49+
delay(100);
50+
for(i=4;i++;i<=6)
51+
{
52+
z[i]=values[i];
53+
Serial.println(z[i]);
54+
}
55+
delay(100);
56+
57+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "dht.h"
2+
#define dht_apin A2
3+
4+
dht DHT;
5+
6+
void setup()
7+
{
8+
9+
Serial.begin(9600);
10+
delay(500);
11+
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
12+
delay(1000);
13+
14+
}
15+
16+
void loop()
17+
{
18+
19+
20+
DHT.read11(dht_apin);
21+
22+
Serial.print("Current humidity = ");
23+
Serial.print(DHT.humidity);
24+
Serial.print("% ");
25+
Serial.print("temperature = ");
26+
Serial.print(DHT.temperature);
27+
Serial.println("C ");
28+
29+
delay(5000);
30+
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int PIR_output=5; // output of pir sensor
2+
int led=13; // led pin
3+
4+
void setup()
5+
{
6+
pinMode(PIR_output, INPUT);// setting pir output as arduino input
7+
pinMode(led, OUTPUT);//setting led as output
8+
Serial.begin(9600);//serial communication between arduino and pc
9+
}
10+
void loop()
11+
{
12+
if(digitalRead(PIR_output) == HIGH) // reading the data from the pir sensor
13+
{
14+
digitalWrite(13, HIGH); // setting led to high
15+
Serial.println("motion detected");
16+
17+
}
18+
else
19+
{
20+
digitalWrite(13, LOW); // setting led to low
21+
Serial.println("scanning");
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3+
4+
<storageModule moduleId="org.eclipse.cdt.core.settings">
5+
6+
<cconfiguration id="org.eclipse.cdt.core.default.config.1924795996">
7+
8+
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.1924795996" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
9+
10+
<externalSettings/>
11+
12+
<extensions/>
13+
14+
</storageModule>
15+
16+
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
17+
18+
</cconfiguration>
19+
20+
</storageModule>
21+
22+
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
23+
24+
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
25+
26+
</storageModule>
27+
28+
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
29+
30+
</cproject>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>blink</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.cdt.core.cBuilder</name>
10+
<triggers>clean,full,incremental,</triggers>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
</buildSpec>
15+
<natures>
16+
<nature>org.eclipse.cdt.core.cnature</nature>
17+
<nature>org.eclipse.cdt.core.ccnature</nature>
18+
<nature>com.espressif.idf.core.idfNature</nature>
19+
</natures>
20+
</projectDescription>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/home/vikrant/wifi/esp/esp-idf/components**",
8+
"/home/vikrant/wifi/esp/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/xtensa-esp32-elf/**"
9+
],
10+
"defines": [],
11+
"compilerPath": "/home/vikrantthakur/wifi/esp/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc",
12+
"cStandard": "c11",
13+
"cppStandard": "c++17",
14+
"intelliSenseMode": "clang-x64",
15+
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
16+
}
17+
],
18+
"version": 4
19+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"sdkconfig.h": "c",
4+
"task.h": "c",
5+
"freertos.h": "c"
6+
}
7+
}

0 commit comments

Comments
 (0)