diff --git a/README.md b/README.md index a586321..6e28266 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,15 @@ This is a port of the RFM69 library for arduino from https://github.com/LowPower Attach the RFM69 as follows: -| RFM pin | Pi pin -| ------- |------- -| 3v3 | 17 -| DIO0 | 18 (GPIO24) -| MOSI | 19 -| MISO | 21 -| CLK | 23 -| NSS | 24 -| Ground | 25 -| RESET | 29 +| RFM pin | # | Pi pin header description| Pi pin header description | # | RFM pin +| ------- |----|-------------- |------------- |----| ------- +| 3v3 | 17 | 3.3V Power | (GPIO24) | 18 | DIO0 +| MOSI | 19 | MOSI (GPIO10) | GND | 20 | Ground +| MISO | 21 | MISO (GPIO9) | (GPIO25) | 22 | +| CLK | 23 | SCLK (GPIO11) | CE0 (GPIO8) | 24 | NSS (CS) +| Ground | 25 | GND | CE1 (GPIO7) | 26 | +| | 27 | ID_SD (N/A) | ID_SC (N/A) | 28 | +| RESET | 29 | (GPIO5) | GND | 30 | Ground You can change the interrupt pin (GPIO24) in the class init. @@ -37,3 +36,14 @@ cd py-spidev sudo make install ``` +And don't forget to enable the SPI interface: + +```bash +sudo raspi-config +``` + +Select "Interface Options", -> "SPI", choose "Yes" to enable it and reboot. + +```bash +sudo reboot +``` diff --git a/example.py b/example.py index c6e281c..71900de 100755 --- a/example.py +++ b/example.py @@ -23,12 +23,22 @@ if test.sendWithRetry(2, "blah", 3, 20): print "ack recieved" print "reading" + while True: - test.receiveBegin() - while not test.receiveDone(): - time.sleep(.1) - print "%s from %s RSSI:%s" % ("".join([chr(letter) for letter in test.DATA]), test.SENDERID, test.RSSI) - if test.ACKRequested(): - test.sendACK() -print "shutting down" -test.shutdown() + try: + test.receiveBegin() + while not test.receiveDone(): + time.sleep(.1) + print "%s from %s RSSI:%s" % ("".join([chr(letter) for letter in test.DATA]), test.SENDERID, test.RSSI) + if test.ACKRequested(): + test.sendACK() + except KeyboardInterrupt: + userAnswer = raw_input('Enter "yes" to cancel or "no" to keep running [yes/no]:').strip().lower() + + if userAnswer == 'yes': + # quit as requested by user + print "shutting down" + test.shutdown() + break + else: + continue diff --git a/radio1.py b/radio1.py index 467c908..f0e3ed0 100755 --- a/radio1.py +++ b/radio1.py @@ -33,33 +33,41 @@ print "starting loop..." sequence = 0 -while True: - msg = "I'm radio %d: %d" % (NODE, sequence) - sequence = sequence + 1 +while True: + try: + msg = "I'm radio %d: %d" % (NODE, sequence) + sequence = sequence + 1 - print "tx to radio 2: " + msg - if radio.sendWithRetry(2, msg, 3, 20): - print "ack recieved" + print "tx to radio 2: " + msg + if radio.sendWithRetry(2, msg, 3, 20): + print "ack recieved" - print "start recv..." - radio.receiveBegin() - timedOut=0 - while not radio.receiveDone(): - timedOut+=TOSLEEP - time.sleep(TOSLEEP) - if timedOut > TIMEOUT: - print "timed out waiting for recv" - break + print "start recv..." + radio.receiveBegin() + timedOut=0 + while not radio.receiveDone(): + timedOut+=TOSLEEP + time.sleep(TOSLEEP) + if timedOut > TIMEOUT: + print "timed out waiting for recv" + break - print "end recv..." - print " *** %s from %s RSSI:%s" % ("".join([chr(letter) for letter in radio.DATA]), radio.SENDERID, radio.RSSI) + print "end recv..." + print " *** %s from %s RSSI:%s" % ("".join([chr(letter) for letter in radio.DATA]), radio.SENDERID, radio.RSSI) - if radio.ACKRequested(): - print "sending ack..." - radio.sendACK() - else: - print "ack not requested..." + if radio.ACKRequested(): + print "sending ack..." + radio.sendACK() + else: + print "ack not requested..." + except KeyboardInterrupt: + userAnswer = raw_input('Enter "yes" to cancel or "no" to keep running [yes/no]:').strip().lower() -print "shutting down" -radio.shutdown() + if userAnswer == 'yes': + # quit as requested by user + print "shutting down" + radio.shutdown() + break + else: + continue diff --git a/radio2.py b/radio2.py index ea21be3..436bbf2 100755 --- a/radio2.py +++ b/radio2.py @@ -33,33 +33,40 @@ sequence=0 print "starting loop..." -while True: - - - msg = "I'm radio %d: %d" % (NODE, sequence) - sequence = sequence + 1 - - print "tx to radio 1: " + msg - if radio.sendWithRetry(1, msg, 3, 20): - print "ack recieved" - print "starting recv..." - radio.receiveBegin() - timedOut=0 - while not radio.receiveDone(): - timedOut+=TOSLEEP - time.sleep(TOSLEEP) - if timedOut > TIMEOUT: - print "timed out waiting for recv" +while True: + try: + msg = "I'm radio %d: %d" % (NODE, sequence) + sequence = sequence + 1 + + print "tx to radio 1: " + msg + if radio.sendWithRetry(1, msg, 3, 20): + print "ack recieved" + + print "starting recv..." + radio.receiveBegin() + timedOut=0 + while not radio.receiveDone(): + timedOut+=TOSLEEP + time.sleep(TOSLEEP) + if timedOut > TIMEOUT: + print "timed out waiting for recv" + break + + print "end recv..." + print " ### %s from %s RSSI:%s " % ("".join([chr(letter) for letter in radio.DATA]), radio.SENDERID, radio.RSSI) + + if radio.ACKRequested(): + radio.sendACK() + else: + print "ack not requested..." + except KeyboardInterrupt: + userAnswer = raw_input('Enter "yes" to cancel or "no" to keep running [yes/no]:').strip().lower() + + if userAnswer == 'yes': + # quit as requested by user + print "shutting down" + radio.shutdown() break - - print "end recv..." - print " ### %s from %s RSSI:%s " % ("".join([chr(letter) for letter in radio.DATA]), radio.SENDERID, radio.RSSI) - - if radio.ACKRequested(): - radio.sendACK() - else: - print "ack not requested..." - -print "shutting down" -radio.shutdown() + else: + continue