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
def platform_detect(): """Detect if running on the Raspberry Pi or Beaglebone Black and return the platform type. Will return RASPBERRY_PI, BEAGLEBONE_BLACK, or UNKNOWN.""" # Handle Raspberry Pi pi = pi_version() if pi is not None: return RASPBERRY_PI # Handle Beaglebone Black # TODO: Check the Beaglebone Black /proc/cpuinfo value instead of reading # the platform. # regex stuff here # Handle Minnowboard # Assumption is that mraa is installed try: import mraa if mraa.getPlatformName() == "MinnowBoard MAX": return MINNOWBOARD except ImportError: pass # Handle wiringX compatible device # Assumption is that wiringX is installed try: from wiringX import gpio as wxgpio if wxgpio.setup() != 0: return WIRINGX except ImportError: pass # Couldn't figure out the platform, just return unknown. return UNKNOWN
# 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/>. # This example shows how to read temperature from the TMP102 I2C device # with WiringX in Python. It assumes that the sensor is configured at # the default I2C address of 0x48 from time import sleep from wiringX import gpio # setup wiringX gpio.setup(gpio.RASPBERRYPI1B2) # get a handle to the sensor, using the default I2C address fd = gpio.I2CSetup("/dev/i2c-0", 0x48) while True: # read from the default register data = gpio.I2CReadReg16(fd, 0x00) reg = [] # calculate the temperature reg.append((data >> 8) & 0xff) reg.append(data & 0xff) res = (reg[1] << 4) | (reg[0] >> 4) res = res * 0.0625 # print the result print(u'Temperature: ' + str(res) + u' C')
# 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
stopbits=stopbits, timeout=timeout) if not device.isOpen(): device.open() except Exception as e: print(e) exit(1) # needed commands 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(commands.getoutput('cat /proc/cpuinfo| grep "processor"| wc -l')) # raspberrypi3 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)
# 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/>. # This example shows how to read temperature from the TMP102 I2C device # with WiringX in Python. It assumes that the sensor is configured at # the default I2C address of 0x48 from time import sleep from wiringX import gpio # setup wiringX gpio.setup(gpio.RASPBERRYPI1B2) # get a handle to the sensor, using the default I2C address fd = gpio.I2CSetup("/dev/i2c-0", 0x48) while True: # read from the default register data = gpio.I2CReadReg16(fd, 0x00) reg = [] # calculate the temperature reg.append((data>>8)&0xff) reg.append(data&0xff) res = (reg[1] << 4) | (reg[0] >> 4) res = res * 0.0625 # print the result print(u'Temperature: ' + str(res) + u' C')
# 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
# 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/>. # This example shows how to read temperature from the TMP102 I2C device # with WiringX in Python. It assumes that the sensor is configured at # the default I2C address of 0x48 from time import sleep from wiringX import gpio # setup wiringX gpio.setup() # get a handle to the sensor, using the default I2C address fd = gpio.I2CSetup(0x48) while True: # read from the default register data = gpio.I2CReadReg16(fd, 0x00) reg = [] # calculate the temperature reg.append((data>>8)&0xff) reg.append(data&0xff) res = (reg[1] << 4) | (reg[0] >> 4) res = res * 0.0625 # print the result print(u'Temperature: ' + str(res) + u' C')