Commit 1dc1933c authored by Markéta Jedličková's avatar Markéta Jedličková
Browse files

Libraries for openCansat graphix added

parent 5e2ac3ee
#include <OcsStorage.h>
#include <RFM69.h>
#include <Ucglib.h>
#ifndef UCG_INTERRUPT_SAFE
#define UCG_INTERRUPT_SAFE
#endif
uint8_t screenNum = 1;
#define Serial SerialUSB
// LOCAL
#define PC_BAUDRATE 56700
// BUTTONS
#define BUTTON_1 5
#define BUTTON_2 4
#define BUTTON_3 3
// 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
#define interupt_pin 9
bool isRadioOk = true;
RFM69 radio(chip_select_pin, interupt_pin, true);
// RFM69
Ucglib_ST7735_18x128x160_HWSPI ucg(6, 7, -1);
OcsGraphics ocsDesign(ucg);
OcsStorage ocsData(ocsDesign);
OcsStorage::message income;
void setup()
{
Serial.begin(PC_BAUDRATE);
while(!Serial);
Serial.println("PpenCanSat base station test started");
// Space behind font is transparent
ucg.begin(UCG_FONT_MODE_TRANSPARENT);
// Clear the screen and reset the clip range to maximum
ucg.clearScreen();
ocsDesign.drawBackground();
ocsDesign.drawHomescreen();
// Buttons
pinMode(BUTTON_1, INPUT);
pinMode(BUTTON_2, INPUT);
pinMode(BUTTON_3, INPUT);
// RFM69
Serial.print("OpenCansat ");
Serial.print(MYNODEID,DEC);
Serial.println(" is ready");
if(!radio.initialize(FREQUENCY, MYNODEID, NETWORKID))
{
isRadioOk = false;
Serial.println("RFM69HW initialization failed!");
}
else
{
radio.setHighPower(true); // Always use this for RFM69HW
}
//// RFM69
}
void loop()
{
int button1 = digitalRead(BUTTON_1);
int button2 = digitalRead(BUTTON_2);
int button3 = digitalRead(BUTTON_3);
if(button1 == LOW and screenNum == 1)
{
screenNum = 0;
ocsDesign.drawLeftScreen();
delay(300);
Serial.println("Button 1 ");
}
if(button2 == LOW and screenNum != 1)
{
screenNum = 1;
ocsDesign.drawHomescreen();
delay(300);
Serial.println("Button 2 ");
}
if(button3 == LOW and screenNum == 1)
{
screenNum = 2;
ocsDesign.drawRightScreen();
delay(300);
Serial.println("Button 3 ");
}
if (radio.receiveDone()) // Got one!
{
Serial.println("Message received: " + String(income.messageId));
income = *(OcsStorage::message*)radio.DATA;
ocsData.Update(income, screenNum);
delay(300);
}
}
...@@ -30,13 +30,16 @@ ...@@ -30,13 +30,16 @@
// Local // Local
#define PC_BAUDRATE 56700 #define PC_BAUDRATE 56700
#define MS_DELAY 0 // Number of milliseconds between data sending and LED signalization #define MS_DELAY 0 // Number of milliseconds between data sending and LED signalization
#define LED_DELAY 100
#define Serial SerialUSB #define Serial SerialUSB
// 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 // Frequency set up #define FREQUENCY RF69_433MHZ // Frequency set up
#define CHIP_SELECT_PIN 43 //radio chip select
#define INTERUP_PIN 9 //radio interrupt
// BMP280 // BMP280
#define BMP280_ADDRESS_OPEN_CANSAT 0x76 #define BMP280_ADDRESS_OPEN_CANSAT 0x76
...@@ -48,21 +51,22 @@ ...@@ -48,21 +51,22 @@
// SD card // SD card
#define sd_cs_pin 35 // set SD's chip select pin (according to the circuit) #define sd_cs_pin 35 // set SD's chip select pin (according to the circuit)
// RFM69 modul
#define chip_select_pin 43 //radio chip select
#define interupt_pin 9 //radio interrupt
// create object 'rf69' from the library, which will // create object 'rf69' 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
RFM69 radio(chip_select_pin, interupt_pin, true); RFM69 radio(CHIP_SELECT_PIN, INTERUP_PIN, true);
// define our own struct data type with variables; used to send data // define our own struct data type with variables; used to send data
typedef struct typedef struct
{ {
int messageId; int16_t messageId;
String datetime; uint16_t year;
double longitude; uint8_t month;
double latitude; uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t sec;
float longitude;
float latitude;
uint8_t num_of_satelites; uint8_t num_of_satelites;
float temperature; float temperature;
float pressure; float pressure;
...@@ -106,16 +110,17 @@ bool isBmeOk = true; ...@@ -106,16 +110,17 @@ bool isBmeOk = true;
bool isBmpOk = true; bool isBmpOk = true;
bool isSdOk = true; bool isSdOk = true;
bool isRadioOk = true; bool isRadioOk = true;
bool isGpsConnected = true;
void setup() void setup()
{ {
Serial.begin(PC_BAUDRATE); Serial.begin(PC_BAUDRATE);
// 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!
while(!Serial); // while(!Serial);
Serial.println("openCanSat LITE"); Serial.println("openCanSat LITE");
...@@ -144,30 +149,17 @@ void setup() ...@@ -144,30 +149,17 @@ void setup()
// begin communication with the INA219 // begin communication with the INA219
ina219.begin(); ina219.begin();
// begin communication with gps // check of Gps is connected
gps.begin(); Wire.beginTransmission(0x42); // 42 is addres of GPS
int error = Wire.endTransmission();
// begin communication with the SD card using the previously specified pin if (error != 0)
// print an error to the serial in case the SD card is not found
if (!SD.begin(sd_cs_pin))
{ {
isSdOk = false; isGpsConnected = false;
Serial.println("SD card initialization failed!");
return;
} }
// begin communication with gps
if(isSdOk) gps.begin();
{
// Keep only last measurement
if(SD.exists("data.txt"))
{
Serial.println("data.txt removed");
SD.remove("data.txt");
}
Serial.println("SD card initialized.");
}
// Uncomment when you want to see debug prints from GPS library // Uncomment when you want to see debug prints from GPS library
// gps.debugPrintOn(57600); // gps.debugPrintOn(57600);
...@@ -234,7 +226,12 @@ void loop() ...@@ -234,7 +226,12 @@ void loop()
Serial.println("Load Voltage: " + static_cast<String>(data.voltage_load) + " V"); Serial.println("Load Voltage: " + static_cast<String>(data.voltage_load) + " V");
// Initialize GPS // Initialize GPS
data.datetime = ""; data.year = 0;
data.month = 0;
data.day = 0;
data.hour = 0;
data.minute = 0;
data.sec = 0;
data.latitude = 0; data.latitude = 0;
data.longitude = 0; data.longitude = 0;
data.num_of_satelites = 0; data.num_of_satelites = 0;
...@@ -242,46 +239,36 @@ void loop() ...@@ -242,46 +239,36 @@ void loop()
// save start time in millisec // save start time in millisec
uint32_t start = millis(); uint32_t start = millis();
if (gps.scan(250)) // END LED BLINK
{ digitalWrite(D13_led_pin, LOW);
data.datetime = gps.getDateTimeString();
data.latitude = gps.getLat();
data.longitude = gps.getLon();
data.num_of_satelites = gps.getNumberOfSatellites();
Serial.println(String("Time to find fix: ") + (millis() - start) + String("ms"));
Serial.println(String("Datetime: ") + data.datetime);
Serial.println(String("Lat: ") + String(data.latitude, 7));
Serial.println(String("Lon: ") + String(data.longitude, 7));
Serial.println(String("Num of sats: ") + String(data.num_of_satelites));
Serial.println();
}
else
{
Serial.println("Gps have no satelit to fix.");
}
// write to the file and print info to serial
// print an error to the serial in case it does not succeed
file = SD.open("data.txt", FILE_WRITE); // open test.txt for write pinMode(M_led_pin, INPUT);
// END LED BLINK
if (file) if(isGpsConnected)
{ {
file.println("A " + static_cast<String>(data.altitude) + if (gps.scan(250))
" I " + static_cast<String>(data.current_mA) + {
" Time " + static_cast<String>(data.datetime) + data.year = gps.getYear();
" H " + static_cast<String>(data.humidity_bme280) + data.month = gps.getMonth();
" Lat " + static_cast<String>(data.latitude) + data.day = gps.getDay();
" Lon " + static_cast<String>(data.longitude) + data.hour = gps.getHour();
" I " + static_cast<String>(data.messageId) + data.minute = gps.getMinute();
" NoS " + static_cast<String>(data.num_of_satelites) + data.sec = gps.getSecond();
" P " + static_cast<String>(data.pressure) + data.latitude = gps.getLat();
" T " + static_cast<String>(data.temperature) + data.longitude = gps.getLon();
" Vb " + static_cast<String>(data.voltage_bus) + data.num_of_satelites = gps.getNumberOfSatellites();
" Vl " + static_cast<String>(data.voltage_load) + Serial.println(String("Time to find fix: ") + (millis() - start) + String("ms"));
" Vs " + static_cast<String>(data.voltage_shunt)); Serial.println(String("Datetime: ") + String(data.year) + "/"+ String(data.month) + "/"+ String(data.day) + " " + String(data.hour) + ":"+ String(data.minute) + ":"+ String(data.sec));
Serial.println("Writing to file data.txt finished."); Serial.println(String("Lat: ") + String(data.latitude, 7));
file.close(); Serial.println(String("Lon: ") + String(data.longitude, 7));
Serial.println(String("Num of sats: ") + String(data.num_of_satelites));
Serial.println();
}
else
{
Serial.println("Gps have no satelit to fix.");
}
} }
// RFM69HW // RFM69HW
...@@ -303,15 +290,12 @@ void loop() ...@@ -303,15 +290,12 @@ void loop()
digitalWrite(D13_led_pin, HIGH); digitalWrite(D13_led_pin, HIGH);
digitalWrite(M_led_pin, HIGH); digitalWrite(M_led_pin, HIGH);
// START LED hart beat
delay(MS_DELAY); if(!isGpsConnected)
{
digitalWrite(D13_led_pin, LOW); delay(200);
}
pinMode(M_led_pin, INPUT);
// END LED hart beat
idCounter ++; idCounter ++;
delay(MS_DELAY);
} }
name=OcsDataStorage
version=1.0
author=Marketa Jedlickova
maintainer=Jedlickova <jedlickovam@outlook.cz>
sentence=Data storage for openCansat.
paragraph=
category=Data storage.
url=http://www.opencansat.eu
architectures=samd
#include <OcsStorage.h>
OcsStorage::OcsStorage(OcsGraphics& ocsDesignIn)
: isInitalize(false),
ocsDesign(ocsDesignIn)
{
}
float OcsStorage::getTemp()
{
return this->actualData.temperature;
}
float OcsStorage::getMinTemp()
{
return this->minData.temperature;
}
OcsStorage::message OcsStorage::getActualData()
{
return this->actualData;
}
void OcsStorage::Update(message income, uint8_t screenNum)
{
if(screenNum == 1)
{
if(this->isInitalize == false)
{
ocsDesign.drawMinTemp(income.temperature);
ocsDesign.drawMaxTemp(income.temperature);
ocsDesign.drawMinPress(income.pressure);
ocsDesign.drawMaxPress(income.pressure);
minData.temperature = income.temperature;
maxData.temperature = income.temperature;
minData.pressure = income.pressure;
maxData.pressure = income.pressure;
isInitalize = true;
}
checkTemperature(income.temperature);
checkPressure(income.pressure);
checkAltitude(income.altitude);
checkHumidity(income.humidity_bme280);
ocsDesign.drawMessageId(income.messageId);
}
else if(screenNum == 0)
{
String hour;
String minute;
String sec;
if(income.hour < 10)
{
hour += "0";
}
if(income.minute < 10)
{
minute += "0";
}
if(income.sec < 10)
{
sec += "0";
}
hour += String(income.hour);
minute += String(income.minute);
sec += String(income.sec);
String time = hour + ":" + minute + ":" + sec;
ocsDesign.drawTime(13, 47, time);
ocsDesign.drawDate(income.day, income.month, income.year);
ocsDesign.drawLongitude(income.longitude);
ocsDesign.drawLatitude(income.latitude);
ocsDesign.drawNumOfSat(income.num_of_satelites);
float loadvoltage = income.voltage_bus + (income.voltage_shunt / 1000);
float power = income.current_mA * loadvoltage;
ocsDesign.drawPower(power);
}else if(screenNum == 2)
{
}
}
// ToDo -10 value size is over the box
void OcsStorage::checkTemperature(float temp)
{
if(temp > -40 and temp < 80)
{
if(actualData.temperature != temp)
{
this->actualData.temperature = temp;
ocsDesign.drawTemp(temp);
}
if(temp < this->minData.temperature)
{
this->minData.temperature = temp;
ocsDesign.drawMinTemp(temp);
}
if(temp > this->maxData.temperature)
{
this->maxData.temperature = temp;
ocsDesign.drawMaxTemp(temp);
}
}
else
{
// ToDo error handling
}
}
void OcsStorage::checkPressure(float pressure)
{
if(pressure > 30000 and pressure < 100000)
{
if(actualData.pressure != pressure)
{
this->actualData.pressure = pressure;
ocsDesign.drawPress(pressure);
}
if(pressure < this->minData.pressure)
{
this->minData.pressure = pressure;
ocsDesign.drawMinPress(pressure);
}
if(pressure > this->maxData.pressure)
{
this->maxData.pressure = pressure;
ocsDesign.drawMaxPress(pressure);
}
}
else
{
// ToDo error handling
}
}
void OcsStorage::checkAltitude(float altitude)
{
if(altitude > 0 and altitude < 5000)
{
if(this->actualData.altitude != altitude)
{
this->actualData.altitude = altitude;
ocsDesign.drawAltitude(altitude);
}
}
else
{
// ToDo error handling
}
}
void OcsStorage::checkHumidity(float humidity)
{
if(humidity > 0 and humidity < 100)
{
if(this->actualData.humidity_bme280 != humidity)
{
this->actualData.humidity_bme280 = humidity;
ocsDesign.drawHumidity(humidity);
}
}
else
{
// ToDo error handling
}
}
#ifndef _OCSDATASTORAGE_HH
#define _OCSDATASTORAGE_HH
#include <Arduino.h>
#include "OcsGraphics.h"
class OcsStorage
{
public:
OcsStorage(OcsGraphics& ocsDesignIn);
// define our own struct data type with variables
typedef struct
{
uint16_t messageId;
uint16_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t sec;
float longitude;
float latitude;
uint8_t num_of_satelites;
float temperature;
float pressure;
float altitude;