Arduino MKR Zero - I2C and communications

Sorry !!!
I am trying to read data from a BMP180 with an Arduino MKR Zero.
I have problems uploading the program. If I have the BMP180 connected to both I2C bus (D11 and d12) the program does not upload. If I disconnect it, if I can upload the program but the program does not start.
I do not know what's happening !!!

This program on an ARDUINO UNO, works fine

// Sonda digital BMP180 - I2C
// Llibreries i variables-----------------------------------------------------
#include <SFE_BMP180.h>
#include <Wire.h>

SFE_BMP180 bmp180;
double PresionNivellMar = 1013.25; //pressio sobre el nivell del mar en mar

// Configuració SETUP del programa********************************************
void setup()
  {
  delay(500);           //esperem 0,5 segons   
  Serial.begin(9600);   //port serie
  Serial.println("**************");
  Serial.println("Sonda MBP180  ");
  Serial.println("**************");
  delay(1000);
 
  if (bmp180.begin())
    Serial.println("BMP180 iniciado");
  else
    {
    Serial.println("Error al iniciar BMP180");
    while(1); // bucle infinito
    }
  
  }
// INICI DEL PROGRAMA********************************************************* 
void loop()
  {   
  Serial.println(" -> Dades capturades  :");  
  CapturaDeDades(); 
  Esperem (1); //esperem 1, 10 minut,...
  delay (1000);  //esperem 1 segon
  }
//Fi bucle del programa******************************************************  


//Funció capturar dades------------------------------------------------------
void CapturaDeDades()
  {
  char status;
  double Temperatura, Pressio, Altitud;
  
  status = bmp180.startTemperature(); //Inici de lectura de temperatura
    if (status != 0)
    {   
      delay(status);                  //Pausa perque acavi la lectura
      status = bmp180.getTemperature(Temperatura); //Obtener la temperatura
      if (status != 0)
      {
        status = bmp180.startPressure(3); //Inici lectura de pressio
        if (status != 0)
        {        
          delay(status); //Pausa perque acavi la lectura        
          status = bmp180.getPressure(Pressio, Temperatura); //Obtenim la presio
          if (status != 0)
          {                  
            Serial.print(" -> Temperatura: ");
            Serial.print(Temperatura,2);
            Serial.print(" *C , ");
            Serial.print("Presion: ");
            Serial.print(Pressio,2);
            Serial.print(" mb, ");         
            Altitud = bmp180.altitude(Pressio,PresionNivellMar); //Calcular altura
            Serial.print("Altitud: ");
            Serial.print(Altitud);
            Serial.println(" m");  
          }      
        }      
      }   
    }   
  }
// Fi capturar dades---------------------------------------------------------

// Funció temps d'espera entre captura de dades, en minuts-------------------
void Esperem (int minuts)
  {
  Serial.print(" -> Esperant (minuts) :");
  Serial.println( minuts);
  Serial.println (" ");
  for (int a=0; a<minuts; a++)
    {
    //delay(60000);  //60000 es un minut
    delay(5000);  //60000 es un minut
    }
  }
// Fi funció temps d'espera--------------------------------------------------

Perhaps post in the section appropriate to the language you understand, this is clearly an English forum .......

Sorry !!!

Hi @aprentik

Is the BMP180 breakout board being powered with the MKRZero's 3.3V supply pin?

Good morning. If I have it powered with the VCC, which I have checked is 3.3V. I put the pull-up resistors on D11 and D12, because I have read that it is not clear that they are there.
I have also been trying to read the data of a GPS through the serial pin D14 Tx and D13RX (Serial1) and things also happen to me that I do not understand. If the GPS receiver does not transmit, the program is blocked. When the GPS receiver receives data from the satellites, then the program works well. That doesn't happen to me with UNO. I also attach the GPS program.
I don't know if I'm doing it wrong or this board is letting me down. Any ideas? Thank you very much.

GPS: https://learn.adafruit.com/adafruit‐ultimate‐gps/

