Commit 168d5616 authored by Error414's avatar Error414

init

parents
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
platformio.ini
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choice one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#
#
# Template #1: General project. Test it using existing `platformio.ini`.
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
#
# script:
# - platformio run
#
# Template #2: The project is intended to by used as a library with examples
#
# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html
Parts List:
* Arduino Nano
* Ublox NEO-6
* DC-DC 3V3 to 5V
* OLED 64x32 I2C
Thanks to https://github.com/ShikOfTheRa/scarab-osd
/*
* This file is part of GPS_TACHOMETER.
*
* GPS_TACHOMETER 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.
*
* GPS_TACHOMETER is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPS_TACHOMETER. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _gps_h
#define _gps_h
#include "Arduino.h"
enum PROTOCOL_BYTES {
PREAMBLE1 = 0xb5,
PREAMBLE2 = 0x62,
MSG_SOL = 0x6,
MSG_VELNED = 0x12
};
struct ubxSolution {
uint32_t time;
int32_t time_nsec;
int16_t week;
uint8_t fix_type;
uint8_t fix_status;
int32_t ecef_x;
int32_t ecef_y;
int32_t ecef_z;
uint32_t position_accuracy_3d;
int32_t ecef_x_velocity;
int32_t ecef_y_velocity;
int32_t ecef_z_velocity;
uint32_t speed_accuracy;
uint16_t position_DOP;
uint8_t res;
uint8_t satellites;
uint32_t res2;
};
struct ubxVelned {
uint32_t time; // GPS msToW
int32_t ned_north;
int32_t ned_east;
int32_t ned_down;
uint32_t speed_3d;
uint32_t speed_2d;
int32_t heading_2d;
uint32_t speed_accuracy;
uint32_t heading_accuracy;
};
enum ubx_nav_status_bits {
NAV_STATUS_FIX_VALID = 1
};
struct resultGps {
uint8_t GPS_fix_type;
uint8_t GPS_numSat;
uint32_t GPS_speed;
bool newData = false;
};
const uint8_t UBLOX_INIT[] PROGMEM = {
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x05, 0x00, 0xFF, 0x19, //disable all default NMEA messages
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x03, 0x00, 0xFD, 0x15,
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x01, 0x00, 0xFB, 0x11,
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x00, 0x00, 0xFA, 0x0F,
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x02, 0x00, 0xFC, 0x13,
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0xF0, 0x04, 0x00, 0xFE, 0x17,
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x02, 0x01, 0x0E, 0x47, //set POSLLH MSG rate
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x03, 0x01, 0x0F, 0x49, //set STATUS MSG rate
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x06, 0x01, 0x12, 0x4F, //set SOL MSG rate
0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x01, 0x12, 0x01, 0x1E, 0x67, //set VELNED MSG rate
0xB5, 0x62, 0x06, 0x16, 0x08, 0x00, 0x03, 0x07, 0x03, 0x00, 0x51, 0x08, 0x00, 0x00, 0x8A, 0x41, //set WAAS to EGNOS
0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A, //(5Hz)
};
class GPS{
public:
GPS(SoftwareSerial *connection);
void init();
void processGPS();
bool newDataAvailable();
uint16_t getSpeed();
uint8_t getSatsNum();
uint8_t getFixType();
resultGps* getData();
private:
void SerialGpsPrint(const char* str);
bool UBLOXParseGps();
SoftwareSerial *_connection;
uint8_t _ckA;
uint8_t _ckB;
uint8_t _step;
uint8_t _msgID;
uint16_t _payloadLength;
uint16_t _payloadCounter;
uint8_t _class;
resultGps result;
union {
ubxSolution solution;
ubxVelned velned;
uint8_t bytes[];
} _buffer;
};
GPS::GPS(SoftwareSerial *connection){
_connection = connection;
}
void GPS::SerialGpsPrint(const char* str) {
char b;
while (str && (b = pgm_read_byte(str++))) {
_connection->write(b);
delay(5);
}
}
void GPS::init(){
const static uint32_t init_speed[5] = {9600, 19200, 38400, 57600, 115200};
for (uint8_t i = 0; i < 5; i++) {
delay(100);
_connection->begin(init_speed[i]);
_connection->flush();
SerialGpsPrint(PSTR("$PUBX,41,1,0003,0001,19200,0*23\r\n"));
}
_connection->flush();
delay(100);
_connection->begin(19200);
for(unsigned int i = 0; i < sizeof(UBLOX_INIT); i++) {
_connection->write( pgm_read_byte(UBLOX_INIT+i) );
delay(5);
}
}
void GPS::processGPS(){
while ( _connection->available() ) {
byte data = _connection->read();
switch (_step) {
case 1:
if (PREAMBLE2 == data) {
_step++;
break;
}
_step = 0;
case 0:
if (PREAMBLE1 == data){
_step++;
}
break;
case 2:
_step++;
_class = data;
_ckB = _ckA = data; // reset the checksum accumulators
break;
case 3:
_step++;
_ckB += (_ckA += data); // checksum byte
_msgID = data;
break;
case 4:
_step++;
_ckB += (_ckA += data); // checksum byte
_payloadLength = data; // payload length low byte
break;
case 5:
_step++;
_ckB += (_ckA += data); // checksum byte
_payloadLength += (uint16_t)(data << 8);
if (_payloadLength > 100 || _payloadLength < 1) {
_payloadLength = 0;
_step = 0;
}
_payloadCounter = 0; // prepare to receive payload
break;
case 6:
_ckB += (_ckA += data); // checksum byte
if (_payloadCounter < sizeof(_buffer)) {
_buffer.bytes[_payloadCounter] = data;
}
if (++_payloadCounter == _payloadLength)
_step++;
break;
case 7:
_step++;
if (_ckA != data){
_step = 0; // bad checksum
}
break;
case 8:
_step = 0;
if (_ckB != data) {
break; // bad checksum
}
if (UBLOXParseGps()) {
return true;
}
}
}
return false;
}
bool GPS::UBLOXParseGps() {
switch (_msgID) {
case MSG_SOL:
if ((_buffer.solution.fix_status & NAV_STATUS_FIX_VALID) && (_buffer.solution.fix_type == FIX_3D || _buffer.solution.fix_type == FIX_2D)){
result.GPS_fix_type = _buffer.solution.fix_type;
}
result.GPS_numSat = _buffer.solution.satellites;
result.newData = true;
return true;
case MSG_VELNED:
result.GPS_speed = (uint8_t)(round((_buffer.velned.speed_2d / 10) * 0.36)); // km/h
result.newData = true;
return true;
default:
break;
}
return false;
}
bool GPS::newDataAvailable(){
return result.newData;
}
resultGps* GPS::getData(){
result.newData = false;
return &result;
}
#endif
/*
* This file is part of GPS_TACHOMETER.
*
* GPS_TACHOMETER 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.
*
* GPS_TACHOMETER is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPS_TACHOMETER. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _screen_h
#define _screen_h
#include "Arduino.h"
enum FIX_TYPE {
FIX_NONE = 0,
FIX_DEAD_RECKONING = 1,
FIX_2D = 2,
FIX_3D = 3,
FIX_GPS_DEAD_RECKONING = 4,
FIX_TIME = 5
};
class Screen{
public:
Screen(Adafruit_SSD1306 *screenDriver);
void init();
void showMainScreen();
void showSat(uint8_t satsNum);
void showFixType(uint8_t fixType);
void showMaxSpeed(uint8_t maxSpeed);
void showPrewMaxSpeed(uint8_t maxSpeed);
private:
Adafruit_SSD1306 *_screenDriver;
};
Screen::Screen(Adafruit_SSD1306 *screenDriver){
_screenDriver = screenDriver;
}
void Screen::init(){
_screenDriver->begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void Screen::showMainScreen(){
_screenDriver->clearDisplay();
_screenDriver->setTextSize(1);
_screenDriver->setTextColor(WHITE, 0);
_screenDriver->setCursor(0,0);
_screenDriver->print("S:");
_screenDriver->setCursor(35,0);
_screenDriver->print("F:");
_screenDriver->setCursor(0,10);
_screenDriver->print("MS:");
_screenDriver->setCursor(0,20);
_screenDriver->print("PR:");
_screenDriver->display();
}
void Screen::showSat(uint8_t satsNum){
static uint8_t progress = 0;
_screenDriver->setCursor(11,0);
_screenDriver->setTextSize(1);
_screenDriver->print(satsNum);
switch(progress){ //"| / - \ | / - \"
case 0:
case 4:
_screenDriver->print("|");
progress++;
break;
case 1:
case 5:
_screenDriver->print("/");
progress++;
break;
case 2:
case 6:
_screenDriver->print("-");
progress++;
break;
case 3:
_screenDriver->print("\\");
progress++;
break;
case 7:
_screenDriver->print("\\");
progress = 0;
break;
}
_screenDriver->display();
}
void Screen::showFixType(uint8_t fixType){
_screenDriver->setCursor(46,0);
_screenDriver->setTextSize(1);
switch(fixType){
case FIX_2D:
_screenDriver->print("2D");
break;
case FIX_3D:
_screenDriver->print("3D");
break;
case FIX_NONE:
default:
_screenDriver->print("No");
}
_screenDriver->display();
}
void Screen::showMaxSpeed(uint8_t maxSpeed){
_screenDriver->setCursor(20,10);
_screenDriver->setTextSize(1);
_screenDriver->print(maxSpeed);
_screenDriver->display();
}
void Screen::showPrewMaxSpeed(uint8_t maxSpeed){
_screenDriver->setCursor(20,20);
_screenDriver->setTextSize(1);
_screenDriver->print(maxSpeed);
_screenDriver->display();
}
#endif
/*
* This file is part of GPS_TACHOMETER.
*
* GPS_TACHOMETER 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.
*
* GPS_TACHOMETER is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPS_TACHOMETER. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _speed_h
#define _speed_h
#include "Arduino.h"
class Speed{
public:
Speed();
void setSpeed(uint8_t speed);
uint8_t getMaxSpeed();
uint8_t getMaxPrewSpeed();
private:
uint8_t maxSpeed = 0;
uint8_t maxPrewSpeed = 0;
};
Speed::Speed(){
maxPrewSpeed = EEPROM.read(EEPROM_PREW_SPEED_ADDRESS);
}
void Speed::setSpeed(uint8_t speed){
static uint8_t ignoring = 0;
if(ignoring < IGNORE_FIRST_SPEED){
ignoring++;
return;
}
if(speed > maxSpeed){
maxSpeed = speed;
maxPrewSpeed = maxSpeed;
EEPROM.write(EEPROM_PREW_SPEED_ADDRESS, maxPrewSpeed);
}
}
uint8_t Speed::getMaxSpeed(){
return maxSpeed;
}
uint8_t Speed::getMaxPrewSpeed(){
return maxPrewSpeed;
}
#endif
/*
* This file is part of GPS_TACHOMETER.
*
* GPS_TACHOMETER 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.
*
* GPS_TACHOMETER is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPS_TACHOMETER. If not, see <http://www.gnu.org/licenses/>.
*/
#include <settings.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Screen.h>
#include <GPS.h>
#include <Speed.h>
SoftwareSerial GPSConnection(GPS_RX_PIN, GPS_TX_PIN); // RX, TX
Adafruit_SSD1306 screenDriver(OLED_RESET);
Screen screen(&screenDriver);
GPS gps(&GPSConnection);
Speed speed;
void setup(){
screen.init();
screen.showMainScreen();
screen.showPrewMaxSpeed(speed.getMaxPrewSpeed());
gps.init();
}
void loop(){
gps.processGPS();
if(gps.newDataAvailable()){
resultGps *data = gps.getData();
screen.showFixType(data->GPS_fix_type);
screen.showSat(data->GPS_numSat);
speed.setSpeed(data->GPS_speed);
screen.showMaxSpeed(speed.getMaxSpeed());
}
}
/*
* This file is part of GPS_TACHOMETER.
*
* GPS_TACHOMETER 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.
*
* GPS_TACHOMETER is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPS_TACHOMETER. If not, see <http://www.gnu.org/licenses/>.
*/
#define OLED_RESET 4
#define GPS_RX_PIN 12
#define GPS_TX_PIN 11
#define IGNORE_FIRST_SPEED 30
#define EEPROM_PREW_SPEED_ADDRESS 0
Markdown is supported
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