My name is Ryosuke Kamei and I am an IT consultant based on the idea of "gentle IT"! Currently, in my work, I am doing upstream processes focusing on requirements analysis and requirements definition, but I also write programs! As part of our friendly IT activities, we will introduce "Raspberry Pi 3" (commonly known as Raspberry Pi), which has the philosophy of "providing inexpensive PCs that can be programmed for education"! This time, we will control the motor! If you apply this, you will have a radio-controlled model with Raspberry Pi!
Wiring diagram is [Razpai Magazine-June 2016 issue Special feature 1 Akiba's popular parts Wiring diagram best 17 ⑨ Motor can be rotated freely](https://www.amazon.co.jp/ Razpai Magazine-2016 June issue-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? -22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) As it is.
The photo is as follows. Is it quite difficult to understand?
I made a video for the time being. Isn't this also difficult to understand ...
I tried to wake it up in the text. Wiring seen from Raspberry Pi
--Raspberry Pi 2nd pin (5V) --Motor driver 7th (Vcc) --Raspberry Pi 16th pin (GPIO23) --Motor driver 5th (IN1) --Raspberry Pi 18th pin (GPIO24) --Motor driver 6th (IN2) --Raspberry Pi 6th pin (GND) --Motor driver 1st (GND) --Battery minus side
Wiring seen from the motor driver
--Motor driver No. 4 (Vref) --Resistance 5.1kΩ --Motor driver No. 8 (Vs) --Motor driver No. 8 (Vs) --Battery plus side --Motor driver No. 2 (OUT1) --DC motor --Motor driver No. 10 (OUT2) --DC motor
Other
--Condenser --DC motor --Condenser --DC motor
The program is [Razpai Magazine-June 2016 Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 ⑨ Motor can be rotated freely](https://www.amazon.co.jp/ Razpai Magazine-June 2016 No.-Nikkei BP Personal Computer Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? = 18fd04738627edef8d6fffd6c9b8f9c2) is changed so that arguments can be entered.
The source is uploaded to GitHub, so please use it as you like.
Clone with git
$ git clone https://github.com/RyosukeKamei/raspberrypi3.git
motor.py
#Library to control GPIO
import wiringpi
#Timer library
import time
#Get arguments
import sys
#GPIO terminal settings
motor1_pin = 23
motor2_pin = 24
#argument
param = sys.argv
#1st argument
# go :rotation
# back :back reverse
# break :brake
order = param[1]
#Second argument Seconds
second = int(param[2])
#Set GPIO output mode to 1
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode( motor1_pin, 1 )
wiringpi.pinMode( motor2_pin, 1 )
if order == "go":
if second == 0:
print("Break 0 command to stop rotation!")
else:
print(str(second)+"Rotate seconds")
wiringpi.digitalWrite( motor1_pin, 1 )
wiringpi.digitalWrite( motor2_pin, 0 )
time.sleep(second)
elif order == "back":
if second == 0:
print("Break 0 command to stop reverse rotation!")
else:
print(str(second)+"Second reverse rotation")
wiringpi.digitalWrite( motor1_pin, 0 )
wiringpi.digitalWrite( motor2_pin, 1 )
time.sleep(second)
#If the second argument is 0, do not brake
#If the first argument is break, brake
if order == "break" or second != 0:
print("brake!")
wiringpi.digitalWrite( motor1_pin, 1 )
wiringpi.digitalWrite( motor2_pin, 1 )
I recorded the video of how it is moving.
The program has the following format: It is necessary to enter both the first argument and the second argument.
program
$ sudo python3 motor.py [1st argument:order] [2nd argument:The number of seconds]
The first argument is
There are three. Please enter one. (Actually, other than these three, message display and control are required, but it will be omitted because the program will be complicated.)
The second argument is the number of seconds. If you enter 1, it will rotate for 1 second. If you enter 0, it will rotate until it is "breaked" by the next command.
10 seconds rotation
$ sudo python3 motor.py go 10
Continue to rotate
$ sudo python3 motor.py go 0
10 seconds rotation
$ sudo python3 motor.py back 10
Continue to rotate
$ sudo python3 motor.py back 0
brake
$ sudo python3 motor.py break 0
Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac
Install Docker on RaspberryPi3 Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Easy construction] Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Trial and error]
Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!
Programming with Node-RED programming with Raspberry Pi 3 and programming normally Light the LED with python on Raspberry Pi 3 (Hello World) Detect switch status on Raspberry Pi 3 Run a servo motor using python on Raspberry Pi 3 Control the motor with a motor driver using python on Raspberry Pi 3! Detect slide switch using python on Raspberry Pi 3! Detect magnet switch using python on Raspberry Pi 3! Detect temperature using python on Raspberry Pi 3! Sound the buzzer using python on Raspberry Pi 3! Detect analog signals with A / D converter using python on Raspberry Pi 3! Detect "brightness" using python on Raspberry Pi 3! Detect "temperature (using A / D converter)" using python on Raspberry Pi 3! Output to "7-segment LED" using python on Raspberry Pi 3!
Coding rules "Let's write gentle code" (FuelPHP) Naming convention "Friendly to yourself, team-friendly, and unseen members after 3 months"
PHP environment + Eclipse is linked to Apache using Docker Building FuelPHP development environment using Docker Create CRUD skeleton using initial settings of FuelPHP development environment using Docker and scaffold FuelPHP database migration