Ejemplo n.º 1
0
    def __init__(self, csn, ce, spi_major=0, spi_minor=0):
        self._spi = spidev.SpiDev()
        self._spi.open(spi_major, spi_minor)
        self._csn = pi_header_1.pin(csn, direction=Out)
        self._ce = pi_header_1.pin(ce, direction=Out)

        self._registry = Registry(self)

        self._status = NRF24.STATUS.power_down

        # load defaults
        with self:
            self._registry['STATUS'] = 0b01110000
            self._registry['CONFIG'] = 0b00001010
            self._registry['EN_AA'] = 0b00000000
            self._registry['EN_RXADDR'] = 0b00000000
            self._registry['SETUP_AW'] = 0b00000011
            self._registry['SETUP_RETR'] = 0b00000011
            self._registry['RF_CH'] = 2
            self._registry['RF_SETUP'] = 0b0000111
            self._registry['DYNPD'] = 0b00000000
            self._registry['FEATURE'] = 0b00000000
            self._registry['TX_ADDR'] = 0xe7e7e7e7e7
            self._registry['RX_ADDR_P0'] = 0xe7e7e7e7e7
            self._registry['RX_PW_P0'] = 32

            self.pipes = {
                0: Pipe(self, 0, queue_size=4),
                1: Pipe(self, 1, queue_size=4),
                2: Pipe(self, 2, queue_size=4),
                3: Pipe(self, 3, queue_size=4),
                4: Pipe(self, 4, queue_size=4),
                5: Pipe(self, 5, queue_size=4),
            }
Ejemplo n.º 2
0
def fMain():
	with pi_header_1.pin(7, direction=In) as inPin:
		with pi_header_1.pin(11, direction=Out) as outPin:
		
			vTReceiver = threading.Thread(target=fReceiver, args=(inPin,))
			vTReceiver.daemon = True
			vTReceiver.start()
			
			vTTransmitter = threading.Thread(target=fTransmiter, args=(outPin,))
			vTTransmitter.daemon = True
			vTTransmitter.start()
			
			vTReceiver.join()
			vTTransmitter.join()
Ejemplo n.º 3
0
def fMain():
    with pi_header_1.pin(7, direction=In) as inPin:
        with pi_header_1.pin(11, direction=Out) as outPin:

            vTReceiver = threading.Thread(target=fReceiver, args=(inPin, ))
            vTReceiver.daemon = True
            vTReceiver.start()

            vTTransmitter = threading.Thread(target=fTransmiter,
                                             args=(outPin, ))
            vTTransmitter.daemon = True
            vTTransmitter.start()

            vTReceiver.join()
            vTTransmitter.join()
Ejemplo n.º 4
0
    def __init__(self):
        self.outfile = open("/home/pi/testit", 'a')

        # Grab a reference to the SPI device
        self.nrf24   = SPIDevice(0, 0) 

        # Setup chip-enable pin
        self.ce_pin = pi_header_1.pin(22, direction=Out) 
        self.ce_pin.open()
Ejemplo n.º 5
0
def get_interrupt_pin():
    """ Button interrupts are fed back to PI header via a GPIO pin.
        Since MCP23017 runs at 5V, and PI GPIOs take 3V3, need to set
        MCP23017 interrupts as "open drain" and use an internal pullup
        on the PI input pin.
    """
    return pi_header_1.pin(BUTTON_INTERRUPT_PIN,
                           direction=In,
                           interrupt=Falling,
                           pull=PullUp)
Ejemplo n.º 6
0
 def __init__(self):
     self.nrf24 = SPIDevice(0, 0)
     # set auto-ack on data pipe 0 and 1 (EN_AA)
     self.SET_EN_AA = ENAA_P0 | ENAA_P1
     # use data pipes 0 and 1 (EN_RXADDR)
     self.SET_EN_RXADDR = ERX_P0 | ERX_P1
     # 1Mbps, 0dB and no LNA gain (RF_SETUP)
     self.SET_RF_SETUP = 0x00
     # set dynamic payloads on data pipe 0 and 1. requires corresponding ENAA_Px (DYNPD)
     self.SET_DYNPD = DPL_P0 | DPL_P1
     # enable dynamic payloads
     self.SET_FEATURE = EN_DPL
     # receiver address(RX_ADDR_P0)
     self.RX_ADDR_P1 = [0x47, 0x47, 0x47, 0x47, 0x47]
     # transmitter address (TX_ADDR)
     self.TX_ADDRESS = [0x47, 0x47, 0x47, 0x47, 0x47]
     # set channel to 2400Mhz (RF_CH)
     self.SET_RF_CH = 36
     # set automatic retransmission to 15 retransmit on fail AA, 250uS delay(SETUP_RETR)
     self.SET_SETUP_RETR = BIT7 | BIT6 | BIT5 | BIT4
     # 5 byte address (SETUP_AW)
     self.SET_SETUP_AW = BIT0 | BIT1
     # enable CRC, I think (CONFIG)
     self.SET_CONFIG = EN_CRC
     self.nrf24.speed_hz = 500000
     self.CE_pin = pi_header_1.pin(16, direction=Out)
     with self.CE_pin:
         self.CE_pin.value = 0
         self.CE_pin.value = 1
     # IRQ pin with interrupt on high
     self.IRQ_pin = pi_header_1.pin(22, direction=In, interrupt=Falling)
     # epoll, activated with enableRX and write functions
     self.epoll = None
     self.readLoopFlag = False
     self.is_transmitting = False
     self.rf_status = 0
     self.last_received_pipe = None
     self.lastTXfailed = False
     self.radio_lock = Lock()
     self.setup()
	def __init__(self):
		self.nrf24 = SPIDevice(0, 0)
		self.TX_ADDRESS = [a,a,a,a,a]
		self.RX_ADDRESS = [a,a,a,a,a]
		self.RADIO_CHANNEL = 0
		self.PAYLOAD_SIZE = 5
		self.RADIO_MODE = 0b00100110
		self.nrf24.speed_hz=500000
		self.radio_pin = pi_header_1.pin(12, direction=Out)
		self.radio_pin.open()
		self.radio_pin.value=0
		self.radio_pin.value=1
		self.radio_lock=threading.Lock()
		self.setupRadio()
Ejemplo n.º 8
0
    def __init__(self):
        """__init__ function is allways run first, when the class is called!"""
        """Here we define ALL necesary class variables for operation"""
        self._nrf24SPI = SPIDevice(0,
                                   0)  #Define SPI-unit (used in doOperation)
        self._radio_pin = pi_header_1.pin(22,
                                          direction=Out)  #"CE" on nRF, output
        #self._radio_pin.open() #openin pin so that it's state could be changed

        try:
            self._radio_pin.open(
            )  #openin pin so that it's state could be changed
        except:
            print("Do nothing!")
            #self._radio_pin.close() #openin pin so that it's state could be changed
            #self._radio_pin.open() #openin pin so that it's state could be changed

        self._mode = -1  #defines default mode which is not operational
        self._rxBufValid = 0
        self._buf = ""
        #not for all packets..
        self._txHeaderTo = 0xFF
        self._txHeaderFrom = 0xFF
        self._txHeaderId = 0x00
        self._txHeaderFlags = 0x00
        #comm with MIRF
        self._thisAddress = 0xff  #default address
        self._rxGood = 0

        self._configuration = NRF24_EN_CRC  #| NRF24_CRCO #default configuration
        self._chipEnablePin = 22

        self._packetHeaderLength = 1
        #related to ACCENTURE application
        self._basicPacket = []
        #self._nodeID = 44

        #defiene necesary for init
        self._packetLength = 5  #used to define PIPE length
        self._enAutoACK = True  #enable on ALL pipes
        self._addresWidth = AddressWidth5bytes  #5byte address
        self._autoRetransmitDelay = 250
        self._autoRetransmitCount = 3
        self._channel = 100
        self._transferRate = DataRate2Mbps
        self._transferPower = TransmitPower0dBm
        self._continiouseWave = False
        self._SPISpeed = 1000000
        self._pipeLength = 5
        self._carrierDetect = False  #BUG
Ejemplo n.º 9
0
 def __init__(self):
     self.nrf24 = SPIDevice(0, 0)
     self.TX_ADDRESS = [a, a, a, a, a]
     self.RX_ADDRESS = [a, a, a, a, a]
     self.RADIO_CHANNEL = 0
     self.PAYLOAD_SIZE = 5
     self.RADIO_MODE = 0b00100110
     self.nrf24.speed_hz = 500000
     self.radio_pin = pi_header_1.pin(12, direction=Out)
     self.radio_pin.open()
     self.radio_pin.value = 0
     self.radio_pin.value = 1
     self.radio_lock = threading.Lock()
     self.setupRadio()
