Let's get the accelerometer working on the MK4
 
Notifiche
Cancella tutti

Let's get the accelerometer working on the MK4  

  RSS
MCDELTAT
(@mcdeltat)
Utenti
Let's get the accelerometer working on the MK4

I'm working on a project to get the accelerometer working on the MK4. I have a background in electronics and wanted to just drop the good news that it was working, but alas, we all need a little help. There's a lot of info, so hopefully this makes sense.

The goal: To get the M959 command to run on my printer.

What I'm currently stuck on: The pinout of the MK4 ACCEL port, as it relates to the breakout board. Physically, I think I have everything I need right here on my desk.

So what's the M959 command? My best guess is that it's the command baked into the firmware for Buddy boards that tunes the IS. I.E. you run it, it does a routine, and then spits out some numbers for you to put into IS. It's documented here alongside M959, which is to excite harmonic vibrations to rune IS. https://help.prusa3d.com/article/buddy-firmware-specific-g-code-commands_633112

Digging through the source for the current driver, it seems like they compile in support for the accelerometer, and are just assuming that no one has one to wire up. For example, in `lib/Marlin/Marlin/src/gcode/gcode.h` on line 997, the definition for M959 is behind the `#if ENABLED(ACCELEROMETER)` check. In `ProjectOptions.cmake` we see `set(BOARDS_WITH_ACCELEROMETER "XBUDDY" "DWARF")`, meaning MK 3.9, MK4, Mini, and XL and supported. This is used later on to set `HAS_ACCELEROMETER`. That variable is then used in `include/buddy/main.hpp` to import the library `#include "SparkFunLIS2DH.h"`

That board in question is an off-the-shelf accelerometer board found here: https://www.sparkfun.com/products/retired/15760 They no longer sell it, but it's a simple board. I managed to get an official one elsewhere, and I'm confident we can clone it later. The chip and board support both I2C and SPI communication, and that's where it starts getting funky.

Prusa was actually really nice and fully documented what each of the pins on the unused xBuddy ports is here: https://help.prusa3d.com/article/accessory-connectors-mk4_622345

From the source code and that list, it really seems like things are wired up for SPI. We see CS, SCL, SDI, SDO, etc. However, looking at the schematics for the board, they've tied 2/6 of those pins to 3.3V, suggesting that I shouldn't wire them. Schematics here: https://cdn.sparkfun.com/assets/a/c/e/2/d/Schematic.pdf Pin 2 of the LIS2DH is CS, but it's tied to 3.3V. The pin 3 SDO is also tied to 3.3V and a jumper. When used in I2C mode, this changes the address. This leaves pin 4 of the chip (SDA/SDI/SDO) all tied to SDA on the silkscreen.

So from all of that, I have these as what I think are the final pinouts, going from MK4 Board Pins to ACCELL Breakout Board Pins.

* Pin 1 (CS) -> DISCONNECTED (On board, CS from Chip is tied to 3.3V)
* Pin 2 (SCL) -> SCL
* Pin 3 (SDI) -> SDA
* Pin 4 (SDO) -> DISCONNECTED (On board, pin 3 from Chip (SDO/SA0) is tied to 3.3V)
* Pin 5 (3V3) -> 3V3
* Pin 6 (GND) -> GND

Does that sound right? Does anyone have other evidence I don't have? Does anyone have a good idea of how to mount the thing to the printer? At the moment I was planning on just using sticky velcro ha.

Thanks for your help.

Postato : 04/02/2024 11:59 pm
Oregun, Arduino, Gummibjorn e 2 persone hanno apprezzato
gus67
(@gus67)
Utenti
RE:

Kudos for the work so far 👍

The accelerometer is definitely way up on my "want it, need it, make it happen..." list, since as soon as your printer is sliding away from stock the "one size fits all" approach just doesn't cut it anymore. Althou it works surprisingly well for the stock models 🤔 

I'd like to see where this is going 🙂 

Questo post è stato modificato 10 months fa da gus67
Postato : 08/02/2024 12:30 pm
Joshua Giacone
(@joshua-giacone)
Eminent Member
RE: Let's get the accelerometer working on the MK4

Keep us posted on this would love to help try it out

Postato : 08/02/2024 5:10 pm
kenb
 kenb
(@kenb-2)
Active Member
RE: Let's get the accelerometer working on the MK4

perhaps this will help: https://www.st.com/content/ccc/resource/technical/document/datasheet/12/c0/5c/36/b9/58/46/f2/DM00091513.pdf/files/DM00091513.pdf/jcr:content/translations/en.DM00091513.pdf which is the data sheet for the accelerometer.  CS is used to command the device to use either i2c (pulled high), or spi when pulled low. CS is used with spi devices as chip select—pull it low to talk to a specific device.  so this makes sense—keep reading.

i might be misunderstanding what you’re asking, but i think the data sheet should answer your questions.  if the sparkfun breakout has CS pulled high, then they have it set to i2c only—you’ll need to change that, or find a more suitable breakout.

cool project!  good luck with it!

kb

Postato : 18/02/2024 1:07 am
MCDELTAT
(@mcdeltat)
Utenti
Topic starter answered:
RE: Let's get the accelerometer working on the MK4
Posted by: @kenb-2

perhaps this will help: https://www.st.com/content/ccc/resource/technical/document/datasheet/12/c0/5c/36/b9/58/46/f2/DM00091513.pdf/files/DM00091513.pdf/jcr:content/translations/en.DM00091513.pdf which is the data sheet for the accelerometer.  CS is used to command the device to use either i2c (pulled high), or spi when pulled low. CS is used with spi devices as chip select—pull it low to talk to a specific device.  so this makes sense—keep reading.

i might be misunderstanding what you’re asking, but i think the data sheet should answer your questions.  if the sparkfun breakout has CS pulled high, then they have it set to i2c only—you’ll need to change that, or find a more suitable breakout.

cool project!  good luck with it!

kb

Thanks for pointing that out. I cross posted this to Reddit and had more initial success there, but haven't got any updates once I posted mine. I wired up the accelerometer as per my first post and it doesn't work. The good news is that it does throw the error "Recv: Error:accelerometer communication", which if you look at the code, occurs in exactly one location and it is behind a "#if ENABLED(ACCELEROMETER)" definition block. So good news: Prusa compiles in support for the board to the production firmware.

I purchased a cheap logic analyzer and grabbed the data on the port. If you want to take a look at that, I put them in a zip file here https://file.io/Wog28tKrt5oi  

So my current project is two-fold. I'm re-reading the code to see if it is the SparkFun board. Of interest, it seems that they probably have the chip select broken out because it sets the pin low to get into SPI mode. I could cut the trace on the board and do a bodge wire to ground, but I kind of want to keep the PCB intact.

So I ordered a few remaining items to do reflow work, and I plan on designing a quick board that uses the same Molex QuickMate connector as the MK4 board. That way someone can just buy a cable assembly from somewhere like Digikey and go straight from board to breakout. I'll hopefully have all that sorted in ~2 weeks.

 

Postato : 25/02/2024 8:02 pm
konfuzed, me, gus67 e 1 persone hanno apprezzato
Dennis
(@dennis)
Active Member
RE: Let's get the accelerometer working on the MK4

Hello,

I‘m very interested in this topic as well. How is it going so far? Did you receive your parts yet?

Postato : 21/05/2024 7:40 am
Juan Puchol
(@juan-puchol)
Active Member
RE:

Hello,

I have done my own cable for adafruit accelerometer, but it doesn't work. I have checked the cable and  it is fine, but i get "Recv: Error:accelerometer communication" with M959. My xBuddy board is 0.3.7 version.

Questo post è stato modificato 6 months fa 2 tempo da Juan Puchol
Postato : 22/05/2024 6:05 pm
MCDELTAT
(@mcdeltat)
Utenti
Topic starter answered:
RE: Let's get the accelerometer working on the MK4

That’s a very nice looking cable. Better than the one I made. Would love to know the tools you used.

Unfortunately, as discovered by a few other members on the Prusa (unofficial) discord, it does not seem to be working on the 0.3.7/0.4.4 boards. Only works on 0.2.7 boards, which mine is.

I’ll be sure to update the GitHub today with additional warnings.

I’m a little busy and have to put the project to the side for the next few weeks but I plan on buying a new xBuddy board and finding out why it isn’t working. From what we do know so far, I think the pin definitions in the code are explicitly for the 0.2.7 boards and they never updated it for hardware changes they did on the future boards. So hopefully we can push an MR to the code to get it working for everyone. Good news is you’ll be able to use it immediately if they ever do get that resolved.

Postato : 22/05/2024 6:38 pm
Juan Puchol hanno apprezzato
MCDELTAT
(@mcdeltat)
Utenti
Topic starter answered:
RE:

Actually, I spoke too soon. Someone has an idea of why things aren't working on 0.3.7 boards. https://github.com/MCDELTAT/MK4_Accelerometer/issues/1 If you'd like to try, it sounds like this person got it working by soldering a 2K2 resistor between GND and CS on the Adafruit board.

Postato : 23/05/2024 4:54 am
Juan Puchol hanno apprezzato
Juan Puchol
(@juan-puchol)
Active Member
RE: Let's get the accelerometer working on the MK4

Don't worry, I kewn that on version 0.3.7 was not working, but I would like to try. I have crimped myself the cable, I have used this tools:

Postato : 23/05/2024 7:52 am
Juan Puchol
(@juan-puchol)
Active Member
RE: Let's get the accelerometer working on the MK4

I was trying something similar, thanks for sharing

Postato : 23/05/2024 4:18 pm
Juan Puchol
(@juan-puchol)
Active Member
RE: Let's get the accelerometer working on the MK4

 

Posted by: @mcdeltat

Actually, I spoke too soon. Someone has an idea of why things aren't working on 0.3.7 boards. https://github.com/MCDELTAT/MK4_Accelerometer/issues/1 If you'd like to try, it sounds like this person got it working by soldering a 2K2 resistor between GND and CS on the Adafruit board.

 

I was trying something similar, thanks for sharing

Postato : 23/05/2024 5:32 pm
Juan Puchol
(@juan-puchol)
Active Member
RE: Let's get the accelerometer working on the MK4

Hello,

M959 is working on my Enhanced MK4. I didn't have 2k2 resistor so I have done a divider circuit (with two equal resistors serial soldier, in my case two 1K resistors) one end goes to GND the other end goes to CS cable pin, and the resistors join goes to CS Adafruit pin). In this way you get 1.53v instead 3.3. I have done also my Adafruit mount. Now testing my Input Shaper best values

Postato : 24/05/2024 2:44 pm
Bichlesi
(@bichlesi)
Utenti
RE: Let's get the accelerometer working on the MK4

I tried this with a LIS3DH module from Sparkfun:
https://www.sparkfun.com/products/13963

I had to add a 2.2k resistor from CS to GND to make it work with my xBuddy v0.3.7  board.
With this modification I can now report that it's working perfectly fine.

Here's my mounting solution and some pictures of the modified sensor board:
https://www.printables.com/model/897693-accelerometer-mount-for-sparkfun-lis3dh-breakout-b

Postato : 31/05/2024 2:52 pm
Juan Puchol e Zappes hanno apprezzato
3D Printer
(@3d-printer-2)
Utenti
RE: Let's get the accelerometer working on the MK4

Hi

Posted by: @juan-puchol

Hello,

M959 is working on my Enhanced MK4. I didn't have 2k2 resistor so I have done a divider circuit (with two equal resistors serial soldier, in my case two 1K resistors) one end goes to GND the other end goes to CS cable pin, and the resistors join goes to CS Adafruit pin). In this way you get 1.53v instead 3.3. I have done also my Adafruit mount. Now testing my Input Shaper best values

Hi, which accelerometer chip did you used in this mod? I was wondering if it's possible to use a ADXL345 chip instead.

Postato : 21/11/2024 8:34 pm
Condividi: