def __init__( self ): self.auth1 = tweepy.auth.OAuthHandler(config.consumer_key,config.consumer_secret) self.auth1.set_access_token(config.access_token,config.access_token_secret) self.api = tweepy.API(self.auth1) self.board = pymcu.mcuModule() self.board.pwmOff(1)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.left, QtCore.SIGNAL("pressed()"), self.move_left) QtCore.QObject.connect(self.ui.right, QtCore.SIGNAL("pressed()"), self.move_right) self.mcu = pymcu.mcuModule() self._prepare_servo()
def __init__(self): try: import pymcu except ImportError: raise ImportError('pingo.pymcuboard.Pymcuboard requires pymcu installed') super(Pymcuboard, self).__init__() self.board = pymcu.mcuModule() self._add_pins( [DigitalPin(self, location) for location in range(1, 20)] + [AnalogPin(self, 'A%s' % location, resolution=10) for location in range(1, 7)] + [PwmPin(self, 'P%s' % location) for location in range(1, 6) ] )
# mb.pwmOff(1) # mb.pwmDuty(1, 0) # pin.resetTriggerCount() # mb.pinToggle([11,12]) # while pin.triggerCount !=20 : # pin.trigger() #mb.pausems(1) mb.pinLow([11,12]) mb.pwmOff(1) print pin.triggerCount def countImpulse(mb): mb.digitalState(1, 'input') count=0 state=mb.digitalRead(1) while True : newState = mb.digitalRead(1) if state!=newState : count=count+1 print 'count=%i' % count state=newState if __name__ == '__main__': mb = pymcu.mcuModule() # Initialize mb (My Board) with mcuModule Class Object - Find first available pymcu hardware module. checkReadSpeed(mb) stop(mb) try: rotate(mb) finally: stop(mb)
#!/usr/bin/env python # Requires pwmForm.py for QT Gui form import sys from PyQt4 import QtCore, QtGui # Import pyqt from pwmForm import Ui_Form # Import our cutstom pwmForm import pymcu # Import pymcu mb = pymcu.mcuModule() # Find and initialize first found pymcu board. mb.pwmOn(1) # Turn on PWM1 class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.quit) QtCore.QObject.connect(self.ui.horizontalSlider, QtCore.SIGNAL("valueChanged(int)"), self.pwmUpdate) def pwmUpdate(self): mb.pwmDuty(1, self.ui.horizontalSlider.value()) def quit(self): sys.exit(0)
def __init__(self, pin, mode): self.pin = pin self.mode = mode self.mb = pymcu.mcuModule() self._write = lambda cmd: self.mb.serialWrite(self.pin, self.mode, cmd)
#!/usr/bin/env python # -*- coding: utf-8 -*- import pymcu # Import pyMCU module mb = pymcu.mcuModule() # Create a new pyMCU class object from first found pyMCU board # This will move a typical servo to one extent of it's range # (or on a continuous servo will cause it to spin at full speed in one direction) mb.pulseOut(1,500,50) # Generate a 500 ms pulse on Digital Pin 1, repeat 50 times # This will move a typical servo the other extent of it's range # (or on a continuous servo will cause it to spin at full speed in the other direction) mb.pulseOut(1,2000,50) # generate a 2000 ms pulse on Digital Pin 1, repeat 50 times # This will move the servo to one extent then step by 20 ms pulse length back to the other end of the range # (or on a continuous servo will spin at full speed in one direction, slow down, come to a stop, # then speed back up and spin at full speed in the other direction) for x in range(500,2000,20): mb.pulseOut(1,x,5) mb.pausems(10)
#!/usr/bin/env python2 import pymcu import time mb = pymcu.mcuModule() pin = 11 mode = 2 while True: mb.serialWrite(pin, mode, 'r') time.sleep(0.01)
""" Simple pyMCU example using the ChipCap2 Temperature & Humidity Sensor Gets current Low and High Alarm values from EEPROM and prints them Sets New Low and High Alarm Values Then goes into an endless loop to display the Humidity and Temperature every 5 seconds """ import sys #sys.path.append('H:/GitHub/ChipCap2/Python/Library') # set your path to the ChipCap2 lib if you didn't copy it to your site-packages folder import pymcu # import pyMCU library import CFF_ChipCap2 # import ChipCap2 library mb = pymcu.mcuModule() # init pyMCU class ChipCap2_i2cAddr = 0x28 ChipCap2_PowerPin = 1 ChipCap2_ReadyPin = 2 ChipCap2_AlarmLowPin = 3 ChipCap2_AlarmHighPin = 5 cc2 = CFF_ChipCap2.CFF_ChipCap2(mb, ChipCap2_i2cAddr, ChipCap2_PowerPin, ChipCap2_ReadyPin, ChipCap2_AlarmLowPin, ChipCap2_AlarmHighPin) # init ChipCap2 class and set all init variables # Alternatively you could just do: cc2 = CFF_ChipCap2.CFF_ChipCap2(mb) if you are using all the default settings cc2.power(1) # turn ChipCap2 power on mb.pausems(500) cc2.startCommandMode() # put ChipCap2 in Command Mode if cc2.status == CFF_ChipCap2.CCF_CHIPCAP2_STATUS_COMMANDMODE: # check to make sure it went into command mode print "ChipCap2 is now in command mode" print "Get Current Alarm Values"
mb.pausems(500) return tt class ds1821(): def __init__(self, pin, modecmd, readcmd): self.pin = pin self.modecmd = modecmd self.readcmd = readcmd def start(self): mb.owWrite(self.pin, 1, self.modecmd) def check(self): mb.owRead(self.pin,5,1) def read(self): pass if __name__ == "__main__": #mb = pymcu.mcuModule(port = 'COM9', baudrate = 9600) mb = pymcu.mcuModule(port = '/dev/ttyUSB0', baudrate = 9600) mb.mcuSetBaudRate(2) # print mb.mcuInfo() initLCD(sleep = 1) startTemp(5, 0xEE) # start DS1821 conversion while mb.active: displayTemp(line = 1, sleep = 0.1, temp = getTemp()) exit()
#!/usr/bin/env python # Requires pwmForm.py for QT Gui form import sys from PyQt4 import QtCore, QtGui # Import pyqt from pwmForm import Ui_Form # Import our cutstom pwmForm import pymcu # Import pymcu mb = pymcu.mcuModule() # Find and initialize first found pymcu board. mb.pwmOn(1) # Turn on PWM1 class MyForm(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_Form() self.ui.setupUi(self) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.quit ) QtCore.QObject.connect(self.ui.horizontalSlider, QtCore.SIGNAL("valueChanged(int)"), self.pwmUpdate) def pwmUpdate(self): mb.pwmDuty(1, self.ui.horizontalSlider.value()) def quit(self): sys.exit(0) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) myapp = MyForm() myapp.show()
#!/usr/bin/env python import pymcu mb = pymcu.mcuModule() # There are 8 pins on the input keypad # The default for the pymcu is digital pins are set to output # we need to set them to input so we can read from the keypad for pin in xrange(1, 9): mb.digitalState(pin, 'input') print pin # Row 1 (1,2,3,A) pin 8 # Row 2 (4,5,6,B) pin 7 # Row 3 (7,8,9,C) pin 6 # Row 4 (*,0,#,D) pin 5 # Col 1 (1,4,7,*) pin 4 # Col 2 (2,5,8,0) pin 3 # Col 3 (3,6,9,#) pin 2 # Col 4 (A,B,C,D) pin 1 # So if 5 is pressed the pins should be 7, 3 while True: for row_pin in xrange(5, 9): for col_pin in xrange(1, 5): if mb.digitalRead(row_pin) and mb.digitalRead(col_pin): print "The pressed row {0} and col {1}".format(row_pin, col_pin)
import pymcu # Import pyMCU module mb = pymcu.mcuModule( ) # Create a new pyMCU class object from first found pyMCU board # Play DTMF Tones for phone number (123)-456-7890 myboard.dtmfOut(1, 1) myboard.dtmfOut(1, 2) myboard.dtmfOut(1, 3) myboard.dtmfOut(1, 4) myboard.dtmfOut(1, 5) myboard.dtmfOut(1, 6) myboard.dtmfOut(1, 7) myboard.dtmfOut(1, 8) myboard.dtmfOut(1, 9) myboard.dtmfOut(1, 0)
import pymcu import time import pywapi mb = pymcu.mcuModule() # Initialize mcu find first available module mb.lcd() # Initialize the LCD yahoo_result = pywapi.get_weather_from_yahoo('10001') # Use Google as weather source with zip code 10001 mb.lcd(1,yahoo_result['condition']['text']) # Display current conditions on first line of LCD mb.pausems(100) # Small delay between next LCD command mb.lcd(2,'Temp ' + str(int(yahoo_result['condition']['temp']) * 9.0 / 5.0 + 32) + ' F') # Display Temperature on second line of LCD
tt = None if t >> 7 == 1: # negative r = t ^ 0xFF # bit inversion OR tt = r + 1 # add 1 else: # positive tt = t startTemp(5, 0xEE) mb.pausems(500) return tt if __name__ == "__main__": ##################################################### # INIT MODULE ##################################################### mb = pymcu.mcuModule(port="COM9", baudrate=9600) mb.mcuSetBaudRate(2) print mb.mcuInfo() ##################################################### # INIT LED AND BUTTONS ##################################################### mb.pinLow(1) # init LED on pin 1 mb.digitalState(10, "input") # init button on pin 10 ##################################################### # INIT LCD ##################################################### initLCD(sleep=1) #####################################################
global ac1 global ac2 global ac3 global ac4 global ac5 global ac6 global b1 global b2 global mb global mc global md global b5 temperature = 0 pressure = 0 myboard = pymcu.mcuModule() # Initialize mcu find first available module def unsigned(n): return n & 0xFFFF def bmp085ReadInt(address): data1 = myboard.i2cRead(0xEF, address, 2) dt = (data1[0] << 8) | data1[1] return dt def byte2word(byte1, byte2): dt = (byte1 << 8) | byte2 return dt
import pymcu # Import the pymcu module mb = pymcu.mcuModule( ) # Initialize mb (My Board) with mcuModule Class Object - Find first available pymcu hardware module. for x in range(1, 25): # Create a for next loop with 25 iterations mb.pinHigh(1) # Set D1 pin High (LED On) mb.pausems(500) # Sleep for half a second mb.pinLow(1) # Set D1 pin Low (LED Off) mb.pausems(500) # Sleep for half a second
""" Simple pyMCU example using the ChipCap2 Temperature & Humidity Sensor Gets current Low and High Alarm values from EEPROM and prints them Sets New Low and High Alarm Values Then goes into an endless loop to display the Humidity and Temperature every 5 seconds """ import sys # sys.path.append('H:/GitHub/ChipCap2/Python/Library') # set your path to the ChipCap2 lib if you didn't copy it to your site-packages folder import pymcu # import pyMCU library import CFF_ChipCap2 # import ChipCap2 library mb = pymcu.mcuModule() # init pyMCU class ChipCap2_i2cAddr = 0x28 ChipCap2_PowerPin = 1 ChipCap2_ReadyPin = 2 ChipCap2_AlarmLowPin = 3 ChipCap2_AlarmHighPin = 5 cc2 = CFF_ChipCap2.CFF_ChipCap2( mb, ChipCap2_i2cAddr, ChipCap2_PowerPin, ChipCap2_ReadyPin, ChipCap2_AlarmLowPin, ChipCap2_AlarmHighPin ) # init ChipCap2 class and set all init variables # Alternatively you could just do: cc2 = CFF_ChipCap2.CFF_ChipCap2(mb) if you are using all the default settings cc2.power(1) # turn ChipCap2 power on mb.pausems(500) cc2.startCommandMode() # put ChipCap2 in Command Mode if cc2.status == CFF_ChipCap2.CCF_CHIPCAP2_STATUS_COMMANDMODE: # check to make sure it went into command mode