コード例 #1
0
 def output_to_MC(self, data=list, baudrate=int):
     length = len(data)
     #Checks if the list is of length 4. If it isn't, immediately return
     if(length!=4):
         print("Invalid list size. Needed size of 4, you provided a list whose size is {}".format(length))
         return
     wiringpi.wiringPiSetup()
     #opens the Raspberry Pi's UART port, w/ a data transfer rate of
     #115200 bits/s
     serial = wiringpi.serialOpen('/dev/ttyS0', baudrate)
     #sleep a few seconds to make sure the port opens and sets connections
     #properly
     sleep(2)
    #signals to start data transmission, uses start of header char
     wiringpi.serialPuts(serial, chr(1).encode('ascii'))
     wiringpi.serialPuts(serial, data[0].encode('ascii'))
     for index in range(1, length, 1):
         #signals that the next data is being sent, uses start of text char
         wiringpi.serialPuts(serial, chr(2).encode('ascii'))
         #write the string data, as ascii, to the Raspberry Pi
         wiringpi.serialPuts(serial, data[index].encode('ascii'))
     #signals that data transmission is ending, uses end of transmission char
     wiringpi.serialPuts(serial, chr(4).encode('ascii'))
     #closes the serial port
     wiringpi.serialClose(serial)
     return
コード例 #2
0
def ReadVersion(fd):
    # read the version from the RFID board
    WaitForCTS()
    # print ("Sending Read Version Command")     #Added for Debug purposes
    wiringpi2.serialPuts(fd,"z")
    time.sleep(0.1)
    ans = ReadText(fd)
    print ("Response: %s" % ans)
コード例 #3
0
def showUART():
    # UART is an asynchronous serial communication protocol
    loadCheck = importlib.util.find_spec('wiringpi')
    found = loadCheck is not None
    if found:
        import wiringpi
        wiringpi.wiringPiSetup()
        serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
        wiringpi.serialPuts(serial, 'hello world!')
    print("DONE wiringpi")
コード例 #4
0
def ReadTagStatus(fd):
    # read the RFID reader until a tag is present
    notag = True
    while notag:
        WaitForCTS()
        # print ("Sending Tag Status Command")   #Added for Debug purposes
        wiringpi2.serialPuts(fd,"S")
        time.sleep(0.1)
        ans = ReadInt(fd)
        # print ("Tag Status: %s" % hex(ans))    # Added for Debug purposes
        if ans == int("0xD6", 16):
            # D6 is a positive response meaning tag present and read
            notag = False
    print ("Tag Status: %s" % hex(ans))
    return
コード例 #5
0
ファイル: main.py プロジェクト: chekke1999/kaihatukadai
def _serial(send=None):
    wiringpi.wiringPiSetup()
    serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
    if send != None:
        wiringpi.serialPuts(serial, send)
        wiringpi.serialPutchar(serial, 3)
        wiringpi.serialClose(serial)
    else:
        char = ""
        asciinum = -1
        while (True):
            asciinum = wiringpi.serialGetchar(serial)
            if asciinum != -1 and asciinum != 3:
                char += chr(asciinum)
            elif asciinum == 3:
                break
        wiringpi.serialClose(serial)
        return char
def Gpio_Intent(status, room):
    wiringpi.wiringPiSetupGpio()

    wiringpi.pinMode(18, 2)  # pwm mode = 2
    wiringpi.pwmSetMode(0)

    # pwmFrequency in Hz = 19.2e6 Hz / pwmClock / pwmRange.
    wiringpi.pwmSetRange(4096)
    wiringpi.pwmSetClock(4095)
    if status in STATUSON:
        wiringpi.pwmWrite(18, 4096)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSOFF:
        wiringpi.pwmWrite(18, 0)
        return statement('turning {} blue L E D'.format(status))
    elif status in STATUSTOGGLE:
        wiringpi.pwmWrite(18, 2048)
        return statement('{}ing blue L E D'.format(status))
    elif status in STATUSCMD:
        serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
        if status == 'a':
            wiringpi.serialPuts(serial, 'a')
        elif status == 'be':
            wiringpi.serialPuts(serial, 'b')
        elif status == 'see':
            wiringpi.serialPuts(serial, 'c')
        wiringpi.serialClose(serial)
        return statement(
            'Trying to send command ASCII character {}'.format(status))
    else:
        return statement('Sorry not possible.')
コード例 #7
0
    def output_to_MC(self, data=list):

        wiringpi.wiringPiSetup()
        #opens the Raspberry Pi's UART port, w/ a data transfer rate of
        #115200 bits/s
        serial = wiringpi.serialOpen('/dev/ttyS0', 115200)
        #sleep a few seconds to make sure the port opens and sets connections
        #properly
        sleep(2)
        #signals to start data transmission, uses start of header char
        wiringpi.serialPuts(serial, chr(1).encode('ascii'))
        wiringpi.serialPuts(serial, data[0].encode('ascii'))
        for index in range(1, len(data), 1):
            #signals that the next data is being sent, uses start of text char
            wiringpi.serialPuts(serial, chr(2).encode('ascii'))
            #write the string data, as ascii, to the Raspberry Pi
            wiringpi.serialPuts(serial, data[index].encode('ascii'))
        #signals that data transmission is ending, uses end of transmission char
        wiringpi.serialPuts(serial, chr(4).encode('ascii'))
        #closes the serial port
        wiringpi.serialClose(serial)
        return
