Commit 0c94ba0b authored by Markéta Jedličková's avatar Markéta Jedličková
Browse files

Examples and libraries for openCanSat added

parent 1f50ba51
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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_BME280.h" // include Adafruit BME280 library
#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)
// 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
float temperature_bme280 = 0;
float pressure_bme280 = 0;
float altitude_bme280 = 0;
float humidity_bme280 = 0;
// this will only run once
void setup()
{
Serial.begin(57600); // start serial comm with baud rate of 57600Bd
// 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!
while(!Serial);
Serial.println("openCanSat BME280 test started");
// 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))
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
return;
}
Serial.println(); // print new line on serial to make the output look better :-;
}
// code in this function will run repeatedly
void loop()
{
// 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
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)
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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
#define BMP280_ADDRESS 0x76 // set BMP's address (according to the circuit)
// create object 'bmp' from the library, which will
// be used to access the library methods by a dot notation
Adafruit_BMP280 bmp;
int ms_delay = 500; // Number of milliseconds between each two measurements
// empty variables for measured values
float temperature_bmp280 = 0;
float pressure_bmp280 = 0;
float altitude_bmp280 = 0;
// this will only run once
void setup()
{
Serial.begin(57600); // start serial comm with baud rate of 57600Bd
// 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!
while(!Serial);
Serial.println("openCanSat BMP280 test started");
// 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))
{
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
return;
}
Serial.println(); // print new line on serial to make the output look better :-;
}
// code in this function will run repeatedly
void loop()
{
// 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
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)
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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 <Wire.h>
#include "../../libraries/Open_Cansat_GPS/src/Open_Cansat_GPS.h"
#define Serial SerialUSB
OpenCansatGPS gps;
// Setting of delay
const uint16_t msDelay = 2000;
void setup()
{
while (!SerialUSB) {}
Serial.begin(57600);
Serial.println("OpenCansat gps test");
gps.begin();
// Uncomment when you want to see debug prints from GPS library
//gps.debugPrintOn(57600);
}
void loop()
{
// save start time in millisec
uint32_t start = millis();
if (gps.scan(600 * 1000))
{
Serial.println(String(" time to find fix: ") + (millis() - start) + String("ms"));
Serial.println(String(" datetime = ") + gps.getDateTimeString());
Serial.println(String(" lat = ") + String(gps.getLat(), 7));
Serial.println(String(" lon = ") + String(gps.getLon(), 7));
Serial.println(String(" num sats = ") + String(gps.getNumberOfSatellites()));
}
else
{
Serial.println("No Fix");
}
Serial.println(String("Delay: ") + msDelay + String("ms"));
delay(msDelay);
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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_INA219.h> // include Adafruit INA219 library
#define Serial SerialUSB // change default serial to SAMD USB serial
// 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
float voltage_shunt = 0;
float voltage_bus = 0;
float current_mA = 0;
float voltage_load = 0;
// 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
// 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!
while(!Serial);
Serial.println("openCanSat INA219 test started");
// begin communication with the INA219
ina219.begin();
}
// code in this function will run repeatedly
void loop(void)
{
// 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
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)
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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 <Arduino.h>
#define Serial SerialUSB // change default serial to SAMD USB serial
// set LED pins
#define D13_LED 42
#define M_LED 36
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
// 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!
while(!Serial);
Serial.println("openCanSat kit LED test started");
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)
// print the LEDs' status to serial
Serial.println("D13: ON");
Serial.println("MLED: ON, RED");
Serial.println();
// turn D13 and MLED-red on
digitalWrite(D13_LED, HIGH);
digitalWrite(M_LED, HIGH);
delay(ms_delay); // wait a while (defined at the beginning)
// print the LEDs' status to serial
Serial.println("D13: OFF");
Serial.println("MLED: ON, BLUE");
Serial.println();
// 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)
// 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
delay(ms_delay); // wait a while (defined at the beginning)
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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 <RFM69.h> // include RFM69 library
#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 2 // My node ID (0 to 255)
#define FREQUENCY RF69_433MHZ
#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
#define PC_BAUDRATE 56700
// Variables
int idCounter = 1;
RFM69 radio(CHIP_SELECT_PIN, INTERUP_PIN, true);
typedef struct
{
int messageId;
} message;
message data; //create the struct variable
// this will only run once
void setup()
{
Serial.begin(PC_BAUDRATE); // start serial comm with baud rate of 57600Bd
// 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!
while(!Serial);
Serial.println("openCanSat RFM69 receive test started");
// RFM69 initialize
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(true); // Always use this for RFM69HW
Serial.println(); // print new line on serial to make the output look better :-;
}
// code in this function will run repeatedly
void loop()
{
if (radio.receiveDone()) // Got one!
{
Serial.println("Received from node " + static_cast<String>(radio.SENDERID));
data = *(message*)radio.DATA;
Serial.println("Id of received message: " + static_cast<String>(data.messageId));
}
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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 <RFM69.h> // include RFM69 library
#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 MS_DELAY 300 // Number of milliseconds between data sending and LED signalization
// Local
#define PC_BAUDRATE 56700
// Variables
int idCounter = 1;
RFM69 radio(CHIP_SELECT_PIN, INTERUP_PIN, true);
typedef struct
{
int messageId;
} message;
message data; //create the struct variable
// this will only run once
void setup()
{
Serial.begin(PC_BAUDRATE); // start serial comm with baud rate of 57600Bd
// 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!
while(!Serial);
Serial.println("openCanSat RFM69 receive test started");
// RFM69 initialize
radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
radio.setHighPower(true); // Always use this for RFM69HW
Serial.println(); // print new line on serial to make the output look better :-;
}
// code in this function will run repeatedly
void loop()
{
// read values from BME280 into the variables
data.messageId = idCounter;
// print the id of message to serial
Serial.println("Id of sended message: " + static_cast<String>(idCounter));
Serial.println();
radio.send(TONODEID, (const void*)&data, sizeof(data));
idCounter++;
delay(MS_DELAY); // wait a while (defined at the beginning)
}
/*
This code was designed specifically for usage with the openCanSat kit (https://opencansat.eu)
This program is free software; you can redistribute it
and/or modify it under the terms of the GNU General
Public License as published by the Free Software
Foundation; either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General
Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
Licence can be viewed at
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 <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)
File file; // SD library variable
// this will only run once
void setup()
{
Serial.begin(57600); // start serial comm with baud rate of 57600Bd
// 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!
while(!Serial);
Serial.println("openCanSat SD card test started");
// 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)) {
Serial.println("SD card initialization failed!");
return;
}
Serial.println("SD card initialized");
file = SD.open("test.txt", FILE_WRITE); // open test.txt for write
// write to the file and print info to serial
// print an error to the serial in case it does not succeed
if (file)
{
Serial.println("Writing to test.txt");
file.println("openCanSat SD card test");
file.close();
Serial.println("Writing to file finished.");
}
else
{
Serial.println("Error opening test.txt for writing");
}
// read the test.txt and print it to serial
// print an error to the serial in case it does not succeed
file = SD.open("test.txt");
if (file)
{
Serial.println("test.txt:");