element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
element14 presents
  • Challenges & Projects
  • More
element14 presents
element14 presents Forum esp32 C3 with mpu6050
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join element14 presents to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 10 replies
  • Answers 2 answers
  • Subscribers 106 subscribers
  • Views 4155 views
  • Users 0 members are here
  • projects
  • mpu6050
  • Embedded Systems
  • ESP32C3
Related

esp32 C3 with mpu6050

alen10
alen10 over 1 year ago

Hi , i saw this video : www.youtube.com/watch . I want to know if i could use esp32 c3 instead of what you are using in the video . In this case , can you specify the pin diagram in order to connect to mpu6050 ?.

Below is the image of my connection (esp32 C3) with MPU6050 

Code is :

#include <MPU6050_light.h>
MPU6050 mpu(Wire);
unsigned long timer = 0;
#include <BleMouse.h>

BleMouse bleMouse;

#define btnL 2
#define btnR 1
#define btnM 3


#include <Wire.h>
#define SDA 9
#define SCL 10

#define AD0 11
#define INT 12
void setup() {

pinMode(btnR,INPUT);
pinMode(btnL,INPUT);
pinMode(btnM,INPUT);

pinMode(INT, INPUT); //int goes high when activity is detected(wakeup?)
pinMode(AD0, OUTPUT);
digitalWrite(AD0, LOW);//sets I2C adress
delay(50);
Serial.begin(115200);
Wire.begin(SDA,SCL);

Serial.println("Starting BLE work!");
bleMouse.begin();
byte status = mpu.begin();
Serial.print(F("MPU6050 status: "));
Serial.println(status);
while(status!=0){ } // stop everything if could not connect to MPU6050

Serial.println(F("Calculating offsets, do not move MPU6050"));
delay(2000);
// mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
mpu.calcOffsets(); // gyro and accelero
Serial.println("Done!\n");
}

void loop() {
if(bleMouse.isConnected()) {
clicking();
mpu.update();
int x = map(mpu.getAngleX(),-90,90,10,-10);
int y = map(mpu.getAngleY(),-90,90,-10,10);
int z = map(mpu.getAngleZ(),-90,90,-10,10);

bleMouse.move(x,y);


if((millis()-timer)>10){ // print data every 10ms
Serial.print("X : ");
Serial.print(mpu.getAngleX());
Serial.print(x);
Serial.print("\tY : ");
Serial.print(mpu.getAngleY());
Serial.print(y);
Serial.print("\tZ : ");
Serial.println(mpu.getAngleZ());
Serial.print(z);

timer = millis();
}
}


}
void clicking(){

bool Lclick = digitalRead(btnL);
bool Mclick = digitalRead(btnM);
bool Rclick = digitalRead(btnR);
if (Lclick == 0){
bleMouse.click(MOUSE_LEFT);
}

if (Rclick == 0){
bleMouse.click(MOUSE_RIGHT);
}


if (Mclick == 0){
bleMouse.click(MOUSE_MIDDLE);
}

}



image                                     image

  • Sign in to reply
  • Cancel

Top Replies

  • cstanton
    cstanton over 1 year ago in reply to alen10 +1 suggested
    alen10 said: esp32 c3 mini development kit .Even shared the picture of it Hey alen10 , Looks like you have one of these? https://docs.espressif.com/projects/esp-idf/en/stable/esp32c3/hw-reference/esp32c3…
