I have a CNC Shield on top of an Arduino Uno (GRBL pinout) that controls 2 stepper motors through a4988 drivers and it is working like a charm.

Now I want to add an accelerometer to it. From my humble research, the MPU-6050 seems a good pick.

If I purchase stacking headers to lift the CNC shield, can I connect the accelerometer to the unused/reserved A4 and A5 from the Arduino, but power it using CNC's Ground and 5V pins?

I'm open to other approaches if I'm not doing it the proper way.

  • 1
    Minduca, some feedback? you know how SE sites work
    – Juraj
    Oct 25, 2018 at 19:41
  • Sorry for the delay. I found on the CNC shield v3 the same SCL and SDA pins that you mentioned for the Arduino. Right now I'm gonna test the accelerometer connected directly to it and I comme back later! Thanks ;)
    – Minduca
    Oct 27, 2018 at 19:49

2 Answers 2


MPU6050 can use only I2C. Those are pins A4 and A5 on an Uno. 5V and ground are 5v and ground, no matter from which pin

  • Thanks for the info. Altough pins A4 and A5 are available to I2C connection at the arduino, the CNC shield expose these very same SCL and SDA pins and it's simpler to just use them. Same for ground and VCC.
    – Minduca
    Oct 27, 2018 at 23:03
  • of course, those are the same pins
    – Juraj
    Oct 28, 2018 at 5:48

This may be a bit harder to implement than it might seem. The grbl code uses all but one pin, so you would have to change that in the library. So I checked out the the code for the shield, and under the cpu_map tab it defines the pins. I would first try setting the unused pins to arbitrary values to enable the pins previously used by the code. For instance, if you are not using the Zed axis, try changing
#define Z_STEP_BIT 4 // Uno Digital Pin 4

to something like

`#define Z_STEP_BIT      0`. 

This should clear up pin 4 to be setup as a input/output in your main sketch. Another pin definition associated with the Zed axis is

`#define Z_DIRECTION_BIT   7  // Uno Digital Pin 7` 

Clear that one out, and you should be able to use pin 7 as an I/O.

I haven't personally tested the code so give it a try. Also just a heads up will probably run into errors while trying to use the MPU6050 library as well as grbl library, the grbl library is a LOT of code (I didn't spend enough time trying to compile so I don't know how much space it's actually using, but it's a lot). You might also run into timer errors as both libraries most likely reconfigure timers to work with each.

I hope this was a bit helpful!

enter image description here


I realized I didn't specify how to exactly free up A5. It has been assigned to the probe in the cpu_map.

enter image description here

  • MPU6050 uses I2C on pins A4 and A5
    – Juraj
    Oct 23, 2018 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.