Esempio n. 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
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.')
Esempio n. 3
0
    def __init__(self, connector):
        # *** User variables ***
        self.drive_motor_forward_pin = 5
        self.drive_motor_reverse_pin = 6
        self.turn_motor_left_pin = 2
        self.turn_motor_right_pin = 3
        self.pwm0_pin = 1
        self.clock_pin = 7
        self.led_one_pin = 4
        # Serial depends on how PyBluez sets it up, but it's usually this
        self.serial_dev = "/dev/ttyAMA0"
        self.serial_baud = 9600

        # Internal setup
        self.rc = connector
        self.rc.setBlocking(True)
        wiringpi.wiringPiSetup()
        self.serial = wiringpi.serialOpen(self.serial_dev, self.serial_baud)
        wiringpi.pinMode(self.drive_motor_forward_pin, 1)
        wiringpi.pinMode(self.drive_motor_reverse_pin, 1)
        wiringpi.pinMode(self.turn_motor_left_pin, 1)
        wiringpi.pinMode(self.turn_motor_right_pin, 1)

        # Just output a constant high on drive PWM for now...
        wiringpi.pinMode(self.pwm0_pin, 1)
        wiringpi.digitalWrite(self.pwm0_pin, 1)
Esempio n. 4
0
 def open(self, serialName):
     wpi.wiringPiSetupGpio()
     wpi.pinMode(self.resetPin, wpi.GPIO.OUTPUT)
     wpi.pinMode(self.busyPin, wpi.GPIO.INPUT)
     wpi.digitalWrite(self.resetPin, wpi.GPIO.LOW)
     time.sleep(0.1)
     wpi.digitalWrite(self.resetPin, wpi.GPIO.HIGH)
     self.serial = wpi.serialOpen(serialName, 38400)
Esempio n. 5
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")
Esempio n. 6
0
def initializationOfSerialConnection():
    ttys = os.listdir('/dev')
    counter = 0
    for tty in ttys:
        counter += 1
        if tty.find('ttyUSB') != -1:
            wiringpi.wiringPiSetup()
            print('Arduino is found: /dev/' + tty)
            serial = wiringpi.serialOpen('/dev/' + tty, 9600)
            return serial
Esempio n. 7
0
    def __init__(self, device, dz_counter_idx=0, dz_current_idx=0,
                 update_period=20, callback=None):
        """Constructor

        Parameters:

        device: name of the serial port device used to receive the data.
            example: /dev/ttyAMA0

        dz_counter_idx (optionnal): index identifying a virtual counter
            in Domoticz where to send the counter base index (in Wh) and
            apparent power (in VA).

        dz_current_idx (optionnal): index identifying a virtual current
            sensor in Domoticz where to send the instantaneaous current values.
            (in Amps).

        update_period (optionnal) : period of time used to send the data to
            Domoticz.
            20 s by default.

        callback (optionnal): if present, this function will be called each
            time a currnt value is received. The current value is passed as
            parameter to the callback function.
            Note that the callback function shall be designed to not block or
            take a long time to execute.
        """

        Thread.__init__(self)
        self._callback = callback
        self.data_lock = Lock()     # lock for access to couter data

        # Create DzSensor objects if needed
        if dz_counter_idx:
            self.dz_counter = DzSensor(PARAM_STRING_ELECTRIC_COUNTER,
                                       dz_counter_idx, update_period)
        if dz_current_idx:
            self.dz_current = DzSensor(PARAM_STRING_CURRENT, dz_current_idx,
                                       update_period)

        # Open the COM port at 1200 bauds
        self.fd = serialOpen(device, 1200)
        self._current = -1
        self._power = -1
        self._index = -1
        self.start()
