Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte expected_sensor_type_byte = 0x33;
- byte expected_hello_byte = 0x32;
- byte expected_datarequest_byte = 0x31;
- float temperature, humidity, pressure;
- void setup() {
- //Initiating serial communication and flushing serial port, just for good measure
- Serial.begin(9600);
- Serial.flush();
- randomSeed(analogRead(A0));
- }
- void loop() {
- // Check if there is something on the serial port
- if (Serial.available()) {
- //read available data, save to recieved_data
- int recieved_data = Serial.read();
- //Did we recieve the hello byte?
- //This is used by the Raspberry PI to ensure a stable connection
- if (recieved_data == expected_hello_byte) {
- Serial.print("HELLO");
- delay(50);
- }
- //Did we recieve the sensor type byte?
- if (recieved_data == expected_sensor_type_byte) {
- //These lines defines the values to be logged in the csv-file
- //First line is the name of your Arduino Node
- //The following lines are optional, and you can add or remove as many as you want
- //For each Serial.print("name of value") + Serial.print("\t") a column will be generated.
- Serial.print("TempNode");
- Serial.print("\t");
- Serial.print("Temp [C]");
- Serial.print("\t");
- Serial.print("Humidity [%]");
- Serial.print("\t");
- Serial.print("Pressure [kPa]");
- delay(50);
- }
- //Did we recieve the data request byte?
- if (recieved_data == expected_datarequest_byte) {
- //Reading sensor values
- temperature = random(-30, 3000)/100.00;
- humidity = random(3000,9000)/100.00;
- pressure = random(95000, 105000)/100.00;
- //Printing them to the serial port.
- //This has to be the same order as the names from last if.
- Serial.print(temperature);
- Serial.print(";");
- Serial.print(humidity);
- Serial.print(";");
- Serial.print(pressure);
- Serial.print(";");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment