1

I am using ESP32 CAM for one project and I have a sensor that is I2C connected to pins 21 and 22 (default I2C). The sensor is working fine until I turn on the camera. The camera uses this pins (21,22) as input output, not for I2C communication. When I try to read the sensor data in the loop I can't reach the sensor. I want to check the sensor data mainly and if there is some indication from the sensor to turn on the camera.
How I can make this redefinition of the pins in the main loop?
I did try to declare the pins with Wire.begin(21,22, 100000); in the loop but is not working.

6
  • Wire.begin(21,22, 100000); declares the pins 21 and 22 ... you already said that they interfere with the camera – jsotola Apr 18 at 18:02
  • Unfortunately I can't change the pins. The board have modifications and this are the only free pins. I am looking more for a solution where I can switch between the camera and the sensor without restart. – Tencho Tenchev Apr 18 at 18:11
  • Well, if two different hardware devices are connected and want to input on both, the devices may or may not allow a software solution and you may need to add hardware logic to arbitrate them. Without knowing the details of your current HW design, it's hard to offer much specific advice. if the HE doesn't provide a way to arbitrate, it's poorly resigned. – lurker Apr 18 at 18:22
  • Posting a schematic,not a frizzy thing would go a long way in solving your problem. – Gil Apr 18 at 20:37
  • You didn't provide any code or schematic, so it is hard to provide a specific solution to your problem. One thing worth trying is to create a function getSensorReading() and only create the Wire instance Wire.begin() within the function so that it get out of scope at the end of the function. On your comment "I can't change the pins", well, ESP32 does provides two I2C ports, you could try Wire1.begin(14,15, 100000);. – hcheung Apr 19 at 1:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.