Esempio n. 8
0
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
Esempio n. 9
0
def RFIDSetup():
    # setup up the serial port and the wiringpi software for use
    # call setup for the wiringpi2 software
    response = wiringpi2.wiringPiSetup()
    # set the GPIO pin for input
    wiringpi2.pinMode(GPIO_PIN, 0)
    # open the serial port and set the speed accordingly
    fd = wiringpi2.serialOpen('/dev/serial0', 9600)

    # clear the serial buffer of any left over data
    wiringpi2.serialFlush(fd)
    
    if response == 0 and fd >0:
        # if wiringpi is setup and the opened channel is greater than zero (zero = fail)
        print ("PI setup complete on channel %d" %fd)
    else:
        print ("Unable to Setup communications")
        sys.exit()
        
    return fd
    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
Esempio n. 11
0
def SetupUART():
    """
    Setup the UART for communications and return an object referencing it. Does:-
    -Initiates wiringpi software
    -Opens the serial port
    -Checks all is ok and returns the object
    """

    response = wiringpi.wiringPiSetup()
    # open the serial port and set the speed accordingly
    sp = wiringpi.serialOpen('/dev/ttyAMA0', 9600)

    # clear the serial buffer of any left over data
    wiringpi.serialFlush(sp)

    if response == 0 and sp > 0:
        # if wiringpi is setup and the opened channel is greater than zero (zero = fail)
        logging.info("PI setup complete on channel %d" % sp)
    else:
        logging.critical("Unable to Setup communications")
        sys.exit()

    return sp
Esempio n. 12
0
import wiringpi as wpi, threading

fd = wpi.serialOpen("/dev/serial0", 115200)
running = True

def read_serial():
    while running:
        try:
            if wpi.serialDataAvail(fd) != -1 :
                ch = wpi.serialGetchar(fd)
                if ch== -1 :
                    continue
                ch = chr(ch)
                if ch == '\r':
                    ch = '\n'
                print(ch, end='')
        except:
            pass
    print("bye.")
    
try:
    t = threading.Thread(target=read_serial)
    t.start()
    print('serial is ready.')
    while True:
        line = input(">")
        if line == 'exit':
            break
        wpi.serialPrintf(fd,  (line + '\r\n'))
    print('closing.')
