Closed kriswiner closed 7 years ago
what is that slave device that you are trying to access?
MPU9250 and MS5637.
OK, I confirmed I can read the I2C pressure/temperature sensor MS5637, which essentially uses one byte at a time for reads and writes. Here is the sketch that works just fine:
#include "Wire.h"
// See MS5637-02BA03 Low Voltage Barometric Pressure Sensor Data Sheet
#define MS5637_RESET 0x1E
#define MS5637_CONVERT_D1 0x40
#define MS5637_CONVERT_D2 0x50
#define MS5637_ADC_READ 0x00
#define MS5637_ADDRESS 0x76 // Address of altimeter
#define SerialDebug true // set to true to get Serial output for debugging
#define ADC_256 0x00 // define pressure and temperature conversion rates
#define ADC_512 0x02
#define ADC_1024 0x04
#define ADC_2048 0x06
#define ADC_4096 0x08
#define ADC_8192 0x0A
#define ADC_D1 0x40
#define ADC_D2 0x50
// Specify sensor full scale
uint8_t OSR = ADC_8192; // set pressure amd temperature oversample rate
// Pin definitions
int intPin = 14;
int myLed = 5;
uint16_t Pcal[8]; // calibration constants from MS5637 PROM registers
unsigned char nCRC; // calculated check sum to ensure PROM integrity
uint32_t D1 = 0, D2 = 0; // raw MS5637 pressure and temperature data
double dT, OFFSET, SENS, TT2, OFFSET2, SENS2; // First order and second order corrections for raw S5637 temperature and pressure data
int16_t tempCount; // temperature raw count output
float temperature; // Stores the MPU9250 gyro internal chip temperature in degrees Celsius
double Temperature, Pressure; // stores MS5637 pressures sensor pressure and temperature
// global constants for 9 DoF fusion and AHRS (Attitude and Heading Reference System)
float pi = 3.141592653589793238462643383279502884f;
void setup()
{
Serial.begin(115200);
delay(4000);
Wire.begin(21,22); // 21/22 are default on ESP32
Wire.setClock(400000); // choose 400 kHz I2C rate
// Wire.setClockStretchLimit(1000000);
delay(1000);
// Set up the interrupt pin, its set as active high, push-pull
pinMode(intPin, INPUT);
pinMode(myLed, OUTPUT);
digitalWrite(myLed, LOW);
I2Cscan();// look for I2C devices on the bus
// Reset the MS5637 pressure sensor
MS5637Reset();
delay(100);
Serial.println("MS5637 pressure sensor reset...");
// Read PROM data from MS5637 pressure sensor
MS5637PromRead(Pcal);
Serial.println("PROM dta read:");
Serial.print("C0 = "); Serial.println(Pcal[0]);
unsigned char refCRC = Pcal[0] >> 12;
Serial.print("C1 = "); Serial.println(Pcal[1]);
Serial.print("C2 = "); Serial.println(Pcal[2]);
Serial.print("C3 = "); Serial.println(Pcal[3]);
Serial.print("C4 = "); Serial.println(Pcal[4]);
Serial.print("C5 = "); Serial.println(Pcal[5]);
Serial.print("C6 = "); Serial.println(Pcal[6]);
nCRC = MS5637checkCRC(Pcal); //calculate checksum to ensure integrity of MS5637 calibration data
Serial.print("Checksum = "); Serial.print(nCRC); Serial.print(" , should be "); Serial.println(refCRC);
}
void loop()
{
D1 = MS5637Read(ADC_D1, OSR); // get raw pressure value
D2 = MS5637Read(ADC_D2, OSR); // get raw temperature value
dT = D2 - Pcal[5]*pow(2,8); // calculate temperature difference from reference
OFFSET = Pcal[2]*pow(2, 17) + dT*Pcal[4]/pow(2,6);
SENS = Pcal[1]*pow(2,16) + dT*Pcal[3]/pow(2,7);
Temperature = (2000 + (dT*Pcal[6])/pow(2, 23))/100; // First-order Temperature in degrees Centigrade
//
// Second order corrections
if(Temperature > 20)
{
TT2 = 5*dT*dT/pow(2, 38); // correction for high temperatures
OFFSET2 = 0;
SENS2 = 0;
}
if(Temperature < 20) // correction for low temperature
{
TT2 = 3*dT*dT/pow(2, 33);
OFFSET2 = 61*(100*Temperature - 2000)*(100*Temperature - 2000)/16;
SENS2 = 29*(100*Temperature - 2000)*(100*Temperature - 2000)/16;
}
if(Temperature < -15) // correction for very low temperature
{
OFFSET2 = OFFSET2 + 17*(100*Temperature + 1500)*(100*Temperature + 1500);
SENS2 = SENS2 + 9*(100*Temperature + 1500)*(100*Temperature + 1500);
}
// End of second order corrections
//
Temperature = Temperature - T2/100;
OFFSET = OFFSET - OFFSET2;
SENS = SENS - SENS2;
Pressure = (((D1*SENS)/pow(2, 21) - OFFSET)/pow(2, 15))/100; // Pressure in mbar or kPa
float altitude = 145366.45*(1. - pow((Pressure/1013.25), 0.190284));
if(SerialDebug) {
Serial.print("Digital temperature value = "); Serial.print( (float)Temperature, 2); Serial.println(" C"); // temperature in degrees Celsius
Serial.print("Digital temperature value = "); Serial.print(9.*(float) Temperature/5. + 32., 2); Serial.println(" F"); // temperature in degrees Fahrenheit
Serial.print("Digital pressure value = "); Serial.print((float) Pressure, 2); Serial.println(" mbar");// pressure in millibar
Serial.print("Altitude = "); Serial.print(altitude, 2); Serial.println(" feet");
}
digitalWrite(myLed, !digitalRead(myLed));
delay(500);
}
//===================================================================================================================
//====== Set of useful function to access acceleration. gyroscope, magnetometer, and temperature data
//===================================================================================================================
// I2C communication with the MS5637 is a little different from that with the MPU9250 and most other sensors
// For the MS5637, we write commands, and the MS5637 sends data in response, rather than directly reading
// MS5637 registers
void MS5637Reset()
{
Wire.beginTransmission(MS5637_ADDRESS); // Initialize the Tx buffer
Wire.write(MS5637_RESET); // Put reset command in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
void MS5637PromRead(uint16_t * destination)
{
uint8_t data[2] = {0,0};
for (uint8_t ii = 0; ii < 7; ii++) {
Wire.beginTransmission(MS5637_ADDRESS); // Initialize the Tx buffer
Wire.write(0xA0 | ii << 1); // Put PROM address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(MS5637_ADDRESS, 2); // Read two bytes from slave PROM address
while (Wire.available()) {
data[i++] = Wire.read(); } // Put read results in the Rx buffer
destination[ii] = (uint16_t) (((uint16_t) data[0] << 8) | data[1]); // construct PROM data for return to main program
}
}
uint32_t MS5637Read(uint8_t CMD, uint8_t OSR) // temperature data read
{
uint8_t data[3] = {0,0,0};
Wire.beginTransmission(MS5637_ADDRESS); // Initialize the Tx buffer
Wire.write(CMD | OSR); // Put pressure conversion command in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
switch (OSR)
{
case ADC_256: delay(1); break; // delay for conversion to complete
case ADC_512: delay(3); break;
case ADC_1024: delay(4); break;
case ADC_2048: delay(6); break;
case ADC_4096: delay(10); break;
case ADC_8192: delay(20); break;
}
Wire.beginTransmission(MS5637_ADDRESS); // Initialize the Tx buffer
Wire.write(0x00); // Put ADC read command in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(MS5637_ADDRESS, 3); // Read three bytes from slave PROM address
while (Wire.available()) {
data[i++] = Wire.read(); } // Put read results in the Rx buffer
return (uint32_t) (((uint32_t) data[0] << 16) | (uint32_t) data[1] << 8 | data[2]); // construct PROM data for return to main program
}
unsigned char MS5637checkCRC(uint16_t * n_prom) // calculate checksum from PROM register contents
{
int cnt;
unsigned int n_rem = 0;
unsigned char n_bit;
n_prom[0] = ((n_prom[0]) & 0x0FFF); // replace CRC byte by 0 for checksum calculation
n_prom[7] = 0;
for(cnt = 0; cnt < 16; cnt++)
{
if(cnt%2==1) n_rem ^= (unsigned short) ((n_prom[cnt>>1]) & 0x00FF);
else n_rem ^= (unsigned short) (n_prom[cnt>>1]>>8);
for(n_bit = 8; n_bit > 0; n_bit--)
{
if(n_rem & 0x8000) n_rem = (n_rem<<1) ^ 0x3000;
else n_rem = (n_rem<<1);
}
}
n_rem = ((n_rem>>12) & 0x000F);
return (n_rem ^ 0x00);
}
// simple function to scan for I2C devices on the bus
void I2Cscan()
{
// scan for i2c devices
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");
}
But if I try to read the MPU9250 which requires write of a device address, then a register address (more than one byte), then I can not read any data from it. Here is the multi-byte I2C function:
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
Some how the second byte is causing the I2C bus to get hing up. Not sure why but this is the reason most I2C devices cannot be read by the ESP32 except for the very simple (command and response types) ones. Although now that I look at both readByte functions, they look pretty similar so now I don't know why one works and one does not.
@kriswiner hey man can you please explain how did you connect the MS5637 to the esp32 im trying to conect the mpu6050 motion sensor but i failed
I connected pin 21 to SDA, pin 22 to SCL and then 3V3 and GND. But this won't help you since i can't get anything but the I2C address out of the companion MPU9250. There is something different about the Invensense I2C bus/controller that is causing the I2C bus to latch up. Might be a clock stretching issue. I have seen this before on the ESP8266/85. I am using 4K7 pullips on the I2C lines, which usually works for a variety of controllers including the ESP8266/85. But somehow the ESP32 is having trouble with it.
So now what is the solution if i wanna get the motion sensor connected to esp32 i tried alot to find in the internet i did not fine anything
Don't know, I'd like to get the other I2C sensors working as well. I am going to test more but I have not been able to get the MPU9250 to work yet.
Lokks like we will both have to just wait until this is fixed. Or go backt o using the ESP8266/85!
Okay man if i got anything i will post it here and let u know ,good luck
guys calm down :) i'm working on it and so far I can read MPU fine. Update will be up soon.
No disresepect intended, you guys are doing great work!
Just trying to do my part ;>
I am looking forward to your fix.
issue with MPU was directly connected to the fact that before you read from it, you do not send stop (Wire.endTransfer(false)). Now that I have that fixed, I can not write more than 9 bytes to I2C... cat and mouse with this bus
please try the latest commit
I just tried the new core and I am still having the same problem. I can see the I2C devices on the bus but cannot read from the MPU9250 WHO_AM_I register. This is the output I get:
Scanning...
I2C device found at address 0x68 !
I2C device found at address 0x76 !
done
MPU9250 9-axis motion sensor...
MPU9250 I AM FF I should be 71
Could not connect to MPU9250: 0xFF
I verified I can still get data from the MS5637 alone. That is, if I only ask for MS5637 data, read and write from/to MS5637 only then everything works, but when I try to talk with the MPU9250 the bus gets stuck and I can't talk to either.
I also verified that I can get data from the VEML6040 I2C RGBW sensor. So some work and some don't. Odd...
But cannot read the BMX055:
Scanning...
I2C device found at address 0x10 !
I2C device found at address 0x18 !
I2C device found at address 0x1E !
I2C device found at address 0x59 !
I2C device found at address 0x68 !
I2C device found at address 0x69 !
I2C device found at address 0x6A !
done
BMX055 accelerometer...
BMX055 ACC I AM 0xFF I should be 0xFA
BMX055 gyroscope...
BMX055 GYRO I AM 0xFF I should be 0xF
BMX055 magnetometer...
BMX055 MAG I AM 0xFF I should be 0x32
Could not connect to BMX055: 0xFF
@kriswiner Can you try adding another Wire.beginTransmission to get the result instead of using endTransmission(false)? Just curious, I haven't received my ESP32 yet to help test. If it works.. might be a hint.
But if I try to read the MPU9250 which requires write of a device address, then a register address (more than one byte), then I can not read any data from it. Here is the multi-byte I2C function:
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
Change to...
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(); // <<------
Wire.beginTransmission(address); // <<------
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
I tried this:
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data = 0; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
// Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.endTransmission(); // <<------
Wire.beginTransmission(address); // <<------
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
and I get the same behavior. MS5637 alone works, but MPU9250 does not.
Here is what I have found:
Here is an image when you read only one byte:
Here is when you read two bytes:
const uint8_t MPU_addr=0x68; // I2C address of the MPU-6050
#define WHO_AM_I_MPU9250 0x75 // Should return 0x71
uint8_t mpuWhoAmI()
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(MPU_addr); // Initialize the Tx buffer
Wire.write(WHO_AM_I_MPU9250); // Put slave register address in Tx buffer
Wire.endTransmission(true); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(MPU_addr, (uint8_t) 2); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
Wire.read();
return data; // Return data read from slave register
}
Just tested manually and the MPU does not release SDA until it gets another 8 clocks. I know I wrote code to add more clocks for ESP8266, but there I2C is software and here is hardware. We do not have another way of sending more clocks than reading more or writing more
Tried the fix and it seems to work. I can read the MPU9250 and AK8963C. The fusion rate I measure is 20 kHz (compare to 60 kHz with STM32L4) but the fusion is not behaving properly because of the lack of floating point sqrt and sin/tan functions I think. Anyway, this I2C issue ios solved.
There is one curious problem I am having. I was polling the data ready register bit of the AK8963C to test whether bnew data was available. Now that I am reading the next byte, which is the first data byte, it is clearing the data registers so I have had to abandong the data ready test to read the data. Oh well, can't have everything!
I have reposited working ESP32 Arduino sketches here: https://github.com/kriswiner/ESP32
I have sketches for the MPU9250+MS5637, MS5637, VEML6040 and will be adding more as I can test other sensors.
awesome! BTW you should not need to read two bytes anymore :) I found the reason why one byte was not working and I hope I fixed it. So you are welcome to try reading one byte again.
I tested the BNO055 and it works with the extra read byte also. I will download the latest and try without it next.
Tried the latest with reading no extra byte and this does not work. Reading the extra byte does work.
With the latest version: SSD1306 works LM75 works BMP180 works BME280 works only with reading an extra byte
"works" means that not only recognition but also communication works.
Great, it gets better and better. Until this version BMP180 did not work.
That looks good:
BMP180: 1028 hPa 21.90 C
BME280: 1027 hPa 21.60 C 56 rH
LM75: 19.00 C
BMP180: 1028 hPa 21.90 C
BME280: 1027 hPa 21.60 C 56 rH
LM75: 19.00 C
BMP180: 1028 hPa 21.90 C
BME280: 1027 hPa 21.60 C 56 rH
LM75: 19.00 C
I'm reading the documentation for the chips and I'm looking at the decoded data by my logic analyzer and all looks exactly as it should, so I do not get why the extra byte would be needed here and not on other platforms
I verfied the BME280 works without the extra byte. Not sure why the BNO055 and MPOU9250 might need it. I will check the MPU9250 again.
MPU working fine with one byte here
OK, MPU9250 working fine with one byte reads. BNO055 is the outlier, but maybe it is me so I will try again.
Oops. kriswiner is right. BME280 works without extra byte. Sorry, perhaps I lost the oveview which test I had activated.
now if we can get that BNO thing to work :)
OK, verified the BNO055 now works with no extra byte, not sure what I was doing before.
Thank you all for the help :)
Thank you for the arduino core
Tested my BME280 and works :) Now if I could only find out why the temperature is about 3 degrees C above the real temp :-/
If you have your BME280 anywhere near the ESP32 chip (or some other companion sensor) it will get warmer. Measure the current used in your circuit. If it is abobe 10 mA and the BME280 is close it will be warmer. Als, if you have the sensor nead the laptop fan exhaust it will see a warmer temperature. Lot's of reasons why it might show a higher temp.
@kriswiner Hmm, now that I've learnt how to plug the ESP32 and BME280 into a breadboard and how to connect them, any suggestions on guides about how I would use them in a "production" setup?
I assume that at least would imply a good separation of the sensor from the board to avoid such problems. Maybe other things like battery power, low battery detection, some sort of boxing...
ESP32 forum is a better place for this discussion...
I am trying to use DMP functionality of the mpu6050 with the nodemcu esp32s. It initializes fine but I have found that when the interrupt occurs to tell me to read the data available in the FIFO for the device, when using the i2cdevlib library to read the bytes I get 0 returned. I enabled the debug statements in the i2cdevlib library and was able to identify the issue as being the twowire call to read the bytes which returns 0. I am assuming that there is some other issue with the mpu6050 and the i2c bus as I have read on this and other forums. Hopefully me-no-dev might see this and throw some light on the issue. I am attaching the output of the debug statements so you can see what happens. The Wire.available call is returning 0 getfifobytesdmp.txt
The problem is with the i2cdevlib library, not the ESP32 i2c API. https://tools.usps.com/go/TrackConfirmAction.action?tLabels=EZ023693985US
On Fri, Aug 25, 2017 at 12:50 PM, ifrew notifications@github.com wrote:
I am trying to use DMP functionality of the mpu6050 with the nodemcu esp32s. It initializes fine but I have found that when the interrupt occurs to tell me to read the data available in the FIFO for the device, when using the i2cdevlib library to read the bytes I get 0 returned. I enabled the debug statements in the i2cdevlib library and was able to identify the issue as being the twowire call to read the bytes which returns 0. I am assuming that there is some other issue with the mpu6050 and the i2c bus as I have read on this and other forums. Hopefully me-no-dev might see this and throw some light on the issue. I am attaching the output of the debug statements so you can see what happens. The Wire.available call is returning 0 getfifobytesdmp.txt https://github.com/espressif/arduino-esp32/files/1252850/getfifobytesdmp.txt
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-325019343, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qk6WB9iPa1dgG7zXPIS52nlmhj0iks5sbyVqgaJpZM4LKA2r .
Your link is to a ups delivery kris :-) I guess you pasted the wrong link? I'm not so sure its the devlib library as the call that is causing the issue is Wire.available(); It returns 0 when there actually is data reported by the device. I think it is a MPU6050/i2c bus on esp32 issue as Me-No-Dev had found some issues with this in the past. The same code runs fine on ESP8266. testmpu6050esp32.txt
Yes, sorry about that, didn;t intend to link to anything.
I found Jeff's DMP code to be fussy, let's say, which is why I haven't run it in more than three years.The DMP can only do 6 DoF fusion anyway (I know you are using the MPU6050, but the same applies to the MPU9250, a superior device in a lot of ways). The ESP32 can do either 6 or 9 DoF fusion on the host with high rates, so this would be preferred for a lot of applications, and required fo 9DoF. There is code to do so here:
https://github.com/kriswiner/ESP32
On Fri, Aug 25, 2017 at 1:02 PM, ifrew notifications@github.com wrote:
Your link is to a ups delivery kris :-) I guess you pasted the wrong link? I'm not so sure its the devlib library as the call that is causing the issue is Wire.available(); It returns 0 when there actually is data reported by the device. I think it is a MPU6050/i2c bus on esp32 issue as Me-No-Dev had found some issues with this in the past. The same code runs fine on ESP8266. testmpu6050esp32.txt https://github.com/espressif/arduino-esp32/files/1252883/testmpu6050esp32.txt
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-325021775, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qoGynebBFkUPzlsnH4Hc695VFLu5ks5sbyg6gaJpZM4LKA2r .
I don't even see the I2C clock coming from pin 22. Am I missing something here.. I just see 3.3V on the oscilloscope
Do you have pullups on the I2C lines? What board are you using?
On Tue, Oct 17, 2017 at 11:13 AM, muktillc notifications@github.com wrote:
I don't even see the I2C clock coming from pin 22. Am I missing something here.. I just see 3.3V on the oscilloscope
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-337315970, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qnSHd5sty7oMkpE9v6Ha7gPJ8Ov8ks5stOz8gaJpZM4LKA2r .
Yes. I have 10k resistors attached. I am using DOIT ESP32 DevKit V1 board
pin 22 is default SCL and 21 is default SDA.
Do you have this in your arduino sketch?
Wire.begin(21, 22, 400000); //(SDA, SCL) (21,22) are default on ESP32, 400 kHz I2C clock
On Tue, Oct 17, 2017 at 11:43 AM, muktillc notifications@github.com wrote:
Yes. I have 10k resistors attached. I am using DOIT ESP32 DevKit V1 board
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-337329228, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qgaMZrKax2OLsvlYCFYKExeBAsNnks5stPVigaJpZM4LKA2r .
Yes. I do. I can send you the code in a few minutes. It is a simple code. I want to see something wiggle. But seeing nothing.
On Oct 17, 2017 2:49 PM, "Kris Winer" notifications@github.com wrote:
pin 22 is default SCL and 21 is default SDA.
Do you have this in your arduino sketch?
Wire.begin(21, 22, 400000); //(SDA, SCL) (21,22) are default on ESP32, 400 kHz I2C clock
On Tue, Oct 17, 2017 at 11:43 AM, muktillc notifications@github.com wrote:
Yes. I have 10k resistors attached. I am using DOIT ESP32 DevKit V1 board
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90# issuecomment-337329228, or mute the thread https://github.com/notifications/unsubscribe-auth/ AGY1qgaMZrKax2OLsvlYCFYKExeBAsNnks5stPVigaJpZM4LKA2r .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-337331125, or mute the thread https://github.com/notifications/unsubscribe-auth/Aetc8NCB48JCIk2bAJISVT2LNjKjMgi1ks5stPbDgaJpZM4LKA2r .
Don't send me any code, better ask at the ESP32 arduino forum.
On Tue, Oct 17, 2017 at 12:04 PM, muktillc notifications@github.com wrote:
Yes. I do. I can send you the code in a few minutes. It is a simple code. I want to see something wiggle. But seeing nothing.
On Oct 17, 2017 2:49 PM, "Kris Winer" notifications@github.com wrote:
pin 22 is default SCL and 21 is default SDA.
Do you have this in your arduino sketch?
Wire.begin(21, 22, 400000); //(SDA, SCL) (21,22) are default on ESP32, 400 kHz I2C clock
On Tue, Oct 17, 2017 at 11:43 AM, muktillc notifications@github.com wrote:
Yes. I have 10k resistors attached. I am using DOIT ESP32 DevKit V1 board
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90# issuecomment-337329228, or mute the thread https://github.com/notifications/unsubscribe-auth/ AGY1qgaMZrKax2OLsvlYCFYKExeBAsNnks5stPVigaJpZM4LKA2r .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90# issuecomment-337331125, or mute the thread https://github.com/notifications/unsubscribe-auth/ Aetc8NCB48JCIk2bAJISVT2LNjKjMgi1ks5stPbDgaJpZM4LKA2r .
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/90#issuecomment-337335861, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qkO-KtiDJqnSkU303dYsU9_T7elGks5stPpKgaJpZM4LKA2r .
void setup() { Wire.begin(21,22); Serial.begin(115200); Wire.setClock(400000); // choose 400 kHz I2C rate Serial.println("Start i2c-test"); }
void loop() { byte error;
// 0x20 is the address of a pcf8574 GPIO expander Serial.println("Try to contact 0x20"); uint8_t data = 0; // Wire.beginTransmission(0x3A); // error = Wire.endTransmission(); Wire.beginTransmission(0x3B); // Address of the accelerator Wire.write(0x0F); // Put WHO_AM_I address in Tx buffer Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive Wire.requestFrom(0x3B, 1); // Read two bytes from slave PROM address while (Wire.available()) { data = Wire.read(); } // Put read results in the Rx buffer Serial.print("Error code is:"); Serial.println(data);
delay(1000); }
I am just trying to use the above code which is a clip from your code. I don't seem to be having the clock working.
I can read the I2C addresses of the I2C sensors with pins 21/22 but I cannot read the WHO_AM_I byte. This works on the Teensy and STM32L4: