Raspberry Pi Dolly by Raspberry Pi enthusiast itjoker (Implementation of Raspberry Pi Video trolley via Python socket communication)

Source: Internet
Author: User



This article by the Raspberry Pi Fan itjoker editor, reprint please indicate the source. I also have Sina blog is also Raspberry Pi fan itjoker may name less it ...


Required Materials: Raspberry Pi 2B or more than 2B, l2985n Drive board, a number of cable, battery and battery box, USB wireless card (free drive), USB camera (free drive). Required environment: Raspberry-gpio-python, and installation of Mjpg-streamer and the required environment. (There is not much to say, so that the future bloggers have time to increase the configuration of these environments) Okay, let's start our action. First, we start by connecting the l2985n In1,in2,in3,in4 with 4 female to the mother DuPont Line and then 11,12,13,15 the Gpio interface on the Raspberry Pi. (in1=12,in2=11,in3=13,in4=15) in1,in2 control is the Out1,out2 motor in3,in4 control is the OUT3,OUT4 motor (note that the motor wiring to the left side of the intersection with the left side, that is, the left front wheel and the left rear wheel cross-docking. And so on the right. The Raspberry Pi pin-pin diagram draws on the Raspberry Pi Lab. (Due to Bo Master lazy, detailed wiring method did not.) )




Once the wiring is complete, ssh into the Raspberry Pi Input command via the network method: (Copy the service-side code)
sudo nano start.py


Then ctrl+x enter y plus carriage return.



Enter the command:


sudo python start.py


Can run!


With the car service side control code: (Do not use for other purposes, please specify the reprint place and Raspberry Pi fan itjoker)
 
 
 1 ###########################################
 2 #Writer: Joker                                                                       #
 3 #Time: 2017.6.25                                                                   #
 4 ###########################################
 5 # -*- coding: utf-8 -*-
 6 import RPi.GPIO as GPIO
 7 from socket import *
 8 import time
 9 def t_init():
10         GPIO.setmode(GPIO.BOARD)
11         GPIO.setwarnings(False)
12         GPIO.setup(11,GPIO.OUT)
13         GPIO.setup(12,GPIO.OUT)
14         GPIO.setup(13,GPIO.OUT)
15         GPIO.setup(15,GPIO.OUT)
16 def t_stop():
17         GPIO.output(11, False)
18         GPIO.output(12, False)
19         GPIO.output(13, False)
20         GPIO.output(13, False)
21         GPIO.output(15, False)
22         time.sleep(1)
23         GPIO.cleanup()
24 def t_up():
25         t_init()
26         GPIO.output(11, True)
27         GPIO.output(12, False)
28         GPIO.output(13, True)
29         GPIO.output(15, False)
30         time.sleep(1)
31         GPIO.cleanup()
32  
33 def t_down():
34         t_init()
35         GPIO.output(11, False)
36         GPIO.output(12, True)
37         GPIO.output(13, False)
38         GPIO.output(15, True)
39         time.sleep(1)
40         GPIO.cleanup()
41  
42 def t_right():
43         t_init()
44         GPIO.output(11, False)
45         GPIO.output(12, True)
46         GPIO.output(13, True)
47         GPIO.output(15, False)
48         time.sleep(1)
49         GPIO.cleanup()
50 def t_left():
51         t_init()
52         GPIO.output(11, True)
53         GPIO.output(12, False)
54         GPIO.output(13, False)
55         GPIO.output(15, True)
56         time.sleep(1)
57         GPIO.cleanup()
58 #########################################################
59 #Writer: Joker                                                                       #
60 #Time: 2017.6.25                                                                   #
61 #########################################################
62 def commands (cmd):
63     if cmd == ‘d‘:
64       t_down()
65     elif cmd == ‘s‘:
66       t_stop()
67     elif cmd == ‘u‘:
68       t_up()
69     elif cmd == ‘l‘:
70       t_left()
71     elif cmd == ‘r‘:
72       t_right()
73 def execute(command):
74     print command
75     commands(command)
76 HOST =‘192.168.1.103‘ #the ip of raspberry pi
77 PORT = 8888           #the port of raspberry pi
78 s= socket(AF_INET, SOCK_STREAM)
79 s.bind((HOST, PORT))
80 s.listen(1000)
81 print (‘listening on 8888‘)
82 while 1:
83     conn, addr = s.accept()
84     print (‘Connected by:‘, addr)
85     while 1:
86             command= conn.recv(20).replace(‘\n‘,‘‘)
87             if command == ‘g‘:
88               conn.close
89               break
90             elif not command:break
91             a=bytearray(command)
92             execute(a) #command 
93     conn.close()
94 ############################################################################




Attached to the car computer control link: Link: http://pan.baidu.com/s/1jHXZvD0 password: 0lbv OK, then you can play your own production of video car needs Android control terminal can contact qq:649258008


Raspberry Pi Dolly by Raspberry Pi enthusiast itjoker (Implementation of Raspberry Pi Video trolley via Python socket communication)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.