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 @@
Please maintain this license information along with authorship
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)
#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
// Create object 'bme' from the library, which will
// be used to access the library methods by a dot notation
Adafruit_BME280 bme;
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 pressure_bme280 = 0;
float altitude_bme280 = 0;
float humidity_bme280 = 0;
// this will only run once
// This will only run once
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -48,7 +47,7 @@ void setup()
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
if (!bme.begin(BME280_ADDRESS_OPEN_CANSAT))
{
......@@ -56,24 +55,24 @@ void setup()
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()
{
// read values from BME280 into the variables
// Read values from BME280 into the variables
temperature_bme280 = bme.readTemperature();
pressure_bme280 = bme.readPressure() / 100.0F;
altitude_bme280 = bme.readAltitude(SEALEVELPRESSURE_HPA);
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("Pressure = " + (String) pressure_bme280 + " hPa");
Serial.println("Approx altitude = " + (String) altitude_bme280 + " m");
Serial.println("Humidity = " + (String) humidity_bme280 + " %");
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 @@
http://www.gnu.org/licenses/gpl-3.0.txt
Please maintain this license information along with authorship
and copyright notices in any redistribution of this code
*/
#include <Adafruit_BMP280.h> // include Adafruit BMP280 library
#define Serial SerialUSB // change default serial to SAMD USB serial
......@@ -34,12 +32,12 @@ float temperature_bmp280 = 0;
float pressure_bmp280 = 0;
float altitude_bmp280 = 0;
// this will only run once
// This will only run once
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -47,7 +45,7 @@ void setup()
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
if (!bmp.begin(BMP280_ADDRESS))
{
......@@ -55,22 +53,22 @@ void setup()
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()
{
// read values from BME280 into the variables
// Read values from BME280 into the variables
temperature_bmp280 = bmp.readTemperature();
pressure_bmp280 = bmp.readPressure();
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("Pressure = " + (String) pressure_bmp280 + " Pa");
Serial.println("Approx altitude = " + (String) altitude_bmp280 + " m");
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 @@
Please maintain this license information along with authorship
and copyright notices in any redistribution of this code
*/
#include "Open_Cansat_GPS.h"
#include <Wire.h>
#include "../../libraries/Open_Cansat_GPS/src/Open_Cansat_GPS.h"
#define Serial SerialUSB
OpenCansatGPS gps;
int ms_delay = 250; // Number of milliseconds for scan and between another scan is done
void setup()
{
while (!SerialUSB) {}
......@@ -40,10 +41,11 @@ void setup()
void loop()
{
// save start time in millisec
// Save start time in millisec
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(" datetime = ") + gps.getDateTimeString());
......@@ -53,5 +55,6 @@ void loop()
Serial.println();
}
delay(250);
// Wait before next measurement
delay(ms_delay);
}
......@@ -15,30 +15,29 @@
Please maintain this license information along with authorship
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
// library methods by a dot notation
Adafruit_INA219 ina219(0x40);
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_bus = 0;
float current_mA = 0;
float voltage_load = 0;
// this will only run once
// This will only run once
void setup(void)
{
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -46,26 +45,25 @@ void setup(void)
Serial.println("openCanSat INA219 test started");
// begin communication with the INA219
// Begin communication with the INA219
ina219.begin();
}
// code in this function will run repeatedly
// Code in this function will run repeatedly
void loop(void)
{
// read values from INA219 into the variables
// Read values from INA219 into the variables
voltage_shunt = ina219.getShuntVoltage_mV();
voltage_bus = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
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("Bus Voltage: " + (String) voltage_bus + " V");
Serial.println("Current: " + (String) current_mA + " mA");
Serial.println("Load Voltage: " + (String) voltage_load + " V");
Serial.println();
delay(ms_delay); // wait a while (defined at the beginning)
delay(ms_delay); // Wait a while (defined at the beginning)
}
......@@ -15,11 +15,11 @@
Please maintain this license information along with authorship
and copyright notices in any redistribution of this code
*/
#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 M_LED 36
......@@ -27,9 +27,9 @@ int ms_delay = 2000; // Number of milliseconds between each two LED changes
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -37,43 +37,42 @@ void setup()
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()
{
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("MLED: ON, RED");
Serial.println();
// turn D13 and MLED-red on
// Turn D13 and MLED-red on
digitalWrite(D13_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("MLED: ON, BLUE");
Serial.println();
// turn D13 off and MLED-blue on
// Turn D13 off and MLED-blue on
digitalWrite(D13_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("MLED: OFF");
Serial.println();
// 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 @@
Please maintain this license information along with authorship
and copyright notices in any redistribution of this code
*/
#include <RFM69.h> // include RFM69 library
#define Serial SerialUSB // change default serial to SAMD USB serial
......@@ -66,10 +65,13 @@ void setup()
// code in this function will run repeatedly
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));
// transfer data into structure
data = *(message*)radio.DATA;
Serial.println("Id of received message: " + static_cast<String>(data.messageId));
......
......@@ -15,18 +15,17 @@
Please maintain this license information along with authorship
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
#define NETWORKID 0 // Must be the same for all nodes (0 to 255)
#define MYNODEID 1 // My node ID (0 to 255)
#define TONODEID 2 // Destination node ID (0 to 254, 255 = broadcast)
#define FREQUENCY RF69_433MHZ
#define CHIP_SELECT_PIN 43 //radio chip select
#define INTERUP_PIN 9 //radio interrupt
#define CHIP_SELECT_PIN 43 // Radio chip select
#define INTERUP_PIN 9 // Radio interrupt
#define MS_DELAY 300 // Number of milliseconds between data sending and LED signalization
// Local
......@@ -42,14 +41,14 @@ typedef struct
int messageId;
} 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()
{
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -66,22 +65,24 @@ void setup()
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()
{
// read values from BME280 into the variables
// Read values from BME280 into the variables
data.messageId = idCounter;
// print the id of message to serial
// Print the id of message to serial
Serial.println("Id of sended message: " + static_cast<String>(idCounter));
Serial.println();
// Send data to node (with TONODEID)
radio.send(TONODEID, (const void*)&data, sizeof(data));
// Increase id counter
idCounter++;
delay(MS_DELAY); // wait a while (defined at the beginning)
delay(MS_DELAY); // Wait a while (defined at the beginning)
}
......@@ -15,20 +15,19 @@
Please maintain this license information along with authorship
and copyright notices in any redistribution of this code
*/
#include <SD.h> // Include Arduino SD library
#include <SPI.h> // Include Arduino SPI library
#include <SD.h> // include Arduino SD library
#include <SPI.h> // include Arduino SPI library
#define Serial SerialUSB // change default serial to SAMD USB serial
#define cs_pin 35 // set SD's chip select pin (according to the circuit)
#define Serial SerialUSB // Change default serial to SAMD USB serial
#define cs_pin 35 // Set SD's chip select pin (according to the circuit)
File file; // SD library variable
// this will only run once
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)
// note that the port may change after uploading the sketch
// COMMENT OUT FOR USAGE WITHOUT A PC!
......@@ -36,7 +35,7 @@ void setup()
Serial.println("openCanSat SD card test started");
// begin communication with the SD card using the previously specified pin
// Begin communication with the SD card using the previously specified pin
// print an error to the serial in case the SD card is not found
if (!SD.begin(cs_pin))
{
......@@ -46,9 +45,9 @@ void setup()
Serial.println("SD card initialized");
file = SD.open("data.txt", FILE_WRITE); // open test.txt for write
file = SD.open("data.txt", FILE_WRITE); // Open test.txt for write
// write to the file and print info to serial
// Rrite to the file and print info to serial
// print an error to the serial in case it does not succeed
if (file)
{
......@@ -63,7 +62,7 @@ void setup()
Serial.println("Error opening data.txt for writing");
}
// read the test.txt and print it to serial
// Read the test.txt and print it to serial
// print an error to the serial in case it does not succeed
file = SD.open("data.txt");
if (file)
......@@ -83,7 +82,7 @@ void setup()
}
}
// no need for this function
// No need for this function
void loop()
{
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment