コード例 #1
0
def serialWrite(*sendData):
    webiopi.setDebug()
    webiopi.debug("####################")

    #ttyACM0
    com = Serial(port="/dev/ttyACM0",
                 baudrate=9600,
                 bytesize=8,
                 parity='N',
                 stopbits=1,
                 timeout=1,
                 xonxoff=0,
                 rtscts=0,
                 writeTimeout=1000,
                 dsrdtr=None)
    #print(com.portstr)
    webiopi.debug(sendData)
    webiopi.debug(com.portstr)
    time.sleep(2)
    for bt in sendData:
        #com.write(str(bt).encode())
        com.write(bytes(chr(int(bt)).encode()))
    #com.write(bytes(sendData))
    #com.write(sendData)
    #com.write(b"\x04")
    #com.write("asdfghj")
    #com.write(b"\x05")

    readData = com.read(1000)
    #print(len(readData))
    webiopi.debug(len(readData))

    com.close()

    #f = open("data.txt", "w")
    #for var in readData:
    #	print("%s" % str(var))
    #	f.write("var=" + str(var))
    #f.close()
    webiopi.debug(sendData)
    #return [10, 20, 30, 40, 50]
    #return readData
    return ','.join(str(n) for n in readData)
    #return np.array(readData)
    #return 123


#abc = [10, 20, 30, 40, 50]
#serialWrite(abc)
コード例 #2
0
ファイル: robot.py プロジェクト: SpectralAngel/robot
import webiopi
from rrb2 import *
GPIO = webiopi.GPIO
webiopi.setDebug() 

robot = RRB2()


def setup():
    webiopi.debug("Setup")
#   GPIO.setFunction(4, GPIO.OUT)
#   GPIO.setFunction(25, GPIO.OUT)
    flash_lights()
    flash_lights()

def destroy():
    webiopi.debug("Destroy")
    flash_lights()
    flash_lights()
    #flash_lights() flash_lights()

@webiopi.macro
def forward():
    robot.reverse()

@webiopi.macro
def reverse():
    robot.forward()

@webiopi.macro
def stop():
コード例 #3
0
ファイル: rctank.py プロジェクト: averak/rctank
import webiopi

webiopi.setDebug()

GPIO = webiopi.GPIO


class DCMotor:
    _pin1 = 0
    _pin2 = 0

    def __init__(self, pin1, pin2):
        self._pin1 = pin1
        self._pin2 = pin2
        GPIO.setFunction(self._pin1, GPIO.PWM)
        GPIO.setFunction(self._pin2, GPIO.PWM)

    def __del__(self):
        self.write(0.0)  # stop

    def write(self, ratio):
        if 1.0 < ratio:  # saturation
            ratio = 1.0
        if -1.0 > ratio:  # saturation
            ratio = -1.0
        if 0.01 > ratio and -0.01 < ratio:  # stop
            GPIO.pwmWrite(self._pin1, 0.0)
            GPIO.pwmWrite(self._pin2, 0.0)
        elif 0 < ratio:  # Normal rotation
            GPIO.pwmWrite(self._pin1, ratio)
            GPIO.pwmWrite(self._pin2, 0.0)
コード例 #4
0
    def __init__(self):
        self.__setProperties()
        self.__configurePins()

        # Enable debug output
        webiopi.setDebug()
コード例 #5
0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

# Imports
import webiopi
from webiopi.utils.types import str2bool

BLINKPERIOD = 0.5
BLINKING = False

# ----- Enable debug output -----
webiopi.setDebug() #optional, can be omitted

# ----- WebIOPi predefined functions -----

# Called by WebIOPi at script loading
def setup():
    webiopi.debug("Looptest script - Setup") #optional, can be omitted
    
# Looped by WebIOPi
def loop():
    webiopi.debug("Looptest script - Loop") #optional, can be omitted
    if BLINKING:
        print("B-L-I-N-K") 
        webiopi.sleep(BLINKPERIOD)        
        print("---------") 
    webiopi.sleep(BLINKPERIOD)        
コード例 #6
0
ファイル: Robot.py プロジェクト: mikehalma/initio-webiopi
 def __init__(self):
     webiopi.setDebug()
     webiopi.debug('The test robot has been activated')