#---------------------------Global Variables---------------------------- IsGPIO = False IsSPI = False delay = 5 logging = True alarm = False blynk = BlynkLib.Blynk('QaSs_5koxPXKY8STWWwvX3Eqsdsi-1U3') # Initialize Blynk # For ADC SPI firstByte = int('00000001',2) humidityByte = int('10000000',2) lightByte = int('10010000',2) tempByte = int('10100000',2) lastByte = int('00000000',2) adc = spidev.SpiDev() # For DAC commandBits = int('0111',2) << 12 Vref = 3.3 dac = spidev.SpiDev() upperLimit = 2.65 lowerLimit = 0.65 AlarmString = " " lastAlarmTime = 0 alarmBuffer = 3 #min # For time sysStart = datetime.datetime.now() Data = ["00:00:00",0,0,0] # For threads
#!/usr/bin/python3 # # Read MAX6675 from SPI interface and send to database # import sys import time import spidev import mysql.connector SPI = spidev.SpiDev() # for One, 0.0, for Zero: 1,0 SPI.open(0, 0) # for One, 0.0, for Zero: 1,0 # Read 5 times, and use average value temp = 0 for i in range(5): resp = SPI.readbytes(2) temp += ((resp[1] + resp[0] * 256) & 0x7ff8) time.sleep(0.2) # min 0.18s SPI.close() temp /= 160 # /8/5*0.25 # Insert to database USER = '******' PWD = 'www' HOST = 'yfhomeserver.local' DB = 'yfhome' SQL = "INSERT INTO home_temp VALUES (0, %s, 0, %s, %s )"
try: file = open(GPIO_EXPORT_PATH, 'w') file.write("204") ## export the pin to the usermode file.close() file = open(GPIO_MODE_PATH, 'r+') file.write("out") ## make the pin as output file.close() except: print "reinit..." spi = spidev.SpiDev() # create spi object spi.open(1, 0) # open spi port 0, device (CS) 1 try: #spi.mode = 2 #spi.bits_per_word = 8 #spi.cshigh = False while True: #resp = spi.readbytes(2) #resp = spi.xfer([0xAA,0x55,0xAA,0x55],10000000,0) # transfer one byte for n in range(20): #pin = open(GPIO_PIN_PATH, "w") #resp = spi.xfer([0x00,0x00]) # transfer #pin.write("1") #pin.close() #pin = open(GPIO_PIN_PATH, "w") #pin.write("0")
KEY3_PIN = 16 RST = 27 DC = 25 BL = 24 bus = 0 device = 0 # hardware BOUNCE_TIME = 250 BATTERY_HISTORY = 10 # refresh rate TICK_INTERVAL = 0.1 disp = raspberry_pi.ST7789(SPI.SpiDev(bus, device), RST, DC, BL) disp.init() disp.show_image(Image.new('RGB', (240, 240), (0, 0, 0)), 0, 0) GPIO.setmode(GPIO.BCM) GPIO.setup(KEY_UP_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY_DOWN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY_LEFT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY_RIGHT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY_PRESS_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY1_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY2_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(KEY3_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) def on_key_up(channel):
def __init__(self, spi_channel=0): self.spi_channel = spi_channel self.conn = spidev.SpiDev(0, spi_channel) self.conn.max_speed_hz = 1000000 # 1MHz
#!/usr/bin/python __author__ = "D.Qendri" __copyright__ = "Copyright 2015 Sensorian" __license__ = "GPL V3" __version__ = "1.0" import numbers import time import Image import ImageDraw import RPi.GPIO as GPIO import spidev as spi spi = spi.SpiDev() #Loosely based on some snippets from Adafruit display driver. # Constants for interacting with display registers. TFT_WIDTH = 128 # Screen Width TFT_HEIGHT = 160 # Scree Height NOP = 0x00 SWRESET = 0x01 RDDID = 0x04 RDDST = 0x09 RDDPM = 0x0A RDDMADCTL = 0x0B # Read Display MADCTL RDDCOLMOD = 0x0C # Read Display Pixel Format RDDIM = 0x0D # Read Display Image Mode RDDSM = 0x0E # Read Display Signal Mode
def __init__(self, freqBand, nodeID, networkID, isRFM69HW=False, intPin=18, rstPin=31, spiBus=0, spiDevice=0): self.freqBand = freqBand self.address = nodeID self.networkID = networkID self.isRFM69HW = isRFM69HW self.intPin = intPin self.rstPin = rstPin self.spiBus = spiBus self.spiDevice = spiDevice self.intLock = False self.mode = "" self.promiscuousMode = False self.DATASENT = False self.DATALEN = 0 self.SENDERID = 0 self.TARGETID = 0 self.PAYLOADLEN = 0 self.ACK_REQUESTED = 0 self.ACK_RECEIVED = 0 self.RSSI = 0 self.DATA = [] GPIO.setmode(GPIO.BOARD) GPIO.setup(self.intPin, GPIO.IN) GPIO.setup(self.rstPin, GPIO.OUT) frfMSB = { RF69_315MHZ: RF_FRFMSB_315, RF69_433MHZ: RF_FRFMSB_433, RF69_868MHZ: RF_FRFMSB_868, RF69_915MHZ: RF_FRFMSB_915 } frfMID = { RF69_315MHZ: RF_FRFMID_315, RF69_433MHZ: RF_FRFMID_433, RF69_868MHZ: RF_FRFMID_868, RF69_915MHZ: RF_FRFMID_915 } frfLSB = { RF69_315MHZ: RF_FRFLSB_315, RF69_433MHZ: RF_FRFLSB_433, RF69_868MHZ: RF_FRFLSB_868, RF69_915MHZ: RF_FRFLSB_915 } self.CONFIG = { 0x01: [ REG_OPMODE, RF_OPMODE_SEQUENCER_ON | RF_OPMODE_LISTEN_OFF | RF_OPMODE_STANDBY ], #no shaping 0x02: [ REG_DATAMODUL, RF_DATAMODUL_DATAMODE_PACKET | RF_DATAMODUL_MODULATIONTYPE_FSK | RF_DATAMODUL_MODULATIONSHAPING_00 ], #default:4.8 KBPS 0x03: [REG_BITRATEMSB, RF_BITRATEMSB_55555], 0x04: [REG_BITRATELSB, RF_BITRATELSB_55555], #default:5khz, (FDEV + BitRate/2 <= 500Khz) 0x05: [REG_FDEVMSB, RF_FDEVMSB_50000], 0x06: [REG_FDEVLSB, RF_FDEVLSB_50000], 0x07: [REG_FRFMSB, frfMSB[freqBand]], 0x08: [REG_FRFMID, frfMID[freqBand]], 0x09: [REG_FRFLSB, frfLSB[freqBand]], # looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm # +17dBm and +20dBm are possible on RFM69HW # +13dBm formula: Pout=-18+OutputPower (with PA0 or PA1**) # +17dBm formula: Pout=-14+OutputPower (with PA1 and PA2)** # +20dBm formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet) #0x11: [REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111], #over current protection (default is 95mA) #0x13: [REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95], # RXBW defaults are { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_5} (RxBw: 10.4khz) #//(BitRate < 2 * RxBw) 0x19: [REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_16 | RF_RXBW_EXP_2], #for BR-19200: //* 0x19 */ { REG_RXBW, RF_RXBW_DCCFREQ_010 | RF_RXBW_MANT_24 | RF_RXBW_EXP_3 }, #DIO0 is the only IRQ we're using 0x25: [REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_01], #must be set to dBm = (-Sensitivity / 2) - default is 0xE4=228 so -114dBm 0x29: [REG_RSSITHRESH, 220], #/* 0x2d */ { REG_PREAMBLELSB, RF_PREAMBLESIZE_LSB_VALUE } // default 3 preamble bytes 0xAAAAAA 0x2e: [ REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_0 ], #attempt to make this compatible with sync1 byte of RFM12B lib 0x2f: [REG_SYNCVALUE1, 0x2D], #NETWORK ID 0x30: [REG_SYNCVALUE2, networkID], 0x37: [ REG_PACKETCONFIG1, RF_PACKET1_FORMAT_VARIABLE | RF_PACKET1_DCFREE_OFF | RF_PACKET1_CRC_ON | RF_PACKET1_CRCAUTOCLEAR_ON | RF_PACKET1_ADRSFILTERING_OFF ], #in variable length mode: the max frame size, not used in TX 0x38: [REG_PAYLOADLENGTH, 66], #* 0x39 */ { REG_NODEADRS, nodeID }, //turned off because we're not using address filtering #TX on FIFO not empty 0x3C: [ REG_FIFOTHRESH, RF_FIFOTHRESH_TXSTART_FIFONOTEMPTY | RF_FIFOTHRESH_VALUE ], #RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) 0x3d: [ REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_2BITS | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF ], #for BR-19200: //* 0x3d */ { REG_PACKETCONFIG2, RF_PACKET2_RXRESTARTDELAY_NONE | RF_PACKET2_AUTORXRESTART_ON | RF_PACKET2_AES_OFF }, //RXRESTARTDELAY must match transmitter PA ramp-down time (bitrate dependent) #* 0x6F */ { REG_TESTDAGC, RF_DAGC_CONTINUOUS }, // run DAGC continuously in RX mode # run DAGC continuously in RX mode, recommended default for AfcLowBetaOn=0 0x6F: [REG_TESTDAGC, RF_DAGC_IMPROVED_LOWBETA0], 0x00: [255, 0] } #initialize SPI self.spi = spidev.SpiDev() self.spi.open(self.spiBus, self.spiDevice) self.spi.max_speed_hz = 4000000 # Hard reset the RFM module GPIO.output(self.rstPin, GPIO.HIGH) time.sleep(0.1) GPIO.output(self.rstPin, GPIO.LOW) time.sleep(0.1) #verify chip is syncing? while self.readReg(REG_SYNCVALUE1) != 0xAA: self.writeReg(REG_SYNCVALUE1, 0xAA) while self.readReg(REG_SYNCVALUE1) != 0x55: self.writeReg(REG_SYNCVALUE1, 0x55) #write config for value in self.CONFIG.values(): self.writeReg(value[0], value[1]) self.encrypt(0) self.setHighPower(self.isRFM69HW) # Wait for ModeReady while (self.readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00: pass GPIO.remove_event_detect(self.intPin) GPIO.add_event_detect(self.intPin, GPIO.RISING, callback=self.interruptHandler)
def __init__(self, temp_channel = 0): self.temp_channel = temp_channel self.spi = spidev.SpiDev() self.spi.open(0,0) self.spi.max_speed_hz=1000000
def __init__(self): self.spi = spidev.SpiDev() self.init_yomopie() return
def __init__(self,cfg ): threading.Thread.__init__(self) sensor.Sensor.__init__(self,cfg ) myrevision = getrevision() if ( myrevision == "a21041" or myrevision == "a01041" ): self.model = 2 else: self.model = 1 #print myrevision if ( self.model == 2 ) : # Open SPI bus log("Initializing SPI") self.spi = spidev.SpiDev() self.spi.open(0,0) else: log("Initializing libMCP") self.libMCP = cdll.LoadLibrary('./mcp3002/libMCP3002.so') if ( self.libMCP.init() != 0 ): log("Error initializing mcp3002 library.Try to continue") self.cfg = cfg self.bTimerRun = 0 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.__PIN_A, GPIO.IN) # wind Speed self.rb_WindSpeed = TTLib.RingBuffer(self.cfg.number_of_measure_for_wind_average_gust_calculation) self.map = intervalmap.intervalmap() #PCE-SENSOR-C Cucco per oriantare correttamente i sensori if ( self.cfg.sensor_type.upper() == "PCE-SENSOR-C" ): self.map[0:75] = 7 self.map[75:89] = 5 self.map[89:111] = 6 self.map[111:156] = 9 self.map[156:214] = 8 self.map[214:264] = 11 self.map[264:342] = 10 self.map[342:424] = 3 self.map[424:514] = 4 self.map[514:593] = 13 self.map[593:640] = 12 self.map[640:712] = 1 self.map[712:769] = 2 self.map[769:815] = 15 self.map[815:870] = 0 self.map[870:1024]= 14 else: self.map[0:75] = 5 self.map[75:89] = 3 self.map[89:111] = 4 self.map[111:156] = 7 self.map[156:214] = 6 self.map[214:264] = 9 self.map[264:342] = 8 self.map[342:424] = 1 self.map[424:514] = 2 self.map[514:593] = 11 self.map[593:640] = 10 self.map[640:712] = 15 self.map[712:785] = 0 self.map[785:815] = 13 self.map[815:870] = 14 self.map[870:1024]= 12 self.active = True self.start()
spidev = GPIO # the virtual GPIO module directly supports spidev function else: # RPI print("rpi") GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) RST = 18 # RST may use direct +3V strapping, and then be listed as 0 here. (Soft Reset used instead) CE = 0 # RPI GPIO: 0 or 1 for CE0 / CE1 number (NOT the pin#) DC = 22 # Labeled on board as "A0" Command/Data select LED = 23 # LED may also be strapped direct to +3V, (and then LED=0 here). LED sinks 10-14 mA @ 3V import spidev # Don't forget the other 2 SPI pins SCK and MOSI (SDA) TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, isRedBoard=True) #print ("Display character set:") #posx=0 #posy=0 # Manual cursor moving #for i in range (32,256): # TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK) # posx+=TFT.fontW # if (posx+TFT.fontW)>128: # posx=0 # posy+=TFT.fontH #sleep(2) #TFT.clear_display(TFT.BLUE)
def __init__(self): import spidev self.SPI = spidev.SpiDev(0, 0) import Jetson.GPIO self.GPIO = Jetson.GPIO
def main(stdscr): curses.noecho() curses.cbreak() stdscr.keypad(True) now = datetime.datetime.now() greettime = " morning " if (now.hour > 12): greettime = " afternoon " spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 100000 menu = CursesMenu("LVR Butler", "Good " + greettime + ". How can I help?") menu_getStatus = FunctionItem("Read Config", do_transaction, [stdscr, menu, spi, 0x00000000]) menu_wordtwo = FunctionItem("Get LVR WORD2", do_transaction, [stdscr, menu, spi, 0x40000000]) menu_wordthree = FunctionItem("Get LVR WORD3", do_transaction, [stdscr, menu, spi, 0x80000000]) menu_decode = FunctionItem("Decode Last Response", do_decode, [stdscr, menu]) menu.returned_value = write_spi(spi, 0x00000000) smenu_write = CursesMenu("Select Option", "What shall I change?") smenu_write.parent = menu smenu_togglelowDC = FunctionItem("Toggle Low Duty Cycle", bit_toggle, [stdscr, menu, spi, (0x00100000)]) smenu_allOff = FunctionItem("Set All OFF", do_transaction, [stdscr, menu, spi, (0xC0000000)]) smenu_allReady = FunctionItem("Set All READY", do_transaction, [stdscr, menu, spi, (0xC000FF00)]) smenu_allOn = FunctionItem("Set All ON", do_transaction, [stdscr, menu, spi, (0xC000FFFF)]) smenu_write.append_item(smenu_togglelowDC) smenu_write.append_item(smenu_allOff) smenu_write.append_item(smenu_allReady) smenu_write.append_item(smenu_allOn) menu_update = SubmenuItem("Modify Config", smenu_write) ssmenu_writesingle = CursesMenu("Select Channel") ssmenu_writesingle.parent = smenu_write ssmenu_ch = [] for i in range(1, 9, 1): ssmenu_ch.append( FunctionItem("CH" + str(i), bit_toggle, [stdscr, menu, spi, (0x101 << i - 1)])) ssmenu_writesingle.append_item(ssmenu_ch[i - 1]) smenu_writesingle = SubmenuItem("Toggle Single Channel On/Off", ssmenu_writesingle) smenu_write.append_item(smenu_writesingle) menu.append_item(menu_getStatus) menu.append_item(menu_wordtwo) menu.append_item(menu_wordthree) menu.append_item(menu_update) menu.append_item(menu_decode) menu.show()
def __init__(self): if STUB_SPI == False: self.spi = spidev.SpiDev()
# # Python drivers for the BrickPi3 from __future__ import division, print_function import array # for converting hex string to byte array import subprocess # for executing system calls import spidev #from builtins import input FIRMWARE_VERSION_REQUIRED = "1.4.x" # Make sure the top 2 of 3 numbers match BP_SPI = spidev.SpiDev() BP_SPI.open(0, 1) BP_SPI.max_speed_hz = 500000 BP_SPI.mode = 0b00 BP_SPI.bits_per_word = 8 class Enumeration(object): def __init__(self, names): # or *names, with no .split() number = 0 for line, name in enumerate(names.split('\n')): if name.find(",") >= 0: # strip out the spaces while(name.find(" ") != -1): name = name[:name.find(" ")] + name[(name.find(" ") + 1):]
def __init__(self, bus=0): self.spi = spidev.SpiDev() self.spi.open(0, bus) self.spi.max_speed_hz = SPI_FREQUENCY
def setup(self): """Set up Inky GPIO and reset display.""" if not self._gpio_setup: if self._gpio is None: try: import RPi.GPIO as GPIO self._gpio = GPIO except ImportError: raise ImportError( 'This library requires the RPi.GPIO module\nInstall with: sudo apt install python-rpi.gpio' ) self._gpio.setmode(self._gpio.BCM) self._gpio.setwarnings(False) self._gpio.setup(self.cs_pin, self._gpio.OUT, initial=self._gpio.HIGH) self._gpio.setup(self.dc_pin, self._gpio.OUT, initial=self._gpio.LOW, pull_up_down=self._gpio.PUD_OFF) self._gpio.setup(self.reset_pin, self._gpio.OUT, initial=self._gpio.HIGH, pull_up_down=self._gpio.PUD_OFF) self._gpio.setup(self.busy_pin, self._gpio.IN, pull_up_down=self._gpio.PUD_OFF) if self._spi_bus is None: import spidev self._spi_bus = spidev.SpiDev() self._spi_bus.open(0, self.cs_channel) self._spi_bus.no_cs = True self._spi_bus.max_speed_hz = 3000000 self._gpio_setup = True self._gpio.output(self.reset_pin, self._gpio.LOW) time.sleep(0.1) self._gpio.output(self.reset_pin, self._gpio.HIGH) time.sleep(0.1) self._busy_wait() # Resolution Setting # 10bit horizontal followed by a 10bit vertical resolution # we'll let struct.pack do the work here and send 16bit values # life is too short for manual bit wrangling self._send_command(UC8159_TRES, struct.pack(">HH", self.width, self.height)) # Panel Setting # 0b11000000 = Resolution select, 0b00 = 640x480, our panel is 0b11 = 600x448 # 0b00100000 = LUT selection, 0 = ext flash, 1 = registers, we use ext flash # 0b00010000 = Ignore # 0b00001000 = Gate scan direction, 0 = down, 1 = up (default) # 0b00000100 = Source shift direction, 0 = left, 1 = right (default) # 0b00000010 = DC-DC converter, 0 = off, 1 = on # 0b00000001 = Soft reset, 0 = Reset, 1 = Normal (Default) self._send_command( UC8159_PSR, [ 0b11101111, # See above for more magic numbers 0x08 # display_colours == UC8159_7C ]) # Power Settings self._send_command( UC8159_PWR, [ (0x06 << 3) | # ??? - not documented in UC8159 datasheet (0x01 << 2) | # SOURCE_INTERNAL_DC_DC (0x01 << 1) | # GATE_INTERNAL_DC_DC (0x01), # LV_SOURCE_INTERNAL_DC_DC 0x00, # VGx_20V 0x23, # UC8159_7C 0x23 # UC8159_7C ]) # Set the PLL clock frequency to 50Hz # 0b11000000 = Ignore # 0b00111000 = M # 0b00000111 = N # PLL = 2MHz * (M / N) # PLL = 2MHz * (7 / 4) # PLL = 2,800,000 ??? self._send_command(UC8159_PLL, [0x3C]) # 0b00111100 # Send the TSE register to the display self._send_command(UC8159_TSE, [0x00]) # Colour # VCOM and Data Interval setting # 0b11100000 = Vborder control (0b001 = LUTB voltage) # 0b00010000 = Data polarity # 0b00001111 = Vcom and data interval (0b0111 = 10, default) self._send_command(UC8159_CDI, [0x37]) # 0b00110111 # Gate/Source non-overlap period # 0b11110000 = Source to Gate (0b0010 = 12nS, default) # 0b00001111 = Gate to Source self._send_command(UC8159_TCON, [0x22]) # 0b00100010 # Disable external flash self._send_command(UC8159_DAM, [0x00]) # UC8159_7C self._send_command(UC8159_PWS, [0xAA]) # Power off sequence # 0b00110000 = power off sequence of VDH and VDL, 0b00 = 1 frame (default) # All other bits ignored? self._send_command( UC8159_PFS, [0x00] # PFS_1_FRAME )
def __init__(self, ref_volts): self.ref_volts = ref_volts self.spi = spidev.SpiDev() self.spi.open(0, 0) self.spi.max_speed_hz = 1000000 # 1MHz
import time import keyboard import spidev styrmodul_spi = spidev.SpiDev() styrmodul_spi.open(0, 1) styrmodul_spi.max_speed_hz = 10000 def main(): while True: response = styrmodul_spi.readbytes(1) if response == 0xD0: time.sleep(0.01) if keyboard.is_pressed('up'): styrmodul_spi.writebytes([0x01]) print("up") elif keyboard.is_pressed('down'): styrmodul_spi.writebytes([0x02]) print("down") elif keyboard.is_pressed('left'): styrmodul_spi.writebytes([0x03]) print('left') elif keyboard.is_pressed('right'): styrmodul_spi.writebytes([0x04]) print('right') time.sleep(0.01) main()
# Auther:y.kou. # web site: http://www.mille-feuille.mcugear.com/ # Date : 30/7/2015 ################################################################################################################## #Revision Information # ################################################################################################################## #!/usr/bin/python from ..mil import mil import spidev from ..mil import p from ..mil import wiringdata import time DAspibus = spidev.SpiDev(0, 1) #DAspibus.max_speed_hz = 2000000 moduleAddress1 = 0x8000 moduleAddress2 = 0x0009 moduleAddress = 0x80000009 def getInfo(Number): if ((Number >= 0) and (Number <= 3)): address = moduleAddress + Number address2 = moduleAddress2 + Number address1 = moduleAddress1 #check address testaddr = (address1 << 16) + address2 if address != testaddr: print "ERROR: Device address is not correct!"
def InitSPI(): """returns an opened spi connection to device(0,0) in mode 0""" spiObject = spidev.SpiDev() spiObject.open(0, 0) spiObject.mode = 0 return spiObject
import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import spidev DATA_PIPE_0 = 0 DATA_PIPE_1 = 1 DATA_PIPE_2 = 2 DATA_PIPE_3 = 3 DATA_PIPE_4 = 4 DATA_PIPE_5 = 5 tx_address = [0xE7, 0xE7, 0xE7, 0xE7, 0xE7] rx_address = [0xE7, 0xE7, 0xE7, 0xE7, 0xE7] GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) my_nrf = NRF24(GPIO, spidev.SpiDev()) my_nrf.begin(0, 25) #When you connect an external DS18B20 temperature sensor to #the PCB, change the transfer size to 10 TRANSFER_SIZE = 8 #TRANSFER_SIZE = 10 #Standard nRF24L01+ Settings for communication with the Small Weather Station #Don't forget to change these when changing the settings of the station! my_nrf.setPALevel(NRF24.PA_MIN) my_nrf.setDataRate(NRF24.BR_250KBPS) my_nrf.setCRCLength(NRF24.CRC_8) my_nrf.setPayloadSize(TRANSFER_SIZE) my_nrf.setChannel(2) my_nrf.setAutoAck(False)
import sys import spidev # instantiate the spi object spi = spidev.SpiDev(32766, 1) # set the speed to 4MHz spi.max_speed_hz = 4000000 # make an array of 4096 bytes of incremental data to send vals = [] for i in range(0, 16): vals.extend(range(0, 256)) # number of transmissions to make repeat = 8 print "Starting xfers, writing %d bytes %d times in a row" % (len(vals), repeat) for i in range(0, repeat): # perform the transfer #spi.xfer(vals) spi.writebytes(vals) print "Done"
#!/usr/bin/python import spidev import time from scarf_slave import scarf_slave spi = spidev.SpiDev(0, 0) spi.max_speed_hz = 1000000 spi.mode = 0b00 ss = scarf_slave(slave_id=0x01, num_addr_bytes=1, spidev=spi, debug=False) for ss_id in range(1, 128): ss.slave_id = ss_id if (ss.read_id() != 0x00): print "Found scarf slave at 0x%02x" % ss.slave_id
def __init__(self, thread_id, notification_queue, sleeptime, pin = 0): super().__init__(thread_id, notification_queue, sleeptime) # python 3 syntax only self.pin = pin self.spi = spidev.SpiDev() self.spi.open(0,0)
# Author: My MX import time import spidev as SPI import SSD1306 import Image # Raspberry Pi pin configuration: RST = 19 DC = 16 bus = 0 device = 0 # 128x32 display with hardware I2C: disp = SSD1306.SSD1306(rst=RST, dc=DC, spi=SPI.SpiDev(bus, device)) # Initialize library. disp.begin() # Clear display. disp.clear() disp.display() # Load image based on OLED display height. Note that image is converted to 1 bit color. image = Image.open('happycat.ppm').convert('1') # Alternatively load a different format image, resize it, and convert to 1 bit color. #image = Image.open('happycat.png').resize((disp.width, disp.height), Image.ANTIALIAS).convert('1') # Display image.
current_0 = [0]*3 current_1 = [0]*3 # Initialize movement time. movetime = 200 # Initialize opening gesture. pwm_1 = 1500 pwm_2 = 1500 pwm_3 = 1500 pwm_4 = 1500 pwm_5 = 2400 pwm_6 = 1500 # Start SPI connection spi = spidev.SpiDev() # Created an object spi.open(0,0) # Establish network connection. s = setupSocket() # Enter the password. while True: pword = input("Enter the word: ") s.sendall(pword.encode('utf-8')) aword = s.recv(1024) aword = aword.decode('utf-8') if aword == 'Login Successful': time.sleep(2) print(aword) time.sleep(3)
import time import math from decimal import * from pyardrone import ARDrone,at from contextlib import suppress import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import time import spidev import struct import sys #GLOBAL VARIABLES #------------------------------------------------------------------------------------------------- pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]] radio = NRF24(GPIO, spidev.SpiDev()) sample_time=0.05 u=[0,0,0] e=[0,0,0] e1=[0,0,0] u1=[0,0,0] pen=[0,0] ref=0; pitch_ref=0 roll_ref=0 x=[0,0] y=[0,0] x_ang=[0,0,0,0,0,0] y_ang=[0,0,0,0,0,0] phi= [0,0,0,0,0,0]
import spidev import os from time import sleep import RPi.GPIO as GPIO from pidev.stepper import stepper from Slush.Devices import L6470Registers from pidev.Cyprus_Commands import Cyprus_Commands_RPi as cyprus spi = spidev.SpiDev() cyprus.initialize() # initialize the RPiMIB and establish communication cyprus.setup_servo(1) # cyprus.setup_servo(2) # cyprus.set_servo_position(2, 0.5) cyprus.set_servo_position(1, 0) sleep(1) cyprus.set_servo_position(1, 1) # for i in range(1, 41): # number = 0.5 + i/80.0 # cyprus.set_servo_position(2, number) # print(number) # sleep(0.5) # sleep(1) # cyprus.set_servo_position(2, 0.5) limit_pressed = (cyprus.read_gpio() & 0b0001) == 0 counter = 0 ''' while counter != 50:
# THE SOFTWARE. # import time import RPi.GPIO as GPIO import spidev # Pin definition RST_PIN = 17 DC_PIN = 25 CS_PIN = 8 BUSY_PIN = 24 # SPI device, bus = 0, device = 0 SPI = spidev.SpiDev(0, 0) def digital_write(pin, value): GPIO.output(pin, value) def digital_read(pin): return GPIO.input(BUSY_PIN) def delay_ms(delay_time): time.sleep(delay_time / 1000.0) def spi_writebyte(data):