Esempio n. 1
0
def getrmc():

    serial = wp.serialOpen("/dev/ttyAMA0", 57600)  # open serial port

    wp.serialFlush(serial)
    print(serial)
    while True:  # repeat until we get a RMC NMEA string
        gpsstring = ""
        while True:  # repeat until we have a complete string
            if (wp.serialDataAvail(serial) > 0):
                letter = wp.serialGetchar(serial)
                if letter == 10:
                    break
                else:
                    gpsstring += str(chr(letter))
        if (gpsstring[3:6] == "RMC"):
            break
    wp.serialClose(serial)
    return (gpsstring)
Esempio n. 2
0
def getrmc():

    serial = wp.serialOpen("/dev/ttyAMA0",57600) # open serial port 

    wp.serialFlush(serial)
    print(serial)
    while True: # repeat until we get a RMC NMEA string
        gpsstring = ""
        while True: # repeat until we have a complete string
            if (wp.serialDataAvail(serial) > 0):
		letter = wp.serialGetchar(serial)
                if letter == 10:
                    break
	        else:
                    gpsstring += str(chr(letter))
        if (gpsstring[3:6]=="RMC"):
           break
    wp.serialClose(serial)
    return(gpsstring)
def arduinoListen():
  global wiringpi2
  global arduinoIn
  global arduino

  wiringpi2.wiringPiSetup()
  arduino = wiringpi2.serialOpen("/dev/ttyACM0", 9600)
  wiringpi2.delay(250)
  wiringpi2.pinMode(0,1)
  wiringpi2.digitalWrite(0, 1)

  arduinoInReady.acquire()
  arduinoListenerReady.set()
  while(True):
    while(True):
      if(wiringpi2.serialDataAvail(arduino) > 0):
        arduinoIn = chr(wiringpi2.serialGetchar(arduino))
        arduinoInReady.release()
        time.sleep(0.5)
        break
      else:
        time.sleep(0.5)
    arduinoInReady.acquire()
Esempio n. 4
0
import wiringpi2 as wiringpi
import time

wiringpi.wiringPiSetup()
serial = wiringpi.serialOpen('/dev/ttyS0', 9600)
if serial == -1:
    print 'error opening serial at /dev/ttyS0'
    sys.exit(0)
print 'serial opened'
i = 0
while True:
    if (wiringpi.serialDataAvail(serial) > 0):
        line = wiringpi.serialGetchar(serial)
        print line
def dataListen():
  global wiringpi2
  global dataIn
  global middleLayer
  global data

  wiringpi2.wiringPiSetup()
  middleLayer = wiringpi2.serialOpen("/dev/ttyACM0", 9600) #Open serial port for middle layer communication
  wiringpi2.delay(250)

  start = time.time()
  while(True):
    if(wiringpi2.serialDataAvail(middleLayer) > 0):
      time.sleep(0.02)
      newInput = []
      info = wiringpi2.serialGetchar(middleLayer)
      #The first byte is read as a number between 000-255 that gives info about this data packet
      #The hundreds place digit represents if this input contains left (0), back (1), or right (2) range data
      #The remainder of the number divided by 100 represents how many bytes total are in this data packet 
      key = info / 100 # 0: left range data, 1: back range data, 2: right range data
      length = info % 100 # number of bytes in this data packet

      newInput.append(round(time.time() - start, 2)) #Store timestamp
      newInput.append(key)  #Store key for left/back/right range data choice
      newInput.append(wiringpi2.serialGetchar(middleLayer))  #Store height value

      front = 0
      sizeOfFront = wiringpi2.serialGetchar(middleLayer) #Check how many bytes are needed for front range value
      for i in range(0, sizeOfFront):
        front += wiringpi2.serialGetchar(middleLayer) #Sum up front range value bytes
      newInput.append(front)  #Store front range value

      #Store left/right/back range value, thrust value, yaw value, aileron value, and elevator value
      for i in range(0, 5):
        newInput.append(wiringpi2.serialGetchar(middleLayer))

      #IMU readings
      num = wiringpi2.serialGetchar(middleLayer) #First byte is one's place value
      dec = wiringpi2.serialGetchar(middleLayer) / 100.00 #Second byte is decimal value stored as an integer
      heading = num + dec #Combine bytes to get heading value
      newInput.append(heading) #Store heading value

      numSign = wiringpi2.serialGetchar(middleLayer) #First byte is sign of roll value
      if(numSign == 0):
        numSign = -1
      num = wiringpi2.serialGetchar(middleLayer) #Second byte is one's place value
      dec = wiringpi2.serialGetchar(middleLayer) / 100.00 #Third byte is decimal value stored as an integer
      pitch = (numSign)*(num + dec) #Combine bytes to get pitch value
      newInput.append(pitch) #Store pitch value

      numSign = wiringpi2.serialGetchar(middleLayer) #First byte is sign of roll value
      if(numSign == 0):
        numSign = -1
      num = wiringpi2.serialGetchar(middleLayer) #Second byte is one's place value
      dec = wiringpi2.serialGetchar(middleLayer) / 100.00 #Third byte is decimal value stored as an integer
      roll = (numSign)*(num + dec) #Combine bytes to get roll value
      newInput.append(roll) #Store roll value

      #Create DataStream object from input data and add to dataIn to be used by control algorithms
      dataIn.append(DataStream(newInput))
      #Add new DataStream object to DataLog
      data.add(dataIn[-1])

      time.sleep(0.03)
    else:
      time.sleep(0.05)
Esempio n. 6
0
if serial < 0:
    print("Unable to open serial device: \n")
    sys.exit()    

if wiringpi2.wiringPiSetup() == -1:
    print("Unable to start wiringPi: \n")
    sys.exit()    

i = 0
length = 0
rssi = 0
 
while True:
#    print(wiringpi2.serialDataAvail(serial))
    while wiringpi2.serialDataAvail(serial):
        get = wiringpi2.serialGetchar(serial)
        
        if get == 0x7e:
            i = 0
            print("\nBtye started")

        if i == 2:
            length = get
            print("length: ", length)
        if i == 6:
            rssi = get
            print("rssi: ", rssi)
        if i == 8:
            data = get
            print("data: ", data)
Esempio n. 7
0
#this example need change script.bin
#[uart_para6]
#uart_used = 1
#uart_port = 6
#uart_type = 2
#uart_tx = port:PI12<3><1><default><default>
#uart_rx = port:PI13<3><1><default><default>
#PI12:  pin46[U14 Next to sata]
#PI13:  pin48[U14 Next to sata]
serial = wiringpi2.serialOpen('/dev/ttyS6', 115200)
wiringpi2.serialPuts(serial, "\n")
print serial
wiringpi2.serialPuts(serial, "Putchar:")
wiringpi2.serialPutchar(serial, 0x38)  #sent ascii 0x38: 8
#wiringpi2.serialPutchar(serial,0x65)#sent ascii 0x68: A
wiringpi2.serialPuts(serial, "\n")

wiringpi2.serialPuts(serial, "Puts:")
wiringpi2.serialPuts(serial, "hello\n")

wiringpi2.serialPuts(serial, "Printf:")
wiringpi2.serialPrintf(serial, "hello\n")

#####get data from serial

while 1:
    if wiringpi2.serialDataAvail(serial):
        val = wiringpi2.serialGetchar(serial)
        print chr(val)
#wiringpi2.serialClose(serial) # Pass in ID