Raspberry Pi, Arduino, Sensors and the data they produce

Sensor Network –First Deployment

Well, you have to start somewhere, so while this code is neither clean nor fully functional, it does demonstrate the functionality of the effort underway. This code reflect two sensors basically streaming their name and current info, and the receiver RPi scrolling the received info across the screen.

Also my first attempt at putting code in the blog, so we’ll see how it works.

The next code iterations will remove all the screen displays and move to writing a file with the sensor node name and accompanying data from the sensors to a comma deliminated file (.csv).

Arduino based sensors transmitting to the Raspberry Pi via NRF24L01+

This post shows two code blocks, one for any Arduino sensor node and the second is the RPi receiving code.
The Arduino Sensor Node Transmitter -Send-Recieve

#include #include #include // ce,csn pins RF24 radio(9, 10); void setup(void) { while (!Serial); Serial.begin(9600); radio.begin(); radio.setPALevel(RF24_PA_MAX); radio.setChannel(0x76); radio.openWritingPipe(0xF0F0F0F0E1LL); const uint64_t pipe = 0xE8E8F0F0E1LL; radio.openReadingPipe(1, pipe); radio.enableDynamicPayloads(); radio.powerUp(); } void loop(void) { radio.startListening(); Serial.println(“Starting Loop. Radio on.”); char receivedMessage[32] = {0}; if (radio.available()) { radio.read(receivedMessage, sizeof(receivedMessage)); Serial.println(receivedMessage); Serial.println(“Turning off the Radio.”); radio.stopListening(); String stringMessage(receivedMessage); if (stringMessage == “GETSTRING”) { Serial.println(“Looks like they want a string!”); const char text[] = “Hello World!” ; radio.write(text, sizeof(text)); Serial.println(“We sent our message.”); } } delay(1000); }

Raspberry Pi Gateway -Send-Recieve

import RPi.GPIO as GPIO from lib_nrf24 import NRF24 import time import spidev GPIO.setmode(GPIO.BCM) pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]] radio = NRF24(GPIO, spidev.SpiDev()) radio.begin(0,17) radio.setPayloadSize(32) radio.setChannel(0x76) radio.setDataRate(NRF24.BR_1MBPS) 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() message = list(“GETSTRING”) while len(message) 2: print (“Timed out.”) break receivedMessage = [] radio.read(receivedMessage, radio.getDynamicPayloadSize()) print(“Received: {}”.format(receivedMessage)) print(“Translating our received Message into unicode characters…”) string = “” for n in receivedMessage: if (n >= 32 and n <=126): string += chr(n) print(“Our received message decodes to: {}”.format(string)) radio.stopListening() time.sleep(1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: