Yep, admittedly, the behavior of ACCELEROMETER_MEASURE might be a bit confusing. The first invocation for the chip starts the measurements, and the second - finishes it and writes the data, at which point you can provide a filename. It does not continuously write the data. But it is a good idea to give some time at step 8 to let it write all the data before the restart. 10 seconds should be more than enough.
@koconnor and @dmbutyugin your analysis was fully correct: It depends on the orientation and zero-crossing
When the board has separate 3V3 and Vin inputs it is better (almost mandatory) to use the Vin
When having to use RPi Picos 3V3 output (because the board has level shifter) it is beneficial to toggle GPIO23 high
When using the RPi Pico with a board that has voltage regulator but no level shifter it is preferable to use Vbus Pin 40 (5V) → See first measurement campaign No 7 vs. No 16
Following two histograms show the distribution of samples, i.e. number of samples within a bin of 200 units, for above tests No 1 and No 2, i.e. 3V3 input vs. Vin on an Adafruit board
When using the adafruit boards with the Vin pins - did you apply 5V to Vin or 3.3V to Vin? If it was 5V, I’m curious what would happen if you applied 3.3V to Vin. If it was 3.3V, I’d be curious what would happen if 3.3V was applied to both the “Vin” and “3.3” pins.
FWIW, I’d recommend never putting 5V anywhere near these boards if at all possible. Unless I’m misunderstanding your results, the improvement seems to be minor. It’s easy to damage the adxl345 and it’s easy to damage the rpi (and/or micro-controller). Seems simpler to recommend “always use 3V when you can”. YMMV.
The tests No 9 and 10 apply 5V to Vin. This only works with the Chinese board as it has no level shifter. The Adafruit has level shifter, so this would output 5V on SDA and SCL.
Test No 9 corresponds to No 4 and 8 with 3.3V
Test No 10 corresponds to No 13 with 3.3V
See test No 3 and 7. Depending on GPIO23 the results are quite bad (GPIO low) or even the best when GPIO23 is high.
I’m curious: Did you expect such a result? How did you come up with this idea?
To have a complete overview, I also added some results with the tilt Chinese board, which where missing in the table above (previous post). The tests are No 4, 5, 9, 10 and 13.
In fact the tests with 5V (9, 10) seem to provide slightly better results, but this may also be well below the error margin and it might not be worth the risk.
A note, I forgot to mention all along: In my Excel a comma is used as decimal separation. Sorry for this.
I had no real expectations one way or another. The adafruit board lists 3v3 as an output, and as you’ve shown, feeding power into it causes bad results. So, power needs to be fed via Vin. However, using Vin will cause a voltage drop that I wasn’t sure how the level shifters would handle.
In summary though, it seems:
Always use “Vin” and not “3V3” on the adafruit boards.
The 3.3V source on the rpi pico is not powerful enough to run the adxl345. Either set gpio23 high or use 5V (if absolutely sure the adxl345 board has a regulator and does not have level shifters).
From the tests it would seem that it might be preferable to power adafruit boards via VIN pin, as this seems to have no downsides and improves the performance in some other cases (like when powering from pico board). Maybe we should update the documentation to reflect that. Separately, I’d like to write some info about connecting adxl345/343 to the MCU boards, but this is a complicated topic due to 5V tolerances / level shifting, and so it’ll take some time.
FWIW, I’m not sure that 3.3V source on pico isn’t powerful enough: setting gpio23 high causes the power source to go into high-performance mode rather than power saving mode. Note that if the power draw is high, it goes into high-performance mode regardless of the value of that pin. This suggests that adxl345 does not draw enough current from pico, so its power source stays in the power saving mode by default. And this mode is known to cause more ripples on the 3.3V line, which apparently affects adxl345 readings.
Separately, I have a pico, and I will run some experiments with it and the accelerometer to confirm these findings when I have some time (probably this weekend). I’d like to confirm that this is a common trend and not an issue of a specific pico (or a specific batch of picos).
OK, I’ve run some tests with an Adafruit Pico and a couple of adxl343 (adxl0 and adxl1) I had lying around. Note that I purchased them together, so they were probably from the same batch.
For the reference, the powerchain looks like 24V PSU → 5V buck converter (calibrated with a multimeter) → RPi3 → USB cable → RPi Pico → 3.3V → ADXL343. I assembled the test kit on the breadboard. The relevant configuration:
Note that adxl343s were always connected to the 3v3 pin on the picos, as they have logic level shifter and it is not safe to connect them to 5V (and generally doesn’t make sense for this test).
For some reference, here’s the noise of a chinese adxl345 connected to the RPi3 as suggested by the official Klipper documentation (via VCC pin): 18.360854 (x), 20.781346 (y), 22.685117 (z)
So, it seems it is definitely beneficial to put a pico’s power source in the pwm mode prior to running the measurements. Connecting the accelerometer via VIN pin is also beneficial, though not as critical (even with a 3v3 pin, the noise is comparable to a board connected to RPi3 via VCC, at lest in my setup). But it likely won’t hurt. Though in the previous tests done by Sineos connecting the accelerometer to the RPi3 via VIN pin there were no statistically significant improvements vs using 3v3 pin.
X-Axis: Range between 1200 and 8200, divided in bins of 100
Y-Axis: Number of measurements that fall within a specific bin
The spread of the 3V3 is smaller (less scatter), whereas VIN is more centered (see scale of the Y-Axis) → Maybe this explains the low difference in terms of standard deviation
Edit:
To highlight another small result from this measurement:
Average samples/s for Adafruit1 across 64k samples: 3026 (VIN) / 3061.5 (3V3)
Average samples/s for Adafruit2 across 64k samples: 3213.7 (VIN) / 3214.1 (3V3)
I noticed such differences in my previous measurements as well
If you look at the data, it seems that there happens to be a slightly different noise on different axes. E.g. adafruit1_Vin shows larger StaDev on X, and adafruit1_3V3 - on Z. There is a somewhat similar pattern for adafruit2 sensor. So that’s why I say that these results to not demonstrate statistically significant advantage of one connection over the other one. On the chart, you show X axis only, but if you plotted also the Z axis for adafruit1, or Y for adafruit2, you’d likely see the opposite effect.
The fact that adafruit2 produces more samples/s than adafruit1 is certainly odd. What you could do is run Klipper data logging with one sensor connected, e.g.
until it disconnects, then connect the other sensor, and repeat that command with adafruit2 param, and then upload the generated gz files for further analysis. Unfortunately, the mainline Klipper code no longer reports ‘overflows’ and ‘errors’ anywhere in the logs anymore, so that would be the only way to obtain that data. Might be at the end of the day that somehow the adxl345 internal clocks are not very precise, and not a problem of transmissions.
Different characteristics, but seems repeatable for y and z.
Will try this.
I agree. If you look at the very first post of this story, the differences seem below error margin.
Nevertheless, when running this, I’d like to do it in the best possible configuration / accuracy.
I think, we agree on the Pico 3V3 and GPIO23 recommendation. Is there a difference (if yes, what) between:
When supplied via VIN input, the IQR is very small → Very dense 50% of the sample
When supplied via VIN input, the number of Outliers increase 10 fold or more
When supplied via 3V3 input, the IQR triples → Our normal population is spread >3 times as much as with VIN
When supplied via 3V3 input, the number of outliers are factor 10+ less compared to VIN
Chinese
The best of both worlds
IQR a bit worse than Adafruits VIN
Outliers a bit worse than Adafruits 3V3
Supplying the board with 3V3 or 5V makes no difference on the RPi 3B
My recommendation
Don’t use an Adafruit
If you have an Adafruit, connect it via 3V3
RPi Pico
I will omit the screenshot as it contains 41 measurements and is virtually unreadable. Refer to the attached data if you want a closer look.
Adafruits
The same as shown for the RPi 3B is true for the Pico as well with some additional quirks
When supplied via VIN input, the IQR is comparable to the RPi 3B
When supplied via VIN input, toggling GPIO23 high will negatively impact the number of Outliers and positively impact the IQR
When supplied via 3V3 input, the IQR is drastically higher compared to the RPi 3B
When supplied via 3V3 input, toggling GPIO23 high will negatively impact IQR but positively impact the number of Outliers (the exact opposite of the VIN behavior)
When supplied via 3V3 AND VIN: Very good results in both IQR and number of Outliers (@koconnor’s “strange” idea)
When supplied via 3V3 AND VIN, toggling GPIO23 high will negatively impact IQR but positively impact the number of Outliers (the same as the 3V3 behavior)
Chinese
When supplied via Pico’s 3V3 output, toggling GPIO23 high will negatively impact the number of Outliers and positively impact the IQR
When supplied via Pico’s 5V output, the IQR improves at the expense of the number of Outliers. I consider the results worse than 3V3 with GPIO23 high
My recommendation
Adafruit: Connect via 3V3 AND VIN with GPIO23 high
Chinese: Connect via 3V3 with GPIO23 high
Final words
I’m really surprised how significantly the behavior is impacted by the supply voltage and way of connecting
Also there seem to be significant differences between the boards (of course, these results are now my equipment, YMMV)
A question, which is not answered by the data: In real world measurements, is it better to have a low IQR and live with the Outliers or vice versa. In my recommendation I tried to chose either a clear winner or some middle ground.
Cross Check by additional people would be highly welcome
Doing such analysis is a pain in the back. Some support in the software would also be highly welcome (hint @dmbutyugin )
In most of your experiments, improving IQR makes outliers worse and vice versa. It may indicate that a model ‘Assume the noise data should be normally distributed (normal population)’ does not accurately represent the actual process. For example, it is possible that acceleration A(t) = G + V(t) + N(t), where V(t) is the random noise related to power of adxl345, and N(t) - random ambient noise independent of the powering schema (e.g. thermal noise, ambient noise of the room, etc.). Under some conditions, it could be that as you improve V(t) (make it more ‘tight’), most of the outliers out of the fence end up being from N(t). Then naturally, as you decrease IQR, the number of outliers could increase rapidly vs the wide IQR. But that wouldn’t indicate that distribution with a smaller IQR is worse, because ‘outliers’ in both cases follow the same distribution, just as you tighten the allowed range, you find more outliers from that range. I’m not saying it is necessarily like that, but at least the presented results do not exclude that possibility. It would be interesting to see how many outliers you’d get if you took a sample with small IQR, used the fence bounds from a corresponding data set with high IQR (and small number of outliers), and checked how many outliers you get then. This could help compare the cases when IQR1 < IQR2 and outliers1 > outliers2 more fairly.
‘Also there seem to be significant differences between the boards’, you are talking about Adafruit1 and Adafruit2, right? I wonder how much the results are repeatable within one board though? E.g. if you run the same test multiple times, I’d expect that you could get some different results, and this may make results of the two boards more comparable (or maybe not).
‘Don’t use an Adafruit or If you have an Adafruit, connect it via 3V3’. You seem to prefer smaller outliers and higher IQR. However, in light of (1), I may have preferred the reverse: lower IQR and potentially higher number of outliers (their number is comparatively small anyway, I understand), and in this case Adafruit boards may be more preferable. Besides, there are other considerations besides the noise: e.g. QC. With Adafruit boards, you are less likely to get a board where the chip or a capacitor are soldered the wrong way
‘Connect via 3V3 AND VIN’ granted, I’m not sure why this is different that 3v3, perhaps the latter has some issues with the logic level shifters and floating VIN. However, I’d be leery of generally recommending something that is unclear why it should work (it does exclude voltage regulator from the schema altogether, and also affects the logic level shifter, but the effect of that on the noise is hard to understand). However, pure VIN variant often gives smaller IQR (at least, for adafruit1 board) on pico, so it might be more preferable.
Ideally, I’d recommend the same connection schema for Pico and full RPis. If we can, say, always recommend to connect the boards via VIN/VCC - input of the voltage regulator - that would be preferable as this reduces the amount of the documentation and confusion from the users. It also makes user mistakes less likely to occur, because this has smaller mental load - you only need to remember one possible connection. Then, of course, there are printer MCUs with SPI buses, but that requires a different level of expertise from the users anyway.
If the random noise is high frequency, that won’t affect the results of the resonance testing that much, if at all. Averaging the frequency response over many windows (~0.5 sec currently) reduces the noise, and high-frequency harmonics are ignored in our scripts anyway.
I took the tests basically one board at a time and in succession. The results of the boards match in their general tendency. I’d be surprised if there was a significant impact of N(t) and if then it should have been “stable” across one board
Looking at the histogram data would contradict this (forgot to mention on the diagram: X-Axis):
While VIN is more sharply centered, it has outliers in the range of 1200 to > 8200
The 3V3 is more spread (higher IQR) but outliers only between 3200 to 6200
See the attached spread-sheet. I did two additional runs with Adafruit1, Adafruit2 and Chinese.
Interesting thing is:
Adafruit1_0, Adafruit2_0 and Chinese_0 is from the run above
Adafruit2_1 and Adafruit2_2 2 days ago, taken in succession
Adafruit1_1, Adafruit1_2, Chinese_1, Chinese_2 yesterday in succession
Repeatability is almost spooky. Here the differences might really be ambient noise, as today my room lighting (50W LED panel) was on.
The test for repeatability also showed that derived values like IQR etc do match.
This statement was not exactly fair: Above tests omitted VIN AND 3V3 on the RPi 3B. Now in the data attached. Improvement is the same as for the Pico. Basically on par with the Chinese board.
Well, why it works is beyond my pay grade, but it works for both Pico and 3B with my two boards.
For comparison, this is the histogram between VIN and VIN AND 3V3 (This time the Y Axis, to show that the effects are comparable on all axes)