Pages: [1]   Go Down
Author Topic: Conversion for the DUE  (Read 421 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

After i ran out with the SRAM from the Nano, i bought an Arduino DUE.
But there are some issues. I´ve allready replaced the SoftwareSerial, but there are some more problems.
Can anybody help me ?

Code:
#include <TinyGPS++.h>
//#include <SoftwareSerial.h>
#include <Wire.h>
#include <GOFi2cOLED.h>
#define BMP085_ADDRESS 0x77  // I2C address of BMP085

GOFi2cOLED GOFoled;

static const int RXPin = 11, TXPin = 12;  //GPS Anschluss
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;

//SoftwareSerial ss(RXPin, TXPin);


const int  buttonPin = 3;  // Taster Menü
const int  buttonPinu = 2; //Taster Untermenü
const int ledr = 8;       // LED Rot
const int ledg = 7;       // LED Grün


//Taster Menü
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

//Taster Untermenü
int buttonPushCounteru = 0;   // counter for the number of button presses
int buttonStateu = 0;         // current state of the button
int lastButtonStateu = 0;     // previous state of the button


float vmax, v, hmax, h, sat, a, b;
int i;

const unsigned char OSS = 3;  // Oversampling Setting

// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
long b5;
short temperature;
long pressure;
const float p0 = 101325;     // Pressure at sea level (Pa)
float altitude;



void setup()
{
// Serial.begin(115200);
  Serial1.begin(GPSBaud);
   
  GOFoled.init(0x3C);
 
  pinMode(buttonPin, INPUT);   //Taster Menü
  pinMode(buttonPinu, INPUT);  //Taster Untermenü
 
 
  pinMode(ledr, OUTPUT);
  pinMode(ledg, OUTPUT);

  vmax = 0;
  hmax = 0;
  i = 0;
 
 
 // GOFoled.display(); // show splashscreen
 // delay(2000);
 // GOFoled.clearDisplay();
 
 Wire.begin();
  bmp085Calibration();
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  delay (100);
 
 

}

void loop()
{
   
  temperature = bmp085GetTemperature(bmp085ReadUT());
  pressure = bmp085GetPressure(bmp085ReadUP());
  altitude = (float)44330 * (1 - pow(((float) pressure/p0), 0.190295));
 
   
  sat = gps.satellites.value();
 
 
  //****************LED********************
     
      if (sat >7 ){
          digitalWrite(ledg, HIGH);
           digitalWrite(ledr, LOW);
         
          }
         
      if (sat <3 ){
          digitalWrite(ledr, HIGH);
          digitalWrite(ledg, LOW);
          }
               
          if ((sat >=4 )&&(sat<=6)) {
          digitalWrite(ledr, HIGH);
          digitalWrite(ledg, HIGH);
          }
         
  //****************Maxmimalwerte**************************************************     
 
      v=gps.speed.kmph();
        if(v > vmax) vmax=v;
   
      //h=gps.altitude.meters();
      h=altitude;
        if(h > hmax) hmax=h;
       
  // ********************* Button Counter Menüführung ******************************************     
       
buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      buttonPushCounteru = 0;
     
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;   

if (buttonPushCounter == 7) {
  buttonPushCounter = 0;
  }
 
 
 
 
 
 
 
    // ********************* Button Counter Untermenü ******************************************     
       
buttonStateu = digitalRead(buttonPinu);

  // compare the buttonState to its previous state
  if (buttonStateu != lastButtonStateu) {
    // if the state has changed, increment the counter
    if (buttonStateu == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounteru++; 
    }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonStateu = buttonStateu;   

if (buttonPushCounteru == 2) {
  buttonPushCounteru = 0;
  }
       
       
    // ********************* Dispaly ******************************************   
   
    if (buttonPushCounter == 0) {
     
       
    GOFoled.clearDisplay();
    GOFoled.drawLine(75, 0, 75, 128, WHITE);  //Vertikal
    //**********************Tabelle**************************
       GOFoled.drawLine(0, 8, 128, 8, WHITE);    //V
       GOFoled.drawLine(0, 18, 128, 18, WHITE);    //Alt
       GOFoled.drawLine(0, 28, 75, 28, WHITE);    //Sat
       GOFoled.drawLine(0, 38, 75, 38, WHITE);    //Vmax
        GOFoled.drawLine(0, 48, 75, 48, WHITE);    //hmax
     //************************************************
    GOFoled.setTextSize(1);
    GOFoled.setCursor(0,0);
      GOFoled.print(F("V: "));GOFoled.println(gps.speed.kmph());
    GOFoled.setCursor(0,10);
      GOFoled.print(F("Alt: "));GOFoled.println(gps.altitude.meters());
    GOFoled.setCursor(0,20);
      GOFoled.print(F("Sat: "));GOFoled.println(sat,0);
    GOFoled.setCursor(0,30);
      GOFoled.print(F("Vmax: "));GOFoled.println(vmax);
    GOFoled.setCursor(0,40);
      GOFoled.print(F("hmax: "));GOFoled.println(hmax);
    GOFoled.setCursor(0,50);
      GOFoled.print("Kurs: "); GOFoled.println(buttonPushCounteru);
    GOFoled.setCursor(80,0);
      GOFoled.print(altitude);
    GOFoled.setCursor(80,10);
      GOFoled.print(temperature*0.1);
     
      GOFoled.setCursor(85,30);
      GOFoled.setTextSize(2);
      GOFoled.print("GPS");
      GOFoled.setCursor(82,50);
      GOFoled.setTextSize(1);
      GOFoled.print("ironman");
     
          GOFoled.display();
         
          }   
       
 
  if (buttonPushCounter == 1) {
        GOFoled.clearDisplay();
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,0);
        GOFoled.print(F("Geschwindigkeit"));
        GOFoled.setTextSize(2);
        GOFoled.setCursor(0,30);
        GOFoled.print(gps.speed.kmph()); GOFoled.print(" km/h");
       
          if (buttonPushCounteru == 1){
            GOFoled.setTextSize(1);
            GOFoled.setCursor(0,50);
            GOFoled.print("Vmax. ");  GOFoled.print(vmax); GOFoled.print(" km/h");
            }
           
        GOFoled.display();
     }
 
 
   if (buttonPushCounter == 2) {
        GOFoled.clearDisplay();
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,0);
        GOFoled.print(F("GPS Hoehe "));
        GOFoled.setTextSize(2);
        GOFoled.setCursor(0,30);
        GOFoled.print(gps.altitude.meters()); GOFoled.print(F(" m"));
        GOFoled.display();
  }
 
       
 
    if (buttonPushCounter == 3) {
        GOFoled.clearDisplay();
       
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,0);
        GOFoled.print(F("Barometrische Hoehe"));
        GOFoled.setTextSize(2);
        GOFoled.setCursor(0,30);
        GOFoled.print(altitude); GOFoled.print(F(" m"));
       
     
       
         if (buttonPushCounteru == 1){
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,50);
        GOFoled.print("Max.Hoehe ");  GOFoled.print(hmax); GOFoled.print("m");
       
        }
       
       GOFoled.display();
         
  }
 
 
   if (buttonPushCounter == 4) {
        GOFoled.clearDisplay();
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,0);
        GOFoled.print(F("Satelliten"));
        GOFoled.setTextSize(3);
        GOFoled.setCursor(55,30);
        GOFoled.println(sat,0);
        GOFoled.display();
  }
 
 
 
    if (buttonPushCounter == 5) {
        GOFoled.clearDisplay();
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,0);
        GOFoled.print(F("Koordinaten"));
        GOFoled.setTextSize(2);
        GOFoled.setCursor(0,20);
        GOFoled.println(gps.location.lat(),6);
        GOFoled.setTextSize(2);
        GOFoled.setCursor(0,40);
        GOFoled.println(gps.location.lng(),6);
       
       
 
       
         
       
       
        GOFoled.display();
  }

   
   
   
   
     if (buttonPushCounter == 6) {
       
       
       a = gps.location.lat();
       b = gps.location.lng();
       
     static const double Weiler_LAT = 48.57114, Weiler_LON = 10.04410; 
     unsigned long distance1 =
   (unsigned long)TinyGPSPlus::distanceBetween(Weiler_LAT, Weiler_LON,a, b)/1000;
   
        GOFoled.clearDisplay();
        GOFoled.setTextSize(1);
        GOFoled.setCursor(0,30);
        GOFoled.print(distance1);
        GOFoled.display();       
       
       
       
       
       
       GOFoled.display();
         
    }
       
   
     
         
         
    smartDelay(100);




}