Ejemplo n.º 10
0
    def __init__(self):
        """__init__ function is allways run first, when the class is called!"""
        """Here we define ALL necesary class variables for operation"""
        self._nrf24SPI = SPIDevice(0, 0) #Define SPI-unit (used in doOperation)
        self._radio_pin = pi_header_1.pin(22, direction=Out) #"CE" on nRF, output
        #self._radio_pin.open() #openin pin so that it's state could be changed

        try:
            self._radio_pin.open() #openin pin so that it's state could be changed
        except:
            print("Do nothing!")
            #self._radio_pin.close() #openin pin so that it's state could be changed
            #self._radio_pin.open() #openin pin so that it's state could be changed

        self._mode = -1 #defines default mode which is not operational
        self._rxBufValid = 0
        self._buf = ""
        #not for all packets..
        self._txHeaderTo = 0xFF
        self._txHeaderFrom = 0xFF
        self._txHeaderId = 0x00
        self._txHeaderFlags = 0x00
        #comm with MIRF
        self._thisAddress = 0xff #default address
        self._rxGood=0
        
        self._configuration = NRF24_EN_CRC #| NRF24_CRCO #default configuration
        self._chipEnablePin = 22
        
        self._packetHeaderLength = 1
        #related to ACCENTURE application
        self._basicPacket = []
        #self._nodeID = 44
        
        #defiene necesary for init
        self._packetLength = 5 #used to define PIPE length
        self._enAutoACK = True #enable on ALL pipes
        self._addresWidth = AddressWidth5bytes #5byte address
        self._autoRetransmitDelay = 250
        self._autoRetransmitCount = 3
        self._channel = 100
        self._transferRate = DataRate2Mbps
        self._transferPower = TransmitPower0dBm
        self._continiouseWave = False
        self._SPISpeed = 1000000
        self._pipeLength = 5
        self._carrierDetect = False #BUG
Ejemplo n.º 11
0
def test():
    with i2c.I2CMaster() as bus, \
         pi_header_1.pin(ALERT_PIN, direction=In, interrupt=Both, pull=PullUp) as alrt_pin, \
         Selector() as selector:
        selector.add(alrt_pin)
        tmp102 = TMP102(bus)
        tmp102.setExtendedMode(1)
        tmp102.setConversionRate(0)
        tmp102.setBoundTemp(False, 17.0)
        tmp102.setBoundTemp(True, 19.0)
        print(tmp102.getBoundTemp(False))
        print(tmp102.getBoundTemp(True))
        #tmp102.setAlertMode(1)
        tmp102.setFault(1)
        while True:
            selector.wait(30)
            if selector.ready is alrt_pin and selector.has_input:
                print("ALERT: alert_pin:", alrt_pin.value)
            temp = tmp102.readTemperature()
            alrt = tmp102.alert()
            print("Temperature: {0:6}C, alert: {1}, alert_pin: {2}".format(temp, alrt, alrt_pin.value))
Ejemplo n.º 12
0
    def __init__(self):
        """__init__ function is allways run first, when the class is called!"""
        self.nrf24 = SPIDevice(0, 0) #Define SPI-unit (used in doOperation)

        self.radio_pin = pi_header_1.pin(12, direction=Out) #"CE" on nRF, output
Ejemplo n.º 13
0
# Graphite
import socket
import time

CARBON_SERVER = '127.0.0.1'
CARBON_PORT = 2003

if __name__ == "__main__":

    # Setup radio
    radio = NRF24L01P()
    radio.setup()

    try:
        # Setup the interrupt-pin
        interrupt_pin = pi_header_1.pin(18, direction=In, interrupt=Falling)

        # Monitor the radio's interrupt pin using epoll
        epoll = select.epoll() 

        with interrupt_pin:

            # Register the interrupt-pin as an edge-triggered input
            epoll.register(interrupt_pin, select.EPOLLIN | select.EPOLLET) 

            # The main event-loop
            while True: 
                radio.start_listening()
                                
                # An interrupt indicates the radio has incoming data
                events = epoll.poll()