PSU Optical Grounding Isolation
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=219744&start=400#p1416079
Wallwart with a ground pin
Macbook charger teardown: The surprising complexity inside Apple’s power adapter
http://www.righto.com/2015/11/macbook-charger-teardown-surprising.html
kung fu
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=219744&start=200
i2c buffer
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=219744&start=175#p1367903
Rooftop Garden
https://www.raspberrypi.org/forums/download/file.php?id=24832
Lipo power bank
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=219744&start=150#p1362456
Lead acid batteries
https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=219744&start=150#p1362466
meanwell psu
https://raspberrypi.stackexchange.com/questions/103628/reporting-undervoltage-accidental-reverse-voltage
Tutorial 13 – Wireless Pi to Pi Python Communication with NRF24L01+
1. Login to both your devices using PuTTy or your Ubuntu terminal.
2. Login to both your devices’ GUIs using VNC server (Linux / Windows).
wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
ls
unzip master.zip
rm master.zip
cd py–spidev–master
mkdir NRF24L01
In Python 3 (IDLE), create a new file.
24. The names could be: TransmitPi.py (in one of the devices) and Receive.py (in the other device). Save them in the NRF24L01 directory in both the devices.
24. The names could be: TransmitPi.py (in one of the devices) and Receive.py (in the other device). Save them in the NRF24L01 directory in both the devices.
25. In the file TransmitPi.py, write the following code with comments (line starting
with “#”) for clear understanding and save (press Cntrl + S on your PC keyboard) the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
# radio.openReadingPipe(1, pipes[1])
radio.openWritingPipe(pipes[1])
radio.printDetails()
# radio.startListening()
# message = list(input(“Enter a message to send: “))
while(1):
message = list(“Hello World is awesome”)
radio.write(message)
print(“We sent the message of {}”.format(message))
# Check if it returned ackPL
if radio.isAckPayloadAvailable():
returnedPL = []
radio.read(returnedPL, radio.getDynamicPayloadSize())
print(“Our returned payload was {}”.format(returnedPL))
else:
print(“No payload received”)
time.sleep(1)
|
26. In the file ReceivePi.py, write the following code with comments (line starting with “#”) for clear understanding and save (press Cntrl + S on your PC keyboard) the file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(0, pipes[1])
radio.printDetails()
radio.startListening()
while(1):
ackPL = [1]
while not radio.available(0):
time.sleep(1 / 100)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print(“Received: {}”.format(receivedMessage))
print(“Translating the receivedMessage into unicode characters”)
string = “”
for n in receivedMessage:
# Decode into standard unicode set
if (n >= 32 and n <= 126):
string += chr(n)
print(string)
radio.writeAckPayload(1, ackPL, len(ackPL))
print(“Loaded payload reply of {}”.format(ackPL))
|
27. Finally, run the script by clicking on Run -> Run Module in the menu bar or by pressing F5 on your PC keyboard.
TransmitPi.py output
ReceivePi.py output
28. For a master/slave setup, follow steps 1 – 23 as above and run the following python scripts Master.py and Slave.py on your respective devices.
Master.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(1, pipes[0])
radio.openWritingPipe(pipes[1])
radio.printDetails()
# radio.startListening()
def receiveData():
print(“Ready to receive data.”)
radio.startListening()
while not radio.available(0):
time.sleep(1 / 100)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print(“Translating receivedMessage into unicode characters…”)
string = “”
for n in receivedMessage:
# Decode into standard unicode set
if (n >= 32 and n <= 126):
string += chr(n)
print(“Our slave sent us: {}:”.format(string))
radio.stopListening()
while(1):
command = “GET_TEMP”
message = list(command)
# message = list(“Hello World”)
radio.write(message)
print(“We sent the message of {}”.format(message))
# Check if it returned ackPL
if radio.isAckPayloadAvailable():
returnedPL = []
radio.read(returnedPL, radio.getDynamicPayloadSize())
print(“Our returned payload was {}”.format(returnedPL))
receiveData()
else:
print(“No payload received”)
time.sleep(1)
|
Slave.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openWritingPipe(pipes[0])
radio.openReadingPipe(1, pipes[1])
radio.printDetails()
radio.startListening()
def getTemp():
temp = 25
return str(temp)
def sendData(ID, value):
radio.stopListening()
time.sleep(0.25)
message = list(ID) + list(value)
print(“About to send message.”)
radio.write(message)
print(“Sent the data”)
radio.startListening()
while(1):
ackPL = [1]
radio.writeAckPayload(1, ackPL, len(ackPL))
while not radio.available(0):
time.sleep(1 / 100)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print(“Received: {}”.format(receivedMessage))
print(“Translating the receivedMessage into unicode characters”)
string = “”
for n in receivedMessage:
# Decode into standard unicode set
if (n >= 32 and n <= 126):
string += chr(n)
print(string)
# We want tp react to the command from the master.
command = string
if command == “GET_TEMP”:
print(“We should get the temperature!”)
tempID = “temp_”
temp = getTemp()
sendData(tempID, temp)
command = “”
radio.writeAckPayload(1, ackPL, len(ackPL))
print(“Loaded payload reply of {}”.format(ackPL))
|
Master.py output
Slave.py output
Hardware Connections ->
1. Raspberry Pi 3 GPIO Header.
2. nRF24L01 pinout
3. nRF24L01 to Pi connections.
4. Wire up both the devices to the RF modules.
Categories: Uncategorized