regards iron
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Second part
Code:
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (Serial1.available())
      gps.encode(Serial.read());
  } while (millis() - start < ms);
}





// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
  ac1 = bmp085ReadInt(0xAA);
  ac2 = bmp085ReadInt(0xAC);
  ac3 = bmp085ReadInt(0xAE);
  ac4 = bmp085ReadInt(0xB0);
  ac5 = bmp085ReadInt(0xB2);
  ac6 = bmp085ReadInt(0xB4);
  b1 = bmp085ReadInt(0xB6);
  b2 = bmp085ReadInt(0xB8);
  mb = bmp085ReadInt(0xBA);
  mc = bmp085ReadInt(0xBC);
  md = bmp085ReadInt(0xBE);
}

// Calculate temperature given ut.
// Value returned will be in units of 0.1 deg C
short bmp085GetTemperature(unsigned int ut)
{
  long x1, x2;
 
  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
  x2 = ((long)mc << 11)/(x1 + md);
  b5 = x1 + x2;

  return ((b5 + 8)>>4); 
}

// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up)
{
  long x1, x2, x3, b3, b6, p;
  unsigned long b4, b7;
 
  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
 
  // Calculate B4
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
 
  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1)/b4;
  else
    p = (b7/b4)<<1;
   
  x1 = (p>>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
  p += (x1 + x2 + 3791)>>4;
 
  return p;
}

// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
  unsigned char data;
 
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
 
  Wire.requestFrom(BMP085_ADDRESS, 1);
  while(!Wire.available())
    ;
   
  return Wire.read();
}

// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
  unsigned char msb, lsb;
 
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
 
  Wire.requestFrom(BMP085_ADDRESS, 2);
  while(Wire.available()<2)
    ;
  msb = Wire.read();
  lsb = Wire.read();
 
  return (int) msb<<8 | lsb;
}

// Read the uncompensated temperature value
unsigned int bmp085ReadUT()
{
  unsigned int ut;
 
  // Write 0x2E into Register 0xF4
  // This requests a temperature reading
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x2E);
  Wire.endTransmission();
 
  // Wait at least 4.5ms
  delay(5);
 
  // Read two bytes from registers 0xF6 and 0xF7
  ut = bmp085ReadInt(0xF6);
  return ut;
}

// Read the uncompensated pressure value
unsigned long bmp085ReadUP()
{
  unsigned char msb, lsb, xlsb;
  unsigned long up = 0;
 
  // Write 0x34+(OSS<<6) into register 0xF4
  // Request a pressure reading w/ oversampling setting
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF4);
  Wire.write(0x34 + (OSS<<6));
  Wire.endTransmission();
 
  // Wait for conversion, delay time dependent on OSS
  delay(2 + (3<<OSS));
 
  // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  Wire.beginTransmission(BMP085_ADDRESS);
  Wire.write(0xF6);
  Wire.endTransmission();
  Wire.requestFrom(BMP085_ADDRESS, 3);
 
  // Wait for data to become available
  while(Wire.available() < 3)
    ;
  msb = Wire.read();
  lsb = Wire.read();
  xlsb = Wire.read();
 
  up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
 
  return up;
}
Logged

0
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12745
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps it would help to say what the problems are specifically?
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: