 const int TMP116_temp_reg   = 0x00;  // Temperature register
 const int TMP116_config_reg = 0x01;  // Configuration register
 
+int counter=10;
+
+bool has_bme = true;
+
 void setup()
 {
   Serial.begin(57600);
   Serial.println("MIKROE SAM3X WeatherDemo");
 
-  SPI.begin();
-  SPI.setDataMode( SPI_MODE1 );
+  bme_init();
 
-  thunder_init();
+//  SPI.begin();
+//  SPI.setDataMode( SPI_MODE1 );
 
-  Wire.begin();
+//  thunder_init();
 
-  tmp116_init();
+//  Wire.begin();
+
+//  tmp116_init();
 }
 
 void loop()
 {
-  double temp = TMP116_ReadTempSensor();
+//  double temp = TMP116_ReadTempSensor();
+//  Serial.println(temp);
+  
+//  if(digitalRead(AS3935_INT) == HIGH){
+//    AS3935_intVal = lightning.readInterruptReg();
+//    if(AS3935_intVal == AS3935_NOISE_INT){
+//      Serial.println("debug: Noise."); 
+//    }
+//    else if(AS3935_intVal == AS3935_DISTURBER_INT){
+//      Serial.println("debug: Disturber."); 
+//    }
+//    else if(AS3935_intVal == AS3935_LIGHTNING_INT){
+//      Serial.println("debug: Lightning Strike Detected!"); 
+//      // Lightning! Now how far away is it? Distance estimation takes into
+//      // account any previously seen events in the last 15 seconds. 
+//      byte distance = lightning.distanceToStorm(); 
+//      Serial.print("Approximately: "); 
+//      Serial.print(distance); 
+//      Serial.println("km away!"); 
+//    }
+//  }
 
-  Serial.println(temp);
-  
-  if(digitalRead(AS3935_INT) == HIGH){
-    AS3935_intVal = lightning.readInterruptReg();
-    if(AS3935_intVal == AS3935_NOISE_INT){
-      Serial.println("debug: Noise."); 
-    }
-    else if(AS3935_intVal == AS3935_DISTURBER_INT){
-      Serial.println("debug: Disturber."); 
-    }
-    else if(AS3935_intVal == AS3935_LIGHTNING_INT){
-      Serial.println("debug: Lightning Strike Detected!"); 
-      // Lightning! Now how far away is it? Distance estimation takes into
-      // account any previously seen events in the last 15 seconds. 
-      byte distance = lightning.distanceToStorm(); 
-      Serial.print("Approximately: "); 
-      Serial.print(distance); 
-      Serial.println("km away!"); 
-    }
+  bme_read();
+
+  counter++;
+  if (counter == 100)
+  {
+    counter = 10;
   }
 
   delay(5000); // wait 5 seconds for the next I2C scan
+}
+
+void bme_init() {
+   if (! bme.begin(0x76, &Wire)) {
+        Serial.println("Could not find a valid BME280 sensor, check wiring!");
+        has_bme=false;
+    }  
+}
+
+void bme_read() {
+    bme.takeForcedMeasurement(); // has no effect in normal mode
+
+    Serial.print("MIKROESAM3X_WC:");
+    Serial.print(counter);
+    Serial.print(":Temp:");
+    float bme_temp_c = bme.readTemperature();
+    float bme_temp_f = ((bme_temp_c * 1.8) + 32);
+    Serial.print(bme_temp_f);
+    Serial.print("F:Press:");
+    Serial.print(bme.readPressure() / 100.0F);
+    Serial.print("mB:Humidity:");
+    Serial.print(bme.readHumidity());
+    Serial.println("%:#");
 }
 
 void thunder_init()

#include <SPI.h>
#include <Wire.h>
#include "flip_click_defs.h"
#include "SparkFun_AS3935.h"

#define AS3935_INDOOR 0x12 
#define AS3935_OUTDOOR 0xE

#define AS3935_CS  B_CS
#define AS3935_INT B_INT

//SparkFun_AS3935 lightning;

int AS3935_intVal = 0;
int AS3935_noise = 2; // Value between 1-7 
