Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 and BMX055 Wifi i2c #2495

Closed
Hellakoe opened this issue Feb 22, 2019 · 9 comments
Closed

ESP32 and BMX055 Wifi i2c #2495

Hellakoe opened this issue Feb 22, 2019 · 9 comments
Assignees
Labels
Status: Stale Issue is stale stage (outdated/stuck)

Comments

@Hellakoe
Copy link

Hellakoe commented Feb 22, 2019

Hello,

I use the ESP32 to read out the positionsensor Bmx055 from Bosch via i2c, process it and show it on the web server.
The data processing works until I comment in Wifi.softAp(). After that only zeros are shown and i2c doesnt work anymore.
I have already tried the help of @stickbreaker and added his files to the Esp32 file. Unfortunately it doesnt work.
I also do not get any debug messages.
Do you have any idea?
I would be so grateful.
----------------------------- Remove above -----------------------------

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: 222/2/19
IDE name: Arduino IDE
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

Describe your problem here

Sketch: (leave the backquotes for code formatting)

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
 
#include <Wire.h>
#include <WiFi.h>

const char* ssid     = "ESP32";
const char* password = "12345";// offenes netzwerk,wenn auskommentiert
WiFiServer server(80);
 
 
void setup()
{

 
  Serial.begin(115200);


  // Connect to Wi-Fi network with SSID and password
  Serial.print("Setting AP (Access Point)…");
  // Remove the password parameter, if you want the AP (Access Point) to be open
  //WiFi.softAP(ssid, password);
  IPAddress IP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(IP);



  Wire.begin();
  
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, 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 next scan
}
@stickbreaker
Copy link
Contributor

Are you sure you want a binary 'OR' | here:

Serial.println("Gyrokonvertierung Ende");
//Alarmausgabe
 if ((xAccldiff < -350| xAccldiff > 350) || (yAccldiff < -350|| yAccldiff > 350) || (zAccldiff < -450|| zAccldiff > 450)  || (yGyrodiff < -30000|| yGyrodiff > 30000))
   {

Why do you read one byte at a time?

  for (int i = 0; i < 6; i++)
  {
    // Start I2C Transmission
    Wire.beginTransmission(Addr_Mag);
    // Select data register
    Wire.write((66 + i));
    // Stop I2C Transmission
    Wire.endTransmission();
    // Request 1 byte of data
    Wire.requestFrom(Addr_Mag, 1);
 
    // Read 6 bytes of data
    // xMag lsb, xMag msb, yMag lsb, yMag msb, zMag lsb, zMag msb
    if (Wire.available() == 1)
    {
      data[i] = Wire.read();
    }
  }

I would rewrite it to this:

    // Start I2C Transmission
    Wire.beginTransmission(Addr_Mag);
    // Select data register
    Wire.write((66));
    // Stop I2C Transmission
    Wire.endTransmission();
    If(Wire.lastError == I2C_ERROR_OK){ // device answered, accepted data
       Wire.requestFrom(Addr_Mag, 6);
       If (Wire.lastError !=I2C_ERROR_OK){// problem reading data
          Serial.printf("Problem reading Mag data err=%d(%s)\n",Wire.lastError(),Wire.getErrorText(Wire.lastError()));
       }
      else { // good data
         for(uint8_t i = 0;a <6; a++){
           data[i] = Wire.read();
         }
     }
   }
   else { // Problem setting address pointer
       Serial.printf(" Problem communicating with sensor at 0x%02X err=%d(%s)\n",Addr,Mag, Wire.lastError(), Wire.getErrorText(Wire.lastError()));
  }

You state you are having problems with I2C communications, but nowhere in you code do you check the I2C error returns?

I would test the error return after every Wire.endTransmission(), and Wire.requestFrom(). Try to find where the errors are occurring. Without knowing the errors and locations there is nothing you can do to solve the problems.

Chuck.

@Hellakoe
Copy link
Author

Hello chuck,

thank you so much for your help.

In this line I get the debug message: Invalid use of non-static member function

If(Wire.lastError == I2C_ERROR_OK){ // device answered, accepted data

Do you know what could be the reason?

Are you sure you want a binary 'OR' | here:
yes it was a mistake. it actually should be || instead of |.
This means if This or this or this ... happens do this. Right?

Hella

@lbernstone
Copy link
Contributor

Wire.lastError() is a function. You are using it as a variable.
Please note, this is not a forum for assistance with your code. It is for reporting errors in the arduino-esp32 codebase. In the future, please trim down your code to a minimal sketch that demonstrates the issue. A little effort on your part will make it much more likely that you get assistance.

@Hellakoe
Copy link
Author

hmm okay... Thanks for the hint.

I am a beginner at programming and new on github. Will know it for the future.

@Hellakoe
Copy link
Author

Hellakoe commented Mar 4, 2019

@stickbreaker
I tried to apply your advice and try to solve the problem with a simple source code. Once I comment in WiFi.softAP (ssid, password);, the board will not find i2c devices anymore. before that it worked perfectly. I have inserted the shortened text above. So I have found out that my problem with the web server and i2c is, right?
kind regards Hella

@lbernstone
Copy link
Contributor

The only interaction b/w the WiFi and i2c is power. Your power supply is not delivering enough current to drive all your requirements.

@stickbreaker stickbreaker self-assigned this May 19, 2019
@stickbreaker
Copy link
Contributor

@Hellakoe
Have you solved you issues?

@stale
Copy link

stale bot commented Jul 31, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Jul 31, 2019
@stale
Copy link

stale bot commented Aug 14, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Stale Issue is stale stage (outdated/stuck)
Projects
None yet
Development

No branches or pull requests

3 participants