finally:
def main():

    ## MAIN ALGORITHM

    ## Open Serial Port
    ser = serial.Serial (port='/dev/ttyAMA0',baudrate=9600,parity=serial.PARITY_EVEN,stopbits=serial.STOPBITS_TWO,timeout=1)
    wiring_serial = wiringpi.serialOpen('/dev/ttyAMA0',9600)
    new = termios.tcgetattr(wiring_serial)
    new[2] |= termios.CSTOPB
    new[2] |= termios.PARENB
    termios.tcsetattr(wiring_serial,termios.TCSANOW,new)

    ## GUI
    print ('====================================================================')
    print ('            Xirka Silicon Technology Smart Card Reader              ')
    print ('====================================================================')
    print ('Instruction:')
    print ('1. Do not remove the smartcard in the middle of the program')
    print ('2. Enter x or X as APDU Command to exit the program')
    print ('3. Enter t or T as APDU Command to test the performance')
    print (' ')

    init_setup()
    warm_reset()


    GPIO.setmode(GPIO.BCM)
    GPIO.setup(TRG, GPIO.IN, pull_up_down = GPIO.PUD_UP)

    print 

    try:
        if wiringpi.digitalRead(TRG_wiringpi)==0:
            print "Waiting for Card";
            print
            GPIO.wait_for_edge(TRG, GPIO.RISING)
            ATR=read_ATR(wiring_serial)
            print "ATR :",ATR
            print 

            while True:
                apdu = raw_input("Enter APDU Command = ")
                if ((apdu == 'x') or (apdu == 'X')):
                    print
                    print "Please remove the smartcard..."
                    GPIO.wait_for_edge(TRG, GPIO.FALLING)
                    print
                    print "Thank you"
                    break
                elif (apdu=='t') or (apdu == 'T'):
                    start=time.time()
                    print
                    print ("Enter APDU Command = 00 a4 00 00 02 3f 00")
                    transmit_APDU('00 a4 00 00 02 3f 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 00")
                    transmit_APDU('00 a4 00 00 02 30 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 01")
                    transmit_APDU('00 a4 00 00 02 30 01',wiring_serial,ser)
                    print ("Enter APDU Command = 00 b0 00 00 08")
                    transmit_APDU('00 b0 00 00 08',wiring_serial,ser)
                    end = time.time()
                    print 'Execution time: ',(end - start), 'seconds'
                    break
                else:
                    transmit_APDU(apdu,wiring_serial,ser)
        else:
            ATR=read_ATR(wiring_serial)
            print "ATR :",ATR
            print 

            while True:
                apdu = raw_input("Enter APDU Command = ")
                if ((apdu == 'x') or (apdu == 'X')):
                    print
                    print "Please remove the smartcard..."
                    GPIO.wait_for_edge(TRG, GPIO.FALLING)
                    print
                    print "Thank you"
                    break
                elif (apdu=='t') or (apdu == 'T'):
                    start=time.time()
                    print
                    print ("Enter APDU Command = 00 a4 00 00 02 3f 00")
                    transmit_APDU('00 a4 00 00 02 3f 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 00")
                    transmit_APDU('00 a4 00 00 02 30 00',wiring_serial,ser)
                    print ("Enter APDU Command = 00 a4 00 00 02 30 01")
                    transmit_APDU('00 a4 00 00 02 30 01',wiring_serial,ser)
                    print ("Enter APDU Command = 00 b0 00 00 08")
                    transmit_APDU('00 b0 00 00 08',wiring_serial,ser)
                    end = time.time()
                    print 'Execution time: ',(end - start), 'seconds'
                    break

                else:
                    transmit_APDU(apdu,wiring_serial,ser)            
    except KeyboardInterrupt:  
        GPIO.cleanup()       # clean up GPIO on CTRL+C exit  
    GPIO.cleanup()           # clean up GPIO on normal exit  


    wiringpi.serialClose(wiring_serial)
    ser.close()
Esempio n. 14
0
import wiringpi
from time import sleep
import os
wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyS0', 9600)
sleep(3)
 def __init__(self, serialdevice):
     wiringpi.wiringPiSetup()  # Use WiringPi numbering
     self.serial = wiringpi.serialOpen(
         serialdevice, 115200)  # Requires device/baud and returns an ID
#!/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)
Esempio n. 17
0
import libtmux
import io
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

server = libtmux.Server()
print(server.list_sessions())
session = server.get_by_id('$0')
window = session.attached_window
print(window.list_panes())
CAN1pane = window.get_by_id('%0')
MENUpane = window.get_by_id('%1')
CAN2pane = window.get_by_id('%2')

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

A_PIN  = 23
B_PIN  = 24
SW_PIN = 22

GPIO.setup(A_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(B_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)
time_last_refresh = time.time() 
A_set = False
B_set = False
encoderPos = 0
prevPos = 0
sw_state = 0
last_state = None
Esempio n. 18
0
 def __enter__(self):
     print("with enter...")
     self.serial_fd = wiringpi.serialOpen(self.device, self.baud_rate)
     return self
Esempio n. 19
0
import wiringpi as pi

serial_tty = "/dev/ttyS0"
serial_speed = 9600

serial = pi.serialOpen(serial_tty, serial_speed)


def dm_to_deg(data):
    deg = int(float(data) / 100)
    min = float(data) - deg * 100
    return (round(deg + min / 60.0, 6))


while (True):
    gps_line = ''
    while (True):
        buf = chr(pi.serialGetchar(serial))
        if (buf == '\r'):
            break
        elif (buf != '\n'):
            gps_line = gps_line + buf
    gps_data = gps_line.split(",")
    if (gps_data[0] == '$GPRMC'):
        lat = gps_data[3]
        long = gps_data[5]

        if (lat != "" and long != ""):
            lat_deg = dm_to_deg(lat)
            long_deg = dm_to_deg(long)
            print("Latitude:", lat_deg, "  Longitude:", long_deg)