コード例 #8
0
        if(data['bt'] == 'Lock: lock'):
            isMoving = False
        elif(data['bt'] == 'Lock: unlock'):
            isMoving = True
        
        if isMoving:
            coords_of_qr = get_coords_from_qr_code(frame, code)
            if coords_of_qr == False:
                counter_of_failed_frames += 1
            else:
                counter_of_failed_frames = 0

                if coords_of_qr['w'] > width // 4:
                    print("I need stop: ", coords_of_qr['w'])
                    wiringpi.serialPuts(serial, 's')

                    Modules.getModule('bt').sendData('dir: s')

                elif coords_of_qr['w'] < width // 4:
                    print("I need go: ", coords_of_qr['w'])
                    wiringpi.serialPuts(serial, 'g')

                    Modules.getModule('bt').sendData('dir: g')
                
                center = (coords_of_qr['x'] + coords_of_qr['w'] // 2)
                
                if  center < width // 2 - coords_of_qr['w']:
                    print("I need left: ", center)
                    wiringpi.serialPuts(serial, 'l')
コード例 #9
0
def SENDmode():
  #ser.write(b'hello') 
  #wiringpi.serialPuts(serial,"hello")
  if mod == 1:
    wiringpi.serialPuts(serial, "<1")  # CAN1 mode

    if CAN1mode_sel == 0: 
      wiringpi.serialPuts(serial, "O>" ) # set to OFF

    elif CAN1mode_sel == 1:
      wiringpi.serialPuts(serial, "S>")  # set to SNIFF 
      CAN1pane.send_keys('\x01\x04', enter=False) #ctrl-A ctrl-D to detach 
      CAN1pane.send_keys('screen -S filter -X quit')
      time.sleep(1)
      CAN1pane.send_keys('screen -R sniffer')
      time.sleep(1)
      CAN1pane.send_keys('sudo ./can.sh -o 1')
      time.sleep(1)
      CAN1pane.send_keys('sudo ./can.sh -s 1')

    elif CAN1mode_sel == 2:  # set as INPUT to FILTER 
      wiringpi.serialPuts(serial, "I>")
      CAN1pane.send_keys('\x01\x04', enter=False) #ctrl-A ctrl-D to detach 
      time.sleep(1)
      CAN1pane.send_keys('screen -S sniffer -X quit')
      time.sleep(1)
      CAN1pane.send_keys('sudo ./can.sh -d 1')
      time.sleep(1)
      CAN1pane.send_keys('screen -R filter /dev/ttyACM1')

    elif CAN1mode_sel == 3:
      wiringpi.serialPuts(serial, "F>")  # set as OUTPUT of FILTER

    elif CAN1mode_sel == 4:
      wiringpi.serialPuts(serial, "R>")  # set to SNIFF for RECORDING

    elif CAN1mode_sel == 5:
      wiringpi.serialPuts(serial, "P>")  # set to SNIFF for PLAYBACK
コード例 #10
0
#/home/pi/Scripts/motors.py
# Script permettant de faire fonctionner les moteurs du chariot à l'aide de la carte Sabertooth 2x32. On passe en argument la vitesse du premier moteur puis celle du second moteur (une valeur entre 0 et 2047)
# Le montage pour controller la est le suivant:
#-relier le S1 sur le TX du raspberry (envoie)
#-relier le S2 sur le RX du raspberry (reception)
#-relier le 0V sur un GND du raspberry
import wiringpi, sys
m1Speed = sys.argv[1]
m2Speed = sys.argv[2]
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/serial0', 9600)
wiringpi.serialPuts(serial, 'M1: ' + m1Speed + '\r\n')
wiringpi.serialPuts(serial, 'M2: ' + m2Speed + '\r\n')
#wiringpi.serialClose(serial)

#file = open("/home/pi/testfile.txt","a")
#file.write("commande >")
#file.write(sys.argv[1])
#file.write(" ")
#file.write(sys.argv[2])
#file.write("\n")
#file.close()
コード例 #11
0
ファイル: wiring.py プロジェクト: emrysr/stm32config
#!/usr/bin/env python3
import wiringpi
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
wiringpi.serialPuts(serial, 'RES:[{"name":"Dave"}]\n\r')
コード例 #12
0
ファイル: uart.py プロジェクト: navyblu971/drawOnTheWall
import wiringpi as wiringpi
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyAMA0', 9600)
wiringpi.serialPuts(serial, 'hello world!')
コード例 #13
0
ファイル: grohbot.py プロジェクト: thefpoff/grohbot
def print_lcd_line_1(text):
    wiringpi.serialPuts(serial, '?x00?y1')  #set cursor to second line
    wiringpi.serialPuts(serial, text)
コード例 #14
0
ファイル: grohbot.py プロジェクト: thefpoff/grohbot
def print_lcd_line_0(text):
    wiringpi.serialPuts(serial, '?f')  #clear screen line one
    wiringpi.serialPuts(serial, text)
コード例 #15
0
import serial, sys, time
import wiringpi

wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyUSB0', 9600)

while True:
    string = input("Input key: ")
    wiringpi.serialPuts(serial, string)

#ser.write(sys.argv[1].encode('utf-8'))
コード例 #16
0
#!/usr/bin/env python
import wiringpi as wpi
import time

serial = wpi.serialOpen('/dev/ttyS0', 115200)

while True:
    input_str = raw_input('Serial Input> ')
    wpi.serialPuts(serial, input_str)
    time.sleep(0.1)

    output_str = 'Serial Output> '
    while wpi.serialDataAvail(serial):
        output_str += chr(wpi.serialGetchar(serial))
    print output_str

wpi.serialClose(serial)
コード例 #17
0
def showUART( ):
	wiringpi.wiringPiSetup()
	uart_serial = serial.Serial ( DEVICE , BAUD )
	wiringpi.serialPuts( uart_serial , TXTLINE )