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,6 +30,7 @@
// Local
#define PC_BAUDRATE 56700
#define MS_DELAY 0 // Number of milliseconds between data sending and LED signalization
#define LED_DELAY 100
#define Serial SerialUSB
// RFM69
......@@ -37,6 +38,8 @@
#define MYNODEID 1 // My node ID (0 to 255)
#define TONODEID 2 // Destination node ID (0 to 254, 255 = broadcast)
#define FREQUENCY RF69_433MHZ // Frequency set up
#define CHIP_SELECT_PIN 43 //radio chip select
#define INTERUP_PIN 9 //radio interrupt
// BMP280
#define BMP280_ADDRESS_OPEN_CANSAT 0x76
......@@ -48,21 +51,22 @@
// SD card
#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
// 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
typedef struct
{
int messageId;
String datetime;
double longitude;
double latitude;
int16_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;
......@@ -106,6 +110,7 @@ bool isBmeOk = true;
bool isBmpOk = true;
bool isSdOk = true;
bool isRadioOk = true;
bool isGpsConnected = true;
void setup()
{
......@@ -115,7 +120,7 @@ void setup()
// 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);
// while(!Serial);
Serial.println("openCanSat LITE");
......@@ -144,30 +149,17 @@ void setup()
// begin communication with the INA219
ina219.begin();
// begin communication with gps
gps.begin();
// check of Gps is connected
Wire.beginTransmission(0x42); // 42 is addres of GPS
int error = Wire.endTransmission();
// 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(sd_cs_pin))
if (error != 0)
{
isSdOk = false;
Serial.println("SD card initialization failed!");
return;
isGpsConnected = false;
}
if(isSdOk)
{
// Keep only last measurement
if(SD.exists("data.txt"))
{
Serial.println("data.txt removed");
SD.remove("data.txt");
}
Serial.println("SD card initialized.");
}
// begin communication with gps
gps.begin();
// Uncomment when you want to see debug prints from GPS library
// gps.debugPrintOn(57600);
......@@ -234,7 +226,12 @@ void loop()
Serial.println("Load Voltage: " + static_cast<String>(data.voltage_load) + " V");
// 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.longitude = 0;
data.num_of_satelites = 0;
......@@ -242,14 +239,27 @@ void loop()
// save start time in millisec
uint32_t start = millis();
// END LED BLINK
digitalWrite(D13_led_pin, LOW);
pinMode(M_led_pin, INPUT);
// END LED BLINK
if(isGpsConnected)
{
if (gps.scan(250))
{
data.datetime = gps.getDateTimeString();
data.year = gps.getYear();
data.month = gps.getMonth();
data.day = gps.getDay();
data.hour = gps.getHour();
data.minute = gps.getMinute();
data.sec = gps.getSecond();
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("Datetime: ") + String(data.year) + "/"+ String(data.month) + "/"+ String(data.day) + " " + String(data.hour) + ":"+ String(data.minute) + ":"+ String(data.sec));
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));
......@@ -259,29 +269,6 @@ void loop()
{
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
if (file)
{
file.println("A " + static_cast<String>(data.altitude) +
" I " + static_cast<String>(data.current_mA) +
" Time " + static_cast<String>(data.datetime) +
" H " + static_cast<String>(data.humidity_bme280) +
" Lat " + static_cast<String>(data.latitude) +
" Lon " + static_cast<String>(data.longitude) +
" I " + static_cast<String>(data.messageId) +
" NoS " + static_cast<String>(data.num_of_satelites) +
" P " + static_cast<String>(data.pressure) +
" T " + static_cast<String>(data.temperature) +
" Vb " + static_cast<String>(data.voltage_bus) +
" Vl " + static_cast<String>(data.voltage_load) +
" Vs " + static_cast<String>(data.voltage_shunt));
Serial.println("Writing to file data.txt finished.");
file.close();
}
// RFM69HW
......@@ -303,15 +290,12 @@ void loop()
digitalWrite(D13_led_pin, HIGH);
digitalWrite(M_led_pin, HIGH);
// START LED hart beat
delay(MS_DELAY);
digitalWrite(D13_led_pin, LOW);
pinMode(M_led_pin, INPUT);
// END LED hart beat
if(!isGpsConnected)
{
delay(200);
}
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;
float humidity_bme280;
float voltage_shunt;
float voltage_bus;
float current_mA;
float voltage_load;
int16_t rssi;
} message;
void Update(message income, uint8_t screenNum);
float getTemp();
message getActualData();
float getMinTemp();
private:
bool isInitalize;
OcsGraphics ocsDesign;
message actualData {};
message minData {};
message maxData {};
void checkTemperature(float temp);
void checkPressure(float pressure);
void checkAltitude(float altitude);
void checkHumidity(float humidity);
};
#endif /* _OCSGRAPHICS_HH */
name=OcsGraphics
version=1.0
author=Marketa Jedlickova
maintainer=Jedlickova <jedlickovam@outlook.cz>
sentence=Graphics for openCansat.
paragraph=
category=Graphics.
url=http://www.opencansat.eu
architectures=samd
#include "OcsGraphics.h"
#include "src/Ucglib.h"
#include "Time.h"
OcsGraphics::OcsGraphics(Ucglib_ST7735_18x128x160_HWSPI& ucgIn)
:ucg(ucgIn)
{
}
void OcsGraphics::drawLeftScreen()
{
ucg.setRotate90();
ucg.setColor(17, 30, 108);
// Fraw frame
ucg.drawBox(2, 10, 156, 103);
ucg.drawBox(0, 110, 40, 18);
ucg.drawBox(140, 110, 40, 18);