ESP32 I2C mapping
ESP32 I2C mapping
Hello guys,
I'm a beginner in Arduino environment.
I have a question on ESP32 thing from Sparkfun : https://learn.sparkfun.com/tutorials/es ... okup-guide
I want to use 2 sensors at the same time on this microcontroller. This board has 2 I2C buses but only one SCL and one SDA pin, I know it's possible to remap the pin of the board but I don't know how.
I use the Arduino IDE to upload codes in the ESP32.
How can I remap the pins ? Can I keep using the Arduino IDE after the remapping ?
Thanks !
I'm a beginner in Arduino environment.
I have a question on ESP32 thing from Sparkfun : https://learn.sparkfun.com/tutorials/es ... okup-guide
I want to use 2 sensors at the same time on this microcontroller. This board has 2 I2C buses but only one SCL and one SDA pin, I know it's possible to remap the pin of the board but I don't know how.
I use the Arduino IDE to upload codes in the ESP32.
How can I remap the pins ? Can I keep using the Arduino IDE after the remapping ?
Thanks !
Re: ESP32 I2C mapping
Hi guys,
Does anyone have a solution to my problem ?
I tried to install esp-idf, not using Arduino IDE, and launched the I2C example (from here : https://github.com/espressif/esp-idf/tr ... herals/i2c), but it failed. The two new ports didn't be recognized.
Thanks,
Does anyone have a solution to my problem ?
I tried to install esp-idf, not using Arduino IDE, and launched the I2C example (from here : https://github.com/espressif/esp-idf/tr ... herals/i2c), but it failed. The two new ports didn't be recognized.
Thanks,
- ESP_krzychb
- Posts: 400
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: ESP32 I2C mapping
Hi Durassel,
I do not know what sensor you are using, but maybe you can change the I2C address of one of them and use both on the same I2C bus.
To remap the I2C pins to other than default GPIO22/21, enter the pin numbers when calling sensor.begin()Durassel wrote:I know it's possible to remap the pin of the board but I don't know how.
I do not know what sensor you are using, but maybe you can change the I2C address of one of them and use both on the same I2C bus.
Re: ESP32 I2C mapping
Hi krzychb,
Thank you for your response.
I use a temperature sensor : https://www.sparkfun.com/products/13314 and an accelerometer : https://www.sparkfun.com/products/12756.
I want to connect these 2 sensors, in the same time, to the microcontroller : https://www.sparkfun.com/products/13907.
Is it possible to use only one I2C bus with 2 sensors ? If yes, how to distinguish the data received on the same port ?
Thank you for your response.
I use a temperature sensor : https://www.sparkfun.com/products/13314 and an accelerometer : https://www.sparkfun.com/products/12756.
I want to connect these 2 sensors, in the same time, to the microcontroller : https://www.sparkfun.com/products/13907.
Is it possible to use only one I2C bus with 2 sensors ? If yes, how to distinguish the data received on the same port ?
-
- Posts: 9715
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32 I2C mapping
Can I suggest you first read up on I2C to get a grasp on what you're playing with? Not to try to demean you or anything, but I feel that if you're going to use this, reading up on the basics first will answer this question, plus give you the background information to solve a lot of issues you may run into in the future. Since you seem to like Sparkfun, why not look at their page on I2C?
Re: ESP32 I2C mapping
Im having the same problem. I want to use two featherwing joys with a huzzah32. I read up on the hardware part so i know what its doing there.
I cant find the programming part or where the pins are named. I also dont see any thing called sensor.begin in the wire.h library.
Im new to I2c and need a working example to work with or something
I cant find the programming part or where the pins are named. I also dont see any thing called sensor.begin in the wire.h library.
Im new to I2c and need a working example to work with or something
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
Re: ESP32 I2C mapping
ok heres the example that adafruit put out for the feather wing joy.
the seesaw library can be found here....
https://github.com/adafruit/Adafruit_Seesaw
and my board can be found here......
https://www.adafruit.com/product/3405
the example above is only for one featherwing joy but I will be using two. but two on the same bus can take up time, so I want to use two sets of i2c pins on my huzzah. SDA and SCL are set on 22 and 23. Where would these pin defines be found in the Arduino esp library.
the programs begin asks for the device address and not the pin and frequency so I need to know where to define the second set of pins and would I do a double .begin to use both i2c devices?
The huzzah32 has its sda and scl set to this.....
so if I want to use a second set of i2c do simply say...
static const uint8_t SDA2 = pin;
static const uint8_t SCL2 = pin;
Code: Select all
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
#define BUTTON_RIGHT 6
#define BUTTON_DOWN 7
#define BUTTON_LEFT 9
#define BUTTON_UP 10
#define BUTTON_SEL 14
uint32_t button_mask = (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
(1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_SEL);
#if defined(ESP8266)
#define IRQ_PIN 2
#elif defined(ESP32)
#define IRQ_PIN 14
#elif defined(NRF52)
#define IRQ_PIN 27
#elif defined(TEENSYDUINO)
#define IRQ_PIN 8
#elif defined(ARDUINO_ARCH_WICED)
#define IRQ_PIN PC5
#else
#define IRQ_PIN 5
#endif
void setup() {
Serial.begin(115200);
while(!Serial);
if(!ss.begin(0x49)){
Serial.println("ERROR!");
while(1);
}
else{
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss.getVersion(), HEX);
}
ss.pinModeBulk(button_mask, INPUT_PULLUP);
ss.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN, INPUT);
}
int last_x = 0, last_y = 0;
void loop() {
int x = ss.analogRead(2);
int y = ss.analogRead(3);
if ( (abs(x - last_x) > 3) || (abs(y - last_y) > 3)) {
Serial.print(x); Serial.print(", "); Serial.println(y);
last_x = x;
last_y = y;
}
if(!digitalRead(IRQ_PIN)){
uint32_t buttons = ss.digitalReadBulk(button_mask);
//Serial.println(buttons, BIN);
if (! (buttons & (1 << BUTTON_RIGHT))) {
Serial.println("Button A pressed");
}
if (! (buttons & (1 << BUTTON_DOWN))) {
Serial.println("Button B pressed");
}
if (! (buttons & (1 << BUTTON_LEFT))) {
Serial.println("Button Y pressed");
}
if (! (buttons & (1 << BUTTON_UP))) {
Serial.println("Button x pressed");
}
if (! (buttons & (1 << BUTTON_SEL))) {
Serial.println("Button SEL pressed");
}
}
delay(10);
}
https://github.com/adafruit/Adafruit_Seesaw
and my board can be found here......
https://www.adafruit.com/product/3405
the example above is only for one featherwing joy but I will be using two. but two on the same bus can take up time, so I want to use two sets of i2c pins on my huzzah. SDA and SCL are set on 22 and 23. Where would these pin defines be found in the Arduino esp library.
the programs begin asks for the device address and not the pin and frequency so I need to know where to define the second set of pins and would I do a double .begin to use both i2c devices?
The huzzah32 has its sda and scl set to this.....
Code: Select all
static const uint8_t TX = 17;
static const uint8_t RX = 16;
static const uint8_t SDA = 23;
static const uint8_t SCL = 22;
static const uint8_t SS = 2;
static const uint8_t MOSI = 18;
static const uint8_t MISO = 19;
static const uint8_t SCK = 5;
so if I want to use a second set of i2c do simply say...
static const uint8_t SDA2 = pin;
static const uint8_t SCL2 = pin;
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
Re: ESP32 I2C mapping
The adafruit driver does not support multiple i2c buses so i guess you would have to keep separate scope and override global Wire variable with local for each bus.
Re: ESP32 I2C mapping
it says on this page that it has 2 i2c and that only one is configured by default....
https://learn.adafruit.com/adafruit-huz ... r/overview
its in the features list
both i2c devices have resistors pre installed
the pinouts page describes the gpio capabilities if that will help
https://learn.adafruit.com/adafruit-huz ... er/pinouts
https://learn.adafruit.com/adafruit-huz ... r/overview
its in the features list
both i2c devices have resistors pre installed
the pinouts page describes the gpio capabilities if that will help
https://learn.adafruit.com/adafruit-huz ... er/pinouts
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
Who is online
Users browsing this forum: No registered users and 127 guests