def lumiere(self, r, v, b): msg = [0x80] for c in [r, v, b]: if c < 0 or c > 255: return False else: msg.append(int(c / 2)) ser = wiringpi2.serialOpen(self.config.get("pin_led"), 115200) for j in msg: wiringpi2.serialPuts(ser, struct.pack("I", j)) wiringpi2.serialClose(ser)
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 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 close_serial_port(): wp.serialClose(rpi)
import wiringpi2 #wiringpi2.wiringPiSetupGpio() serial = wiringpi2.serialOpen('/dev/ttyAMA0',38400) # Requires device/baud and returns an ID if serial == -1: print('error') wiringpi2.delay(1000) while 1: #while wiringpi2.serialDataAvail(): # this while condition might work better #wiringpi2.serialPuts(serial,"hello") print(wiringpi2.serialGetchar(serial)) wiringpi2.serialClose(serial)