//Arduino MKR Zero
//GPS (TX)(RX) conectat a pin de l'arduino D13(RX) i D14(TX)
//GPSTX a RX(13)
//GPSRX a TX(14)

//informacio de la llibreri TimyGPSPlus
//http://arduiniana.org/libraries/tinygpsplus/

#include <TinyGPS++.h>

//Initialize TinyGPS++ object
TinyGPSPlus gps;

void setup() 
  {
  //while (!Serial);
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial.println("Test GPSBasic - Arduino MKR Zero"); 
  Serial1.println("Test GPSBasic - Arduino MKR Zero"); 
  }

void loop() 
  {
  while (Serial1.available() > 0)
    if (gps.encode(Serial1.read()))
      if (gps.location.isValid())
        {
        Serial.print("Latitud         : ");  
        Serial.println(gps.location.lat(), 6);
        Serial.print("Longitud        : ");
        Serial.println(gps.location.lng(), 6);
        Serial.print("Data            : "); Serial.print(gps.date.day()); Serial.print("/"); 
        Serial.print(gps.date.month()); Serial.print("/"); Serial.println(gps.date.year());
        Serial.print("Hora            : "); Serial.print(gps.time.hour()); Serial.print(":"); 
        Serial.print(gps.time.minute()); Serial.print(":"); Serial.println(gps.time.second());
        Serial.print("Altitud (metres): "); Serial.println(gps.altitude.meters()); 
        Serial.print("Rumb (graus)    : "); Serial.println(gps.course.deg()); 
        Serial.print("Velocitat(kmph) : "); Serial.println(gps.speed.kmph());
        Serial.print("Satelits        : "); Serial.println(gps.satellites.value()); 
        Serial.println("");

        Serial1.print("1;"); 
        Serial1.print(gps.location.lat(), 6); Serial1.print(" "); Serial1.print(gps.location.lng(), 6);Serial1.print(";"); 
        Serial1.print(gps.date.day()); Serial1.print("/"); 
        Serial1.print(gps.date.month()); Serial1.print("/"); 
        Serial1.print(gps.date.year()); Serial1.print(";"); 
        Serial1.print(gps.time.hour()); Serial1.print(":"); 
        Serial1.print(gps.time.minute()); Serial1.print(":"); 
        Serial1.print(gps.time.second()); Serial1.print(";");
        Serial1.print(gps.altitude.meters()); Serial1.print(";");
        Serial1.print(gps.course.deg()); Serial1.print(";");
        Serial1.print(gps.speed.kmph()); Serial1.print(";");
        Serial1.print(gps.satellites.value()); Serial1.print(";");
        Serial1.println("");
        
        delay (100);
      }
 }

One problem at a time! Let's get the bmp180 working before looking at the GPS problem.

Have you tried running the i²c scanner sketch? You should find it in the examples menu in the IDE. It should indicate if the sensor is visible on the i²c bus.

Yes, in parts. First BMP180.
I don't know what you mean by this: "Have you tried running the i²c scanner sketch? You should find it in the examples menu in the IDE. It should indicate if the sensor is visible on the i²c bus."
How do I do it?

Can this code work for me?

/ /---------------------------------------------------------------- /
// Arduino I2C Scanner
// Re-writed by Arbi Abdul Jabbaar
// Using Arduino IDE 1.8.7
// Using GY-87 module for the target
// Tested on 10 September 2019
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
// ---------------------------------------------------------------- /

#include <Wire.h> //include Wire.h library

void setup()
{
  Wire.begin(); // Wire communication begin
  Serial.begin(9600); // The baudrate of Serial monitor is set in 9600
  while (!Serial); // Waiting for Serial Monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address; //variable for error and I2C address
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000); // wait 5 seconds for the next I2C scan
}

Result:
Scanning...
No I2C devices found
!!!!

I have tested this scan code with two different I2C devices, the BMP180 and an RTC I have. It doesn't find them and the serial port (Arduino monitor) sometimes gets blocked. It gives me the feeling that the serial port (serial) and the I2C bus are linked to each other. I don't see how to detect the problem!!!

Scanning...
I2C device found at address 0x68 !
I2C device found at address 0x77 !
done

I did the assembly without the pull-up resistors and now it sees both devices, the BMP and the RTC. I don't see it completely clearly, but now it comes.

Right now, the BMP180 is working fine for me.
I have my doubts and it gives me little confidence.
Now I have to see what happens with the GPS.

// Sonda digital BMP180 - I2C
// ***************************************************************************
// Llibreries i variables-----------------------------------------------------
#include <SFE_BMP180.h>
#include <Wire.h>

SFE_BMP180 bmp180;
double PresionNivellMar = 1013.25; //presio sobre el nivel del mar en mbar

// Configuració SETUP del programa********************************************
void setup()
  {
  delay(500);           //esperem 0,5 segons   
  Serial.begin(9600);   //port serie
  Serial.println("**************");
  Serial.println("Sonda MBP180  ");
  Serial.println("**************");

  if (bmp180.begin())
    Serial.println("BMP180 iniciado");
  else
    {
    Serial.println("Error al iniciar BMP180");
    while(1); // bucle infinito
    }
  }
// INICI DEL PROGRAMA********************************************************* 
void loop()
  {   
  Serial.println(" -> Dades capturades  :");  
  CapturaDeDades(); 
  Esperem (1); //esperem 1, 10 minut,...
  delay (1000);  //esperem 1 segon
  }
//Fi bucle del programa******************************************************  


//Funció capturar dades------------------------------------------------------
void CapturaDeDades()
  {
  char status;
  double Temperatura, Pressio, Altitud;
  
  status = bmp180.startTemperature(); //Inici de lectura de temperatura
    if (status != 0)
    {   
      delay(status);                  //Pausa perque acavi la lectura
      status = bmp180.getTemperature(Temperatura); //Obtener la temperatura
      if (status != 0)
      {
        status = bmp180.startPressure(3); //Inici lectura de pressio
        if (status != 0)
        {        
          delay(status); //Pausa perque acavi la lectura        
          status = bmp180.getPressure(Pressio, Temperatura); //Obtenim la presio
          if (status != 0)
          {                  
            Serial.print(" -> Temperatura: ");
            Serial.print(Temperatura,2);
            Serial.print(" *C , ");
            Serial.print("Presion: ");
            Serial.print(Pressio,2);
            Serial.print(" mb, ");         
            Altitud = bmp180.altitude(Pressio,PresionNivellMar); //Calcular altura
            Serial.print("Altitud: ");
            Serial.print(Altitud);
            Serial.println(" m");  
          }      
        }      
      }   
    }   
  }
// Fi capturar dades---------------------------------------------------------

// Funció temps d'espera entre captura de dades, en minuts-------------------
void Esperem (int minuts)
  {
  Serial.print(" -> Esperant (minuts) :");
  Serial.println( minuts);
  Serial.println (" ");
  for (int a=0; a<minuts; a++)
    {
    //delay(60000);  //60000 es un minut
    delay(5000);  //60000 es un minut
    }
  }
// Fi funció temps d'espera--------------------------------------------------

Result:

-> Dades capturades :
-> Temperatura: 22.20 *C , Presion: 961.45 mb, Altitud: 440.44 m
-> Esperant (minuts) :1

Take a look at the code, see how much data you are printing each time the GPS library has encoded a GPS sentence. Appreciate that about 1 in 4 GPS sentences contain actual position data, so why print data when nothing has changed.

You might try Serial.begin(115200); to speed up the vast amount of stuff your are printing .......

From the GPS, I will try to increase the speed of the serial port. For the students I am helping, they must register the data at most every second and the GPS data will change. I will do more tests. Thanks.

The problem with GPS has nothing to do with the speed of communications. If the GPS receives data from the satellites, the program is working correctly. In the case that it does not receive data, the program does nothing. I can't track anything. It's as if the program doesn't go through setup.

