Commit 77cf2c2b authored by Markéta Jedličková's avatar Markéta Jedličková
Browse files

Examples clean up

parent 414b3152
...@@ -15,32 +15,31 @@ ...@@ -15,32 +15,31 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include "Adafruit_BME280.h" // Include Adafruit BME280 library
#include "Adafruit_BME280.h" // include Adafruit BME280 library #define Serial SerialUSB // Change default serial to SAMD USB serial
#define Serial SerialUSB // change default serial to SAMD USB serial #define BME280_ADDRESS_OPEN_CANSAT 0x77 // Set BME's address (according to the circuit)
#define SEALEVELPRESSURE_HPA (1013.25) // Set sea level pressure value(see: https://en.wikipedia.org/wiki/Atmospheric_pressure)
#define BME280_ADDRESS_OPEN_CANSAT 0x77 // set BME's address (according to the circuit) // Create object 'bme' from the library, which will
#define SEALEVELPRESSURE_HPA (1013.25) // set sea level pressure value(see: https://en.wikipedia.org/wiki/Atmospheric_pressure)
// create object 'bme' from the library, which will
// be used to access the library methods by a dot notation // be used to access the library methods by a dot notation
Adafruit_BME280 bme; Adafruit_BME280 bme;
int ms_delay = 500; // Number of milliseconds between each two measurements int ms_delay = 500; // Number of milliseconds between each two measurements
// epty variables for measured values // Empty variables for measured values
float temperature_bme280 = 0; float temperature_bme280 = 0;
float pressure_bme280 = 0; float pressure_bme280 = 0;
float altitude_bme280 = 0; float altitude_bme280 = 0;
float humidity_bme280 = 0; float humidity_bme280 = 0;
// this will only run once // This will only run once
void setup() void setup()
{ {
Serial.begin(57600); // start serial comm with baud rate of 57600Bd Serial.begin(57600); // Start serial comm with baud rate of 57600Bd
// wait for the Arduino serial (on your PC) to connect // Wait for the Arduino serial (on your PC) to connect
// please, open the Arduino serial console (right top corner) // please, open the Arduino serial console (right top corner)
// note that the port may change after uploading the sketch // note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC! // COMMENT OUT FOR USAGE WITHOUT A PC!
...@@ -48,7 +47,7 @@ void setup() ...@@ -48,7 +47,7 @@ void setup()
Serial.println("openCanSat BME280 test started"); Serial.println("openCanSat BME280 test started");
// begin communication with the BME280 on the previously specified address // Begin communication with the BME280 on the previously specified address
// print an error to the serial in case the sensor is not found // print an error to the serial in case the sensor is not found
if (!bme.begin(BME280_ADDRESS_OPEN_CANSAT)) if (!bme.begin(BME280_ADDRESS_OPEN_CANSAT))
{ {
...@@ -56,24 +55,24 @@ void setup() ...@@ -56,24 +55,24 @@ void setup()
return; return;
} }
Serial.println(); // print new line on serial to make the output look better :-; Serial.println(); // Print new line on serial to make the output look better :-;
} }
// code in this function will run repeatedly // Code in this function will run repeatedly
void loop() void loop()
{ {
// read values from BME280 into the variables // Read values from BME280 into the variables
temperature_bme280 = bme.readTemperature(); temperature_bme280 = bme.readTemperature();
pressure_bme280 = bme.readPressure() / 100.0F; pressure_bme280 = bme.readPressure() / 100.0F;
altitude_bme280 = bme.readAltitude(SEALEVELPRESSURE_HPA); altitude_bme280 = bme.readAltitude(SEALEVELPRESSURE_HPA);
humidity_bme280 = bme.readHumidity(); humidity_bme280 = bme.readHumidity();
// print the measured variables to serial // Print the measured variables to serial
Serial.println("Temperature = " + (String) temperature_bme280 + " °C"); Serial.println("Temperature = " + (String) temperature_bme280 + " °C");
Serial.println("Pressure = " + (String) pressure_bme280 + " hPa"); Serial.println("Pressure = " + (String) pressure_bme280 + " hPa");
Serial.println("Approx altitude = " + (String) altitude_bme280 + " m"); Serial.println("Approx altitude = " + (String) altitude_bme280 + " m");
Serial.println("Humidity = " + (String) humidity_bme280 + " %"); Serial.println("Humidity = " + (String) humidity_bme280 + " %");
Serial.println(); Serial.println();
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
} }
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
http://www.gnu.org/licenses/gpl-3.0.txt http://www.gnu.org/licenses/gpl-3.0.txt
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include <Adafruit_BMP280.h> // include Adafruit BMP280 library #include <Adafruit_BMP280.h> // include Adafruit BMP280 library
#define Serial SerialUSB // change default serial to SAMD USB serial #define Serial SerialUSB // change default serial to SAMD USB serial
...@@ -34,12 +32,12 @@ float temperature_bmp280 = 0; ...@@ -34,12 +32,12 @@ float temperature_bmp280 = 0;
float pressure_bmp280 = 0; float pressure_bmp280 = 0;
float altitude_bmp280 = 0; float altitude_bmp280 = 0;
// this will only run once // This will only run once
void setup() void setup()
{ {
Serial.begin(57600); // start serial comm with baud rate of 57600Bd Serial.begin(57600); // Start serial comm with baud rate of 57600Bd
// wait for the Arduino serial (on your PC) to connect // Wait for the Arduino serial (on your PC) to connect
// please, open the Arduino serial console (right top corner) // please, open the Arduino serial console (right top corner)
// note that the port may change after uploading the sketch // note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC! // COMMENT OUT FOR USAGE WITHOUT A PC!
...@@ -47,7 +45,7 @@ void setup() ...@@ -47,7 +45,7 @@ void setup()
Serial.println("openCanSat BMP280 test started"); Serial.println("openCanSat BMP280 test started");
// begin communication with the BMP280 on the previously specified address // Begin communication with the BMP280 on the previously specified address
// print an error to the serial in case the sensor is not found // print an error to the serial in case the sensor is not found
if (!bmp.begin(BMP280_ADDRESS)) if (!bmp.begin(BMP280_ADDRESS))
{ {
...@@ -55,22 +53,22 @@ void setup() ...@@ -55,22 +53,22 @@ void setup()
return; return;
} }
Serial.println(); // print new line on serial to make the output look better :-; Serial.println(); // Print new line on serial to make the output look better
} }
// code in this function will run repeatedly // Code in this function will run repeatedly
void loop() void loop()
{ {
// read values from BME280 into the variables // Read values from BME280 into the variables
temperature_bmp280 = bmp.readTemperature(); temperature_bmp280 = bmp.readTemperature();
pressure_bmp280 = bmp.readPressure(); pressure_bmp280 = bmp.readPressure();
altitude_bmp280 = bmp.readAltitude(1013.25); altitude_bmp280 = bmp.readAltitude(1013.25);
// print the measured variables to serial // Print the measured variables to serial
Serial.println("Temperature = " + (String) temperature_bmp280 + " *C"); Serial.println("Temperature = " + (String) temperature_bmp280 + " *C");
Serial.println("Pressure = " + (String) pressure_bmp280 + " Pa"); Serial.println("Pressure = " + (String) pressure_bmp280 + " Pa");
Serial.println("Approx altitude = " + (String) altitude_bmp280 + " m"); Serial.println("Approx altitude = " + (String) altitude_bmp280 + " m");
Serial.println(); Serial.println();
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
} }
...@@ -15,15 +15,16 @@ ...@@ -15,15 +15,16 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include "Open_Cansat_GPS.h"
#include <Wire.h> #include <Wire.h>
#include "../../libraries/Open_Cansat_GPS/src/Open_Cansat_GPS.h"
#define Serial SerialUSB #define Serial SerialUSB
OpenCansatGPS gps; OpenCansatGPS gps;
int ms_delay = 250; // Number of milliseconds for scan and between another scan is done
void setup() void setup()
{ {
while (!SerialUSB) {} while (!SerialUSB) {}
...@@ -40,10 +41,11 @@ void setup() ...@@ -40,10 +41,11 @@ void setup()
void loop() void loop()
{ {
// save start time in millisec // Save start time in millisec
uint32_t start = millis(); uint32_t start = millis();
if (gps.scan(250)) // Printing gps values if scan is successful
if (gps.scan(ms_delay))
{ {
Serial.println(String(" time to find fix: ") + (millis() - start) + String("ms")); Serial.println(String(" time to find fix: ") + (millis() - start) + String("ms"));
Serial.println(String(" datetime = ") + gps.getDateTimeString()); Serial.println(String(" datetime = ") + gps.getDateTimeString());
...@@ -53,5 +55,6 @@ void loop() ...@@ -53,5 +55,6 @@ void loop()
Serial.println(); Serial.println();
} }
delay(250); // Wait before next measurement
delay(ms_delay);
} }
...@@ -15,30 +15,29 @@ ...@@ -15,30 +15,29 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include <Adafruit_INA219.h> // Include Adafruit INA219 library
#include <Adafruit_INA219.h> // include Adafruit INA219 library
#define Serial SerialUSB // change default serial to SAMD USB serial #define Serial SerialUSB // Change default serial to SAMD USB serial
// create object 'ina219' from the library with address 0x40 // Create object 'ina219' from the library with address 0x40
// (according to the circuit, which will be used to access the // (according to the circuit, which will be used to access the
// library methods by a dot notation // library methods by a dot notation
Adafruit_INA219 ina219(0x40); Adafruit_INA219 ina219(0x40);
int ms_delay = 500; // Number of milliseconds between each two readings int ms_delay = 500; // Number of milliseconds between each two readings
// empty variables for measured values // Empty variables for measured values
float voltage_shunt = 0; float voltage_shunt = 0;
float voltage_bus = 0; float voltage_bus = 0;
float current_mA = 0; float current_mA = 0;
float voltage_load = 0; float voltage_load = 0;
// this will only run once // This will only run once
void setup(void) void setup(void)
{ {
Serial.begin(57600); // start serial comm with baud rate of 57600Bd Serial.begin(57600); // start serial comm with baud rate of 57600Bd
// wait for the Arduino serial (on your PC) to connect // Wait for the Arduino serial (on your PC) to connect
// please, open the Arduino serial console (right top corner) // please, open the Arduino serial console (right top corner)
// note that the port may change after uploading the sketch // note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC! // COMMENT OUT FOR USAGE WITHOUT A PC!
...@@ -46,26 +45,25 @@ void setup(void) ...@@ -46,26 +45,25 @@ void setup(void)
Serial.println("openCanSat INA219 test started"); Serial.println("openCanSat INA219 test started");
// begin communication with the INA219 // Begin communication with the INA219
ina219.begin(); ina219.begin();
} }
// code in this function will run repeatedly // Code in this function will run repeatedly
void loop(void) void loop(void)
{ {
// read values from INA219 into the variables // Read values from INA219 into the variables
voltage_shunt = ina219.getShuntVoltage_mV(); voltage_shunt = ina219.getShuntVoltage_mV();
voltage_bus = ina219.getBusVoltage_V(); voltage_bus = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA(); current_mA = ina219.getCurrent_mA();
voltage_load = voltage_bus + (voltage_shunt / 1000); voltage_load = voltage_bus + (voltage_shunt / 1000);
// print the measured variables to serial // Print the measured variables to serial
Serial.println("Shunt Voltage: " + (String) voltage_shunt + " mV"); Serial.println("Shunt Voltage: " + (String) voltage_shunt + " mV");
Serial.println("Bus Voltage: " + (String) voltage_bus + " V"); Serial.println("Bus Voltage: " + (String) voltage_bus + " V");
Serial.println("Current: " + (String) current_mA + " mA"); Serial.println("Current: " + (String) current_mA + " mA");
Serial.println("Load Voltage: " + (String) voltage_load + " V"); Serial.println("Load Voltage: " + (String) voltage_load + " V");
Serial.println(); Serial.println();
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
} }
...@@ -15,21 +15,21 @@ ...@@ -15,21 +15,21 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include <Arduino.h> #include <Arduino.h>
#define Serial SerialUSB // change default serial to SAMD USB serial
// set LED pins #define Serial SerialUSB // Change default serial to SAMD USB serial
// Set LED pins
#define D13_LED 42 #define D13_LED 42
#define M_LED 36 #define M_LED 36
int ms_delay = 2000; // Number of milliseconds between each two LED changes int ms_delay = 2000; // Number of milliseconds between each two LED changes
void setup() void setup()
{ {
Serial.begin(57600); // start serial comm with baud rate of 57600Bd Serial.begin(57600); // Start serial comm with baud rate of 57600Bd
// wait for the Arduino serial (on your PC) to connect // Wait for the Arduino serial (on your PC) to connect
// please, open the Arduino serial console (right top corner) // please, open the Arduino serial console (right top corner)
// note that the port may change after uploading the sketch // note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC! // COMMENT OUT FOR USAGE WITHOUT A PC!
...@@ -37,43 +37,42 @@ void setup() ...@@ -37,43 +37,42 @@ void setup()
Serial.println("openCanSat kit LED test started"); Serial.println("openCanSat kit LED test started");
pinMode(D13_LED, OUTPUT); // configure D13 pin as output pinMode(D13_LED, OUTPUT); // Configure D13 pin as output
} }
void loop() void loop()
{ {
pinMode(M_LED, OUTPUT); // configure MLED as output (it is not, after every loop) pinMode(M_LED, OUTPUT); // Configure MLED as output (it is not, after every loop)
// print the LEDs' status to serial // Print the LEDs' status to serial
Serial.println("D13: ON"); Serial.println("D13: ON");
Serial.println("MLED: ON, RED"); Serial.println("MLED: ON, RED");
Serial.println(); Serial.println();
// turn D13 and MLED-red on // Turn D13 and MLED-red on
digitalWrite(D13_LED, HIGH); digitalWrite(D13_LED, HIGH);
digitalWrite(M_LED, HIGH); digitalWrite(M_LED, HIGH);
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
// print the LEDs' status to serial // Print the LEDs' status to serial
Serial.println("D13: OFF"); Serial.println("D13: OFF");
Serial.println("MLED: ON, BLUE"); Serial.println("MLED: ON, BLUE");
Serial.println(); Serial.println();
// turn D13 off and MLED-blue on // Turn D13 off and MLED-blue on
digitalWrite(D13_LED, LOW); digitalWrite(D13_LED, LOW);
digitalWrite(M_LED, LOW); digitalWrite(M_LED, LOW);
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
// print the LEDs' status to serial // Print the LEDs' status to serial
Serial.println("D13: OFF"); Serial.println("D13: OFF");
Serial.println("MLED: OFF"); Serial.println("MLED: OFF");
Serial.println(); Serial.println();
// D13 is already off // D13 is already off
pinMode(M_LED, INPUT); // configure MLED as input to turn off voltage supply on the pin pinMode(M_LED, INPUT); // Configure MLED as input to turn off voltage supply on the pin
delay(ms_delay); // wait a while (defined at the beginning) delay(ms_delay); // Wait a while (defined at the beginning)
} }
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include <RFM69.h> // include RFM69 library #include <RFM69.h> // include RFM69 library
#define Serial SerialUSB // change default serial to SAMD USB serial #define Serial SerialUSB // change default serial to SAMD USB serial
...@@ -66,10 +65,13 @@ void setup() ...@@ -66,10 +65,13 @@ void setup()
// code in this function will run repeatedly // code in this function will run repeatedly
void loop() void loop()
{ {
if (radio.receiveDone()) // Got one! // When receive from radio is done
if (radio.receiveDone()) // Got one message
{ {
// Print node number
Serial.println("Received from node " + static_cast<String>(radio.SENDERID)); Serial.println("Received from node " + static_cast<String>(radio.SENDERID));
// transfer data into structure
data = *(message*)radio.DATA; data = *(message*)radio.DATA;
Serial.println("Id of received message: " + static_cast<String>(data.messageId)); Serial.println("Id of received message: " + static_cast<String>(data.messageId));
......
...@@ -15,19 +15,18 @@ ...@@ -15,19 +15,18 @@
Please maintain this license information along with authorship Please maintain this license information along with authorship
and copyright notices in any redistribution of this code and copyright notices in any redistribution of this code
*/ */
#include <RFM69.h> // Include RFM69 library
#include <RFM69.h> // include RFM69 library #define Serial SerialUSB // Change default serial to SAMD USB serial
#define Serial SerialUSB // change default serial to SAMD USB serial
// RFM69 // RFM69
#define NETWORKID 0 // Must be the same for all nodes (0 to 255) #define NETWORKID 0 // Must be the same for all nodes (0 to 255)
#define MYNODEID 1 // My node ID (0 to 255) #define MYNODEID 1 // My node ID (0 to 255)
#define TONODEID 2 // Destination node ID (0 to 254, 255 = broadcast) #define TONODEID 2 // Destination node ID (0 to 254, 255 = broadcast)
#define FREQUENCY RF69_433MHZ #define FREQUENCY RF69_433MHZ
#define CHIP_SELECT_PIN 43 //radio chip select #define CHIP_SELECT_PIN 43 // Radio chip select
#define INTERUP_PIN 9 //radio interrupt #define INTERUP_PIN 9 // Radio interrupt
#define MS_DELAY 300 // Number of milliseconds between data sending and LED signalization #define MS_DELAY 300 // Number of milliseconds between data sending and LED signalization
// Local // Local
#define PC_BAUDRATE 56700 #define PC_BAUDRATE 56700
...@@ -42,14 +41,14 @@ typedef struct ...@@ -42,14 +41,14 @@ typedef struct
int messageId; int messageId;
} message; } message;
message data; //create the struct variable message data; // Create the struct object
// this will only run once // This setup loop will only run once
void setup() void setup()
{ {
Serial.begin(PC_BAUDRATE); // start serial comm with baud rate of 57600Bd Serial.begin(PC_BAUDRATE); // Start serial comm with baud rate of 57600Bd
// wait for the Arduino serial (on your PC) to connect // Wait for the Arduino serial (on your PC) to connect
// please, open the Arduino serial console (right top corner) // please, open the Arduino serial console (right top corner)
// note that the port may change after uploading the sketch // note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC! // COMMENT OUT FOR USAGE WITHOUT A PC!
...@@ -66,22 +65,24 @@ void setup() ...@@ -66,22 +65,24 @@ void setup()
Serial.println("RFM69HW initialization failed!"); Serial.println("RFM69HW initialization failed!");
} }
Serial.println(); // print new line on serial to make the output look better :-; Serial.println(); // Print new line on serial to make the output look better :-;
} }
// code in this function will run repeatedly // Code in this function will run repeatedly
void loop() void loop()
{ {