def main (): gpio.setup () gpio.pinMode (LED, gpio.OUTPUT) while True: print("HIGH"); gpio.digitalWrite (LED, gpio.HIGH) time.sleep(0.5) print("LOW"); gpio.digitalWrite (LED, gpio.LOW) time.sleep(0.5) return 0
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import sys from time import sleep from wiringX import gpio gpio.setup() gpio.pinMode(gpio.PIN0, gpio.OUTPUT) print gpio.platform() print gpio.I2CRead(0x10) try: while True: gpio.digitalWrite(gpio.PIN0, gpio.LOW) sleep(1) gpio.digitalWrite(gpio.PIN0, gpio.HIGH) sleep(1) except KeyboardInterrupt: pass
gpio.setup(gpio.RASPBERRYPI3) # set pins # GPIO.1 PIN12 # wiringX code just like wiringPi FAN_GPIO = gpio.PIN1 INFRARED_GPIO = gpio.PIN0 # PIN21-PIN28 -> D0-D7 screen_data = [29, 28, 27, 26, 25, 24, 23, 22] # 29 in pin map screen_led = 21 screen_cs = gpio.PIN2 screen_rs = gpio.PIN3 # set GPIOs gpio.pinMode(FAN_GPIO, gpio.PINMODE_OUTPUT) gpio.pinMode(INFRARED_GPIO, gpio.PINMODE_INPUT) gpio.pinMode(screen_led, gpio.PINMODE_OUTPUT) gpio.pinMode(screen_cs, gpio.PINMODE_OUTPUT) gpio.pinMode(screen_rs, gpio.PINMODE_OUTPUT) # init GPIOs gpio.digitalWrite(FAN_GPIO, gpio.LOW) for pin in screen_data: gpio.pinMode(pin, gpio.PINMODE_OUTPUT) gpio.digitalWrite(pin, gpio.LOW) gpio.digitalWrite(screen_led, gpio.LOW) gpio.digitalWrite(screen_cs, gpio.HIGH) gpio.digitalWrite(screen_rs, gpio.LOW) # sensor data keys
#!/usr/bin/env python # # Copyright (c) 2016 CurlyMo <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # import os import sys from time import sleep from wiringX import gpio gpio.setup(gpio.RASPBERRYPI1B2) gpio.pinMode(gpio.PIN0, gpio.PINMODE_OUTPUT) try: while True: gpio.digitalWrite(gpio.PIN0, gpio.HIGH) sleep(1) gpio.digitalWrite(gpio.PIN0, gpio.LOW) sleep(1) except KeyboardInterrupt: pass
# # Copyright (c) 2016 CurlyMo <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # import os import sys from time import sleep from wiringX import gpio gpio.setup(gpio.RASPBERRYPI1B2); gpio.pinMode(gpio.PIN0, gpio.PINMODE_OUTPUT); gpio.pinMode(gpio.PIN1, gpio.PINMODE_INPUT); try: while True: print "Writing to pin 0: High"; gpio.digitalWrite(gpio.PIN0, gpio.HIGH); print "Reading from pin 1: "+str(gpio.digitalRead(gpio.PIN1)); sleep(1); print "Writing to pin 0: Low"; gpio.digitalWrite(gpio.PIN0, gpio.LOW); print "Reading from pin 1: "+str(gpio.digitalRead(gpio.PIN1)); sleep(1); except KeyboardInterrupt: pass
#!/usr/bin/env python import sys, time, math from wiringX import gpio gpio.setup () coil_A_1_pin = 21 coil_A_2_pin = 22 coil_B_1_pin = 23 coil_B_2_pin = 24 gpio.pinMode (coil_A_1_pin, gpio.OUTPUT) gpio.pinMode (coil_A_2_pin, gpio.OUTPUT) gpio.pinMode (coil_B_1_pin, gpio.OUTPUT) gpio.pinMode (coil_B_2_pin, gpio.OUTPUT) def forward (delay, steps): for i in range(0, steps): setStep (1, 0, 1, 0) time.sleep (delay) setStep (0, 1, 1, 0) time.sleep (delay) setStep (0, 1, 0, 1) time.sleep (delay) setStep (1, 0, 0, 1) time.sleep (delay) def backwards (delay, steps): for i in range(0, steps): setStep (1, 0, 0, 1) time.sleep (delay)
import requests import traceback if os.system('w -V'): exit(1) if os.system('vmstat -V'): exit(1) if os.system('cat /proc/cpuinfo| grep "processor"| wc -l'): exit(1) cores = int(subprocess.getoutput('cat /proc/cpuinfo| grep "processor"| wc -l')) # raspberrypi3 gpio.setup(gpio.RASPBERRYPI3) # GPIO.1 PIN12 # wiringX 编码同 wiringPi FAN_GPIO = gpio.PIN1 fan_status = 1 # set FAN_GPIO output gpio.pinMode(FAN_GPIO, gpio.PINMODE_OUTPUT) # init gpio.digitalWrite(FAN_GPIO, gpio.LOW) # 状态上报 URL = '127.0.0.1' PORT = 8080 NAME = 'raspi' # files tempFile = '/sys/class/thermal/thermal_zone0/temp' netFile = '/proc/net/dev' statusCom = 'w' ditlCom = 'vmstat' # 同样的错误半小时上报一次
#!/usr/bin/env python import sys, time, math from wiringX import gpio delay_b = 0.0000001 delay_e = 0.0004 delay_step = 0.0000008 out_pin = 22 gpio.setup () gpio.pinMode (out_pin, gpio.OUTPUT) def freq_out (delay): gpio.digitalWrite (out_pin, 1) time.sleep (delay) gpio.digitalWrite (out_pin, 0) time.sleep (delay) gpio.digitalWrite (out_pin, 1) time.sleep (delay) gpio.digitalWrite (out_pin, 0) time.sleep (delay) while True: delay = delay_b while delay < delay_e: freq_out (delay) delay += delay_step + delay / 1000.0 while delay > delay_b: freq_out (delay) delay -= delay_step + delay / 1000.0
# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import os import sys from time import sleep from wiringX import gpio gpio.setup(); gpio.pinMode(gpio.PIN0, gpio.OUTPUT); print gpio.platform(); print gpio.I2CRead(0x10); try: while True: gpio.digitalWrite(gpio.PIN0, gpio.LOW); sleep(1); gpio.digitalWrite(gpio.PIN0, gpio.HIGH); sleep(1); except KeyboardInterrupt: pass