nRF24L01+ ATmega328P->Raspberry Pi

Sends command from Raspberry Pi to Arduino (programmed in C).

AVR code available here: https://github.com/Ewlbo/Node-RED-nRF24L01-AVR-RPi

[{"id":"ee3cba7e.0d7d78","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"150b649c.aaa7eb","type":"ui_base","theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#676767","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"default":"#4B7930","baseColor":"#097479","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","reset":false},"themeState":{"base-color":{"default":"#097479","value":"#097479","edited":false},"page-titlebar-backgroundColor":{"value":"#676767","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#000000","edited":false},"group-textColor":{"value":"#8d8d8d","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#676767","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"6b38c3f6.dc15ac","type":"ui_tab","z":"","name":"Blue Unit air quality monitoring","icon":"dashboard"},{"id":"5169aa31.e04dc4","type":"ui_tab","z":"","name":"nRF24L01+","icon":"dashboard"},{"id":"ee21d52a.576fe8","type":"ui_group","z":"","name":"UI2","tab":"5169aa31.e04dc4","disp":false,"width":"6","collapse":false},{"id":"ae19efb7.166b8","type":"python-function","z":"ee3cba7e.0d7d78","name":"nRF command","func":"import RPi.GPIO as GPIO\nfrom lib_nrf24 import NRF24\nimport time\nimport spidev\nimport sys\n\nGPIO.setwarnings(False)\nGPIO.setmode(GPIO.BCM)\npipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]\n\nradio = NRF24(GPIO, spidev.SpiDev())\nradio.begin(0, 17)\n\nradio.setPayloadSize(32)\nradio.setChannel(0x76)\nradio.setDataRate(NRF24.BR_2MBPS)\nradio.setPALevel(NRF24.PA_MIN)\n\nradio.setAutoAck(True)\nradio.enableDynamicPayloads()\nradio.enableAckPayload()\n\nradio.openWritingPipe(pipes[0])\nradio.openReadingPipe(1, pipes[1])\n\ntimeout = 0\n\ndef send():\n        radio.stopListening()\n        payload = msg['payload']\n        message = list(str(payload))\n        while len(message) < 32:\n                message.append(0)\n\n        radio.write(message)\n        radio.startListening()\n\nstart =  time.time()\nsend()\n\nwhile not radio.available(0):\n        time.sleep(1 / 100)\n        if time.time() - start > 2:\n                timeout += 1\n                if timeout == 3:\n                        msg['payload'] = \"Device not reachable\"\n                        return msg\n                        sys.exit()\n                start = time.time()\n                send()\n\nreceivedMessage = []\nradio.read(receivedMessage, radio.getDynamicPayloadSize())\n\nstring = \"\"\nfor n in receivedMessage:\n        # Decode into standard unicode set\n        if (n >= 32 and n <= 126):\n                string += chr(n)\n\nmsg['payload'] = string\n\nradio.stopListening()\n\nreturn msg\nsys.exit()\n","outputs":1,"x":480,"y":160,"wires":[["d43ee873.cc1238"]]},{"id":"8cb68ba.3f66b78","type":"ui_chart","z":"ee3cba7e.0d7d78","name":"","group":"ee21d52a.576fe8","order":4,"width":"0","height":"0","label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"20","ymax":"35","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":1030,"y":120,"wires":[[],[]]},{"id":"d1d90d44.a17b9","type":"ui_gauge","z":"ee3cba7e.0d7d78","name":"Temperature","group":"ee21d52a.576fe8","order":3,"width":"0","height":"0","gtype":"donut","title":"Temperature","label":"°C","format":"{{value}}","min":"0","max":"40","colors":["#039be5","#049be5","#059be5"],"seg1":"","seg2":"","x":1030,"y":160,"wires":[]},{"id":"e78fa641.acaf58","type":"function","z":"ee3cba7e.0d7d78","name":"isNaN","func":"if (isNaN(msg.payload) === false)\n{\n    return msg;\n}\n","outputs":1,"noerr":0,"x":870,"y":140,"wires":[["d1d90d44.a17b9","8cb68ba.3f66b78"]]},{"id":"d43ee873.cc1238","type":"function","z":"ee3cba7e.0d7d78","name":"Get response","func":"msg1 = {};\n\nif (msg.payload == \"Device not reachable\")\n{\n    msg1.payload = \"Disconnected\";\n    return [null,msg1];\n}\nelse if (msg.payload == \"OK\")\n{\n    msg1.payload = \"Connected\";\n    return [null,msg1];\n}\nelse\n{\n    msg1.payload = \"Connected\";\n    return [msg,msg1];\n}\n","outputs":"2","noerr":0,"x":680,"y":160,"wires":[["e78fa641.acaf58"],["e478c00c.10631"]],"outputLabels":["msg","msg1"]},{"id":"e478c00c.10631","type":"ui_text","z":"ee3cba7e.0d7d78","group":"ee21d52a.576fe8","order":2,"width":0,"height":0,"name":"","label":"Status","format":"{{msg.payload}}","layout":"row-spread","x":870,"y":180,"wires":[]},{"id":"104553cf.237f6c","type":"ui_button","z":"ee3cba7e.0d7d78","name":"","group":"ee21d52a.576fe8","order":1,"width":0,"height":0,"passthru":false,"label":"Send","color":"","bgcolor":"","icon":"","payload":"REQUEST DATA","payloadType":"str","topic":"","x":310,"y":160,"wires":[["ae19efb7.166b8","e478c00c.10631"]]}]
Ewlbo

Flow Info

created 9 months, 1 week ago

Node Types

Core
  • function (x2)
Other

Tags

  • nRF24L01
  • nRF24L01+
  • RaspberryPi
  • Raspberry
  • Pi
  • Arduino
  • ATmega328P
  • AVR
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option