Well, I would disagree, the speed of communications for Serial.print() commands, can have a significant affect on being able to read a GPS properly.

Out of interest why do you also have a heap of Serial1.print() commands, GPSs get very confused unlsess the data you send them is in the form of very specific commands.

Thanks for your comments. I sure have a problem and I won't rule out any avenues. This program and GPS on an Arduino UNO and MEGA, works fine, even if the GPS does not receive data. This GPS has an LED, if the LED blinks quickly, it means that it is not receiving data from the satellites, this is how the program gets blocked, it does not load anything!!! If the GPS LED blinks slowly, if it receives data from the satellites and I receive the data, the program works correctly. I don't see why or what the error is.

The program you posted in post #5 would not work on a UNO.

And what was the answer to the question asked in post #14, I normally ask questions for good reasons ...........

Thanks for your comments and questions. Thanks to them I am moving forward and learning. It's not the same code, for the Arduino I use the "softwareserial" in Serial1, and some other details.
What I will do is look with the Arduino UNO, what is the difference between what the GSP sends when it does not have data and when it does. I will review everything three times. I'm sure there's some detail I'm overlooking. Thanks for your help and input.

With this modification to the code, it works better. It needs to be improved.

//Arduino MKR Zero
//GPS (TX)(RX) conectat a pin de l'arduino D13(RX) i D14(TX)
//GPSTX a RX(13)
//GPSRX a TX(14)

//informacio de la llibreri TimyGPSPlus
//http://arduiniana.org/libraries/tinygpsplus/

#include <TinyGPS++.h>

//Initialize TinyGPS++ object
TinyGPSPlus gps;

void setup() 
  {
  //while (!Serial);
  Serial.begin(9600);
  Serial1.begin(9600);
  }

void loop() 
  {
  Serial.print(".");  
  CapturaGPS();
  delay(100);
  }

void CapturaGPS()
  {
  if (gps.encode(Serial1.read()))
      if (gps.location.isValid())
        {  
        Serial.println(" ");  
        Serial.print("Latitud         : ");  
        Serial.println(gps.location.lat(), 6);
        Serial.print("Longitud        : ");
        Serial.println(gps.location.lng(), 6);
        Serial.print("Data            : "); Serial.print(gps.date.day()); Serial.print("/"); 
        Serial.print(gps.date.month()); Serial.print("/"); Serial.println(gps.date.year());
        Serial.print("Hora            : "); Serial.print(gps.time.hour()); Serial.print(":"); 
        Serial.print(gps.time.minute()); Serial.print(":"); Serial.println(gps.time.second());
        Serial.print("Altitud (metres): "); Serial.println(gps.altitude.meters()); 
        Serial.print("Rumb (graus)    : "); Serial.println(gps.course.deg()); 
        Serial.print("Velocitat(kmph) : "); Serial.println(gps.speed.kmph());
        Serial.print("Satelits        : "); Serial.println(gps.satellites.value()); 
        Serial.println("");
      
        Serial1.print("1;"); 
        Serial1.print(gps.location.lat(), 6);Serial1.print(" ");Serial1.print(gps.location.lng(), 6);Serial1.print(";"); 
        Serial1.print(gps.date.day()); Serial1.print("/"); 
        Serial1.print(gps.date.month()); Serial1.print("/"); 
        Serial1.print(gps.date.year()); Serial1.print(";"); 
        Serial1.print(gps.time.hour()); Serial1.print(":"); 
        Serial1.print(gps.time.minute()); Serial1.print(":"); 
        Serial1.print(gps.time.second()); Serial1.print(";");
        Serial1.print(gps.altitude.meters()); Serial1.print(";");
        Serial1.print(gps.course.deg()); Serial1.print(";");
        Serial1.print(gps.speed.kmph()); Serial1.print(";");
        Serial1.print(gps.satellites.value()); Serial1.print(";");
        Serial1.println("");
        }
  }

I have changed the library, I have recovered the "TinyGPS.h" and I think I have it more under control. I'll leave it at that for now.
I have added radio communication, an APC220, I am attaching a file with how I have it configured. I don't know if it's the best option, but it's the one I have for now. Thanks for the help.

//Arduino MKR Zero
//Adafruit GPS MTK3339 
//Arduino MKR Zero
//GPS_TX a RX(13)
//GPS_RX a TX(14)  NO conectat
//APC220_TX a RX(13 No Conectat
//APC220_RX Rx a TX(14)
//GPS -> GND Ground ;  VCC +5V
//APC220 -> GND Grouns; Vin + 5V
//GPS -> Make sure you download TinyGPS.h

#include <TinyGPS.h>

unsigned long fix_age;

// Variables GPS
TinyGPS gps;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
long lat, lon;
float LAT, LON;
int year;
byte month, day, hour, minute, second, hundredths;
// Fi variables GPS

void setup()
  {
  Serial1.begin(9600);
  Serial.begin(9600);
  Serial.println(" ");
  Serial.println("*****************************************");
  Serial.println("Receptor dades GPS - Adafruit GPS MTK3339 ");
  Serial.println("Versio: xxxxx ");
  Serial.println("*****************************************");   
  }

void loop()
  {
  CapturaGPS();
  }

// Funcios GPS *************************************************
void CapturaGPS()
  {
  gps.get_position(&lat, &lon, &fix_age);
  getGPS();
  Serial.print("Latitud : ");
  Serial.print(LAT/1000000,7);
  Serial.print(" i Longitud : ");
  Serial.println(LON/1000000,7);
  Serial.print("Data            : "); Serial.print(day, DEC); Serial.print("/"); 
  Serial.print(month, DEC); Serial.print("/"); Serial.println(year);
  Serial.print("Hora            : "); Serial.print(hour, DEC); Serial.print(":"); 
  Serial.print(minute, DEC); Serial.print(":"); Serial.println(second, DEC); 
  Serial.print("Altitud (metres): "); Serial.println(gps.f_altitude()); 
  Serial.print("Rumb (graus)    : "); Serial.println(gps.f_course()); 
  Serial.print("Velocitat(kmph) : "); Serial.println(gps.f_speed_kmph());
  Serial.print("Satelits        : "); Serial.println(gps.satellites()); 
  Serial.println();  

  Serial1.print("1;"); 
  Serial1.print(LAT/1000000,7);Serial1.print(" ");Serial1.print(LON/1000000,7);Serial1.print(";"); 
  Serial1.print(day, DEC); Serial1.print("/"); 
  Serial1.print(month, DEC); Serial1.print("/"); 
  Serial1.print(year); Serial1.print(";"); 
  Serial1.print(hour,DEC); Serial1.print(":"); 
  Serial1.print(minute,DEC); Serial1.print(":"); 
  Serial1.print(second,DEC); Serial1.print(";");
  Serial1.print(gps.f_altitude()); Serial1.print(";");
  Serial1.print(gps.f_course()); Serial1.print(";");
  Serial1.print(gps.f_speed_kmph()); Serial1.print(";");
  Serial1.print(gps.satellites()); Serial1.print(";");
  Serial1.println("");
  }

void getGPS()
  {
    bool newdata = false;
    unsigned long start = millis();
    // Every 1 seconds we print an update
    while (millis() - start < 1000)
    {
      if (feedgps ()){
        newdata = true;
      }
    }
    if (newdata)
    {
      gpsdump(gps);
    }
  }

bool feedgps()
  {
    while (Serial1.available())
    {
      if (gps.encode(Serial1.read()))
        return true;
    }
    return 0;
  }

void gpsdump(TinyGPS &gps)
  {
    //byte month, day, hour, minute, second, hundredths;
    gps.get_position(&lat, &lon);
    gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);   
    LAT = lat;
    LON = lon;
    {
      feedgps(); // If we don't feed the gps during this long routine, we may drop characters and get checksum errors
    }
  }

// Fi funcios GPS *************************************************

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.