Parents
  • mayermakes
    0 mayermakes over 1 year ago

    there is no requirement to use the s3 like in the video it will also work with a C3, you only need to specify and connect the right pins for i2C.
    so either use the pinmux to define which pins are used for SDA&SCL by the wire library or look up the default i2c pins for your particular board(which appears to be some random clone board so that might be not the simplest to find out.) and connect to these.
    also check if the breakout board you are using has the pullop resistors for i2c fitted, if not you nalso need to add them in your config/physically.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mayermakes
    0 mayermakes over 1 year ago in reply to mayermakes
    mayermakes said:
    so either use the pinmux to define which pins are used for SDA&SCL by the wire library
    Wire.begin(SDA, SCL);


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • mayermakes
    0 mayermakes over 1 year ago in reply to mayermakes
    mayermakes said:
    so either use the pinmux to define which pins are used for SDA&SCL by the wire library
    Wire.begin(SDA, SCL);


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • alen10
    0 alen10 over 1 year ago in reply to mayermakes

    Hi , The SDA and SCL connection had been solved .

    I got the virtual mouse working with my smartphone .

    I am doing a  project . The Project is based on Finger module that has esp32 C3 and mpu6050 attached to my Index Finger  .In the prototype , I do not need button to click the screen . It will be done using my finger movement along the Z direction .I can  move the mouse cursor  along (X-Y direction )  and scrolling too with my finger module attached to my finger  . 

    I will attach my code , Can you tell me if the code is correct or not ? 

    Secondly i used  "int x = map(mpu.getAngleX(),-90,90,0,255)" instead of "int x = map(mpu.getAngleX(),-90,90,-10,10)" , Can you tell me which one is good for precise cursor control and without timelag . If timelag shows up , how can i avoid it by either using hardware /Software ?

    #include <MPU6050_light.h>
    MPU6050 mpu(Wire);
    unsigned long timer = 0;
    #include <BleMouse.h>
    #define MPU_ADDR 0x68 
     
    BleMouse bleMouse;
    
    
    int prevX = 0, prevY = 0, prevZ = 0; // Previous sensor readings for movement detection
    // Thresholds for click and scroll detection (adjust as needed)
    #define CLICK_THRESHOLD 1000
    
    
    #include <Wire.h>
    int SDA_pin= 6;
    int Scl_pin= 7;
    
    //#define AD0 11 
    //#define INT 12
    void setup() {
      //pinMode(INT, INPUT); //int goes high when activity is detected(wakeup?)
      //pinMode(AD0, OUTPUT);
      //digitalWrite(AD0, LOW);//sets I2C adress
      delay(50);
      Serial.begin(115200);
      Wire.setPins(SDA_pin ,Scl_pin);
        pinMode(SDA_pin,INPUT_PULLUP );
     
       pinMode(Scl_pin,INPUT_PULLUP );
      Wire.begin();
    
      Serial.println("Starting BLE work!");
      bleMouse.begin();
      byte status = mpu.begin();
      Serial.print(F("MPU6050 status: "));
      Serial.println(status);
      while(status!=0){ } // stop everything if could not connect to MPU6050
      
      Serial.println(F("Calculating offsets, do not move MPU6050"));
      delay(2000);
      // mpu.upsideDownMounting = true; // uncomment this line if the MPU6050 is mounted upside-down
      mpu.calcOffsets(); // gyro and accelero
      Serial.println("Done!\n");
      }
      
    
    void loop() {
      if(bleMouse.isConnected()) {
        Wire.write(0x3B); 
        Wire.write(0x43); 
     
      mpu.update();
      int x = map(mpu.getAngleX(),-90,90,0,255);
      int y = map(mpu.getAngleY(),-90,90,0,255);
      int z =abs(mpu.getAngleZ());
      prevX = x;
      prevY =y;
      
       bleMouse.move(x,y);
        // Click detection based on Z-axis acceleration change
        if (z > CLICK_THRESHOLD && prevZ < CLICK_THRESHOLD) {
         bleMouse.click();
          delay(10); // Debounce (optional)
         
        }
        prevZ = z;
        // Scrolling 
             Serial.println("Scroll up");
             unsigned long startTime;
      startTime = millis();
        while(millis()<startTime+2000) {
          bleMouse.move(0,0,1);
          delay(100);
        }
        delay(500);
    
        Serial.println("Scroll down");
        startTime = millis();
        while(millis()<startTime+2000) {
          bleMouse.move(0,0,-1);
          delay(100);
        }
        delay(500);
    
        Serial.println("Scroll left");
        startTime = millis();
        while(millis()<startTime+2000) {
          bleMouse.move(0,0,0,-1);
          delay(100);
        }
        delay(500);
    
        Serial.println("Scroll right");
        startTime = millis();
        while(millis()<startTime+2000) {
          bleMouse.move(0,0,0,1);
          delay(100);
        }
        delay(500);
    
    
      
      
      if((millis()-timer)>10){ // print data every 10ms
      Serial.print("X : ");
      Serial.print(mpu.getAngleX());
      Serial.print(x);
      Serial.print("\tY : ");
      Serial.print(mpu.getAngleY());
      Serial.print(y);
      Serial.print("\tZ : ");
      Serial.println(mpu.getAngleZ());
      Serial.print(z);
      
      timer = millis();  
      }
      }}
    
    
    
    
    
    
    
      
    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube