Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Michal Rybka
openCanSat-2.0-library
Commits
77cf2c2b
Commit
77cf2c2b
authored
Sep 17, 2018
by
Markéta Jedličková
Browse files
Examples clean up
parent
414b3152
Changes
8
Hide whitespace changes
Inline
Side-by-side
examples/3-Each-module-examples/BME280_test/BME280_test.ino
View file @
77cf2c2b
...
...
@@ -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
int
ms_delay
=
500
;
// Number of milliseconds between each two measurements
//
e
pty variables for measured values
//
Em
pty variables for measured values
float
temperature_bme280
=
0
;
float
pressure_bme280
=
0
;
float
altitude_bme280
=
0
;
float
humidity_bme280
=
0
;
//
t
his will only run once
//
T
his will only run once
void
setup
()
{
Serial
.
begin
(
57600
);
//
s
tart serial comm with baud rate of 57600Bd
Serial
.
begin
(
57600
);
//
S
tart serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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"
);
//
b
egin communication with the BME280 on the previously specified address
//
B
egin 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
();
//
p
rint new line on serial to make the output look better :-;
Serial
.
println
();
//
P
rint new line on serial to make the output look better :-;
}
//
c
ode in this function will run repeatedly
//
C
ode in this function will run repeatedly
void
loop
()
{
//
r
ead values from BME280 into the variables
//
R
ead values from BME280 into the variables
temperature_bme280
=
bme
.
readTemperature
();
pressure_bme280
=
bme
.
readPressure
()
/
100.0
F
;
altitude_bme280
=
bme
.
readAltitude
(
SEALEVELPRESSURE_HPA
);
humidity_bme280
=
bme
.
readHumidity
();
//
p
rint the measured variables to serial
//
P
rint 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
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
}
examples/3-Each-module-examples/BMP280_test/BMP280_test.ino
View file @
77cf2c2b
...
...
@@ -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
;
//
t
his will only run once
//
T
his will only run once
void
setup
()
{
Serial
.
begin
(
57600
);
//
s
tart serial comm with baud rate of 57600Bd
Serial
.
begin
(
57600
);
//
S
tart serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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"
);
//
b
egin communication with the BMP280 on the previously specified address
//
B
egin 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
();
//
p
rint new line on serial to make the output look better
:-;
Serial
.
println
();
//
P
rint new line on serial to make the output look better
}
//
c
ode in this function will run repeatedly
//
C
ode in this function will run repeatedly
void
loop
()
{
//
r
ead values from BME280 into the variables
//
R
ead values from BME280 into the variables
temperature_bmp280
=
bmp
.
readTemperature
();
pressure_bmp280
=
bmp
.
readPressure
();
altitude_bmp280
=
bmp
.
readAltitude
(
1013.25
);
//
p
rint the measured variables to serial
//
P
rint 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
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
}
examples/3-Each-module-examples/GPS_i2c_test/GPS_i2c_test.ino
View file @
77cf2c2b
...
...
@@ -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
()
{
//
s
ave start time in millisec
//
S
ave 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
);
}
examples/3-Each-module-examples/INA219_test/INA219_test.ino
View file @
77cf2c2b
...
...
@@ -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
//
c
hange default serial to SAMD USB serial
#define Serial SerialUSB
//
C
hange default serial to SAMD USB serial
//
c
reate object 'ina219' from the library with address 0x40
//
C
reate 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
//
e
mpty variables for measured values
//
E
mpty variables for measured values
float
voltage_shunt
=
0
;
float
voltage_bus
=
0
;
float
current_mA
=
0
;
float
voltage_load
=
0
;
//
t
his will only run once
//
T
his will only run once
void
setup
(
void
)
{
Serial
.
begin
(
57600
);
// start serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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"
);
//
b
egin communication with the INA219
//
B
egin communication with the INA219
ina219
.
begin
();
}
//
c
ode in this function will run repeatedly
//
C
ode in this function will run repeatedly
void
loop
(
void
)
{
//
r
ead values from INA219 into the variables
//
R
ead 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
);
//
p
rint the measured variables to serial
//
P
rint 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
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
}
examples/3-Each-module-examples/LED_test/LED_test.ino
View file @
77cf2c2b
...
...
@@ -15,21 +15,21 @@
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
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
()
{
Serial
.
begin
(
57600
);
//
s
tart serial comm with baud rate of 57600Bd
Serial
.
begin
(
57600
);
//
S
tart serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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
);
//
c
onfigure MLED as output (it is not, after every loop)
pinMode
(
M_LED
,
OUTPUT
);
//
C
onfigure MLED as output (it is not, after every loop)
//
p
rint the LEDs' status to serial
//
P
rint the LEDs' status to serial
Serial
.
println
(
"D13: ON"
);
Serial
.
println
(
"MLED: ON, RED"
);
Serial
.
println
();
//
t
urn D13 and MLED-red on
//
T
urn D13 and MLED-red on
digitalWrite
(
D13_LED
,
HIGH
);
digitalWrite
(
M_LED
,
HIGH
);
delay
(
ms_delay
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
//
p
rint the LEDs' status to serial
//
P
rint the LEDs' status to serial
Serial
.
println
(
"D13: OFF"
);
Serial
.
println
(
"MLED: ON, BLUE"
);
Serial
.
println
();
//
t
urn D13 off and MLED-blue on
//
T
urn D13 off and MLED-blue on
digitalWrite
(
D13_LED
,
LOW
);
digitalWrite
(
M_LED
,
LOW
);
delay
(
ms_delay
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
//
p
rint the LEDs' status to serial
//
P
rint the LEDs' status to serial
Serial
.
println
(
"D13: OFF"
);
Serial
.
println
(
"MLED: OFF"
);
Serial
.
println
();
// D13 is already off
pinMode
(
M_LED
,
INPUT
);
//
c
onfigure MLED as input to turn off voltage supply on the pin
pinMode
(
M_LED
,
INPUT
);
//
C
onfigure MLED as input to turn off voltage supply on the pin
delay
(
ms_delay
);
//
w
ait a while (defined at the beginning)
delay
(
ms_delay
);
//
W
ait a while (defined at the beginning)
}
examples/3-Each-module-examples/RFM69_receive_test/RFM69_receive_test.ino
View file @
77cf2c2b
...
...
@@ -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
));
...
...
examples/3-Each-module-examples/RFM69_send_test/RFM69_send_test.ino
View file @
77cf2c2b
...
...
@@ -15,19 +15,18 @@
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 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
//r
adio chip select
#define INTERUP_PIN 9
//r
adio interrupt
#define MS_DELAY 300 // Number of milliseconds between data sending and LED signalization
#define CHIP_SELECT_PIN 43
// R
adio chip select
#define INTERUP_PIN 9
// R
adio interrupt
#define MS_DELAY 300
// Number of milliseconds between data sending and LED signalization
// Local
#define PC_BAUDRATE 56700
...
...
@@ -42,14 +41,14 @@ typedef struct
int
messageId
;
}
message
;
message
data
;
//
c
reate the struct
variable
message
data
;
//
C
reate the struct
object
//
t
his will only run once
//
T
his
setup loop
will only run once
void
setup
()
{
Serial
.
begin
(
PC_BAUDRATE
);
//
s
tart serial comm with baud rate of 57600Bd
Serial
.
begin
(
PC_BAUDRATE
);
//
S
tart serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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
();
//
p
rint new line on serial to make the output look better :-;
Serial
.
println
();
//
P
rint new line on serial to make the output look better :-;
}
//
c
ode in this function will run repeatedly
//
C
ode in this function will run repeatedly
void
loop
()
{
//
r
ead values from BME280 into the variables
//
R
ead values from BME280 into the variables
data
.
messageId
=
idCounter
;
//
p
rint the id of message to serial
//
P
rint 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
);
//
w
ait a while (defined at the beginning)
delay
(
MS_DELAY
);
//
W
ait a while (defined at the beginning)
}
examples/3-Each-module-examples/SD_card_test/SD_card_test.ino
View file @
77cf2c2b
...
...
@@ -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)
File
file
;
// SD library variable
#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
);
//
s
tart serial comm with baud rate of 57600Bd
Serial
.
begin
(
57600
);
//
S
tart serial comm with baud rate of 57600Bd
//
w
ait for the Arduino serial (on your PC) to connect
//
W
ait 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"
);
//
b
egin communication with the SD card using the previously specified pin
//
B
egin 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
);
//
o
pen test.txt for write
file
=
SD
.
open
(
"data.txt"
,
FILE_WRITE
);
//
O
pen test.txt for write
//
w
rite to the file and print info to serial
//
R
rite 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"
);
}
//
r
ead the test.txt and print it to serial
//
R
ead 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()
}
}
//
n
o need for this function
//
N
o need for this function
void
loop
()
{
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment