2B0RN2B I have seen the future, and it works
To Be or Not to Be
I have seen the rise of the ultimate mega. And I have heard about its potential. And like what Lincoln Steffens wrote in 1919, he exclaimed:
I have seen the future, and it works!
Mirroring Steffens’ awe at the Bolsheviks, I feel awe, and yes, I do, at the current mega today.
And what is the purpose if the mega can do things much better?
What is the purpose if all of your questions can be answered?
And what if, what if, everything at the start is wrong, and the mega is the only solution?
And in my final process of finishing the 3D scanner, I realized that I cannot push forward without the mega. Yet, the mega can move forward without me.
Microstepping
Behind
Well, ignore all the words I just said a couple weeks ago. GitHub has been a Pandora’s box in my current position. And I feel that I can manipulate my access easily.
I think I found a parallel connection between my relationship with GitHub and the public relationship with the stock market. It goes red after you buy it; it goes green after you sell it.
Configuring Microstepping
Referring back to these two documents:
They show that microstepping is simply a matter of adding jumpers. I’ve converted the official tables into one chart for reference:
A4988 Stepper Driver configuration
| M0 | M1 | M2 | Microstep Resolution |
|---|---|---|---|
| Low | Low | Low | Full step |
| High | Low | Low | Half step |
| Low | High | Low | Quarter step |
| High | High | Low | Eighth step |
| High | High | High | Sixteenth step |
So I have tested both Quarter Step and Sixteenth Step, and trust me, once you get smooth operation, it feels like Smooth Operator from Carlos Sainz.
Just as a fun clip:
So how to use microstepping:
Microstepping increases resolution not precision –– unknown author named Pigtt
Formulas
Let:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25- ```M = microstep factor```
- ```k = microstep index``` (integer)
I LOVE LATEX
$$
\text{Total\_Steps} = S \times M
$$
$$
\Delta\theta = \frac{360}{S \times M}
$$
$$
\theta(k) = \frac{360k}{S \times M}
$$
So, for example, if M = 4, or ```Quarter Step```:
```arduino
N = 200 × 4 = 800
Δθ = 360 / 800 = 0.45°
θ(k) = 0.45k
If M = 16 or Sixteenth Step
1 | N = 200 × 16 = 3200 |
Handshakes
What are handshakes, tokens, and private / public keys?
Essentially, they are all methods of identification. For the Arduino and Python to talk, they need a handshake: my Python plot code has to see a green-light signal before it starts reading — otherwise it falls out of sync with the Arduino and the whole exchange fails.
Here’s a basic handshake demonstration:
1 | void setup() { |
Python receiving handshake and giving back a kiss.
1 | import serial |
Here’s what each piece does on the Arduino side:
Serial.begin(115200)— opens the USB serial connection at115200, the same speed Python uses.while (!Serial)— forces the Arduino to wait until the computer actually opens the USB connection, so the first message isn’t lost during reset.Serial.println("READY")— sent once to tell Python “HELLO there. I have EARS. I am not daydreaming.”Serial.readStringUntil('\n')(insideloop()) — waits until Python sends a full line ending in a newline, guaranteeing a complete command."GO"— the Arduino only proceeds when it receives this exact signal.Serial.println("OK")+while (1)— once"GO"arrives, it confirms withOKand halts, so the exchange runs only once.
WARNING: if the two baud rates don’t match, you’ll just receive ????????? — garbage bytes.
Videos (Very Long):
My mistake of over-relying on WebbGPT.
When you add too many handshakes and maybe, maybe delete your own handshake.
I am not going to paste an entire chunk of code. But I am going to show you the specific bugs that I’ve encountered:
1 | ser = serial.Serial(port, baudrate, timeout=2) |
What I did is that I opened serial, which resets Arduino.
Then I waited 2 seconds while Arduino booted and printed ready.
However, the code reset_input_buffer deletes everything Arduino just sent, including ready.
WHAT AM I DOING
Solution:
A simple solution would be reordering the code so that it clears the trash first:
1 | ser = serial.Serial(port, baudrate, timeout=2) |
Even better, we can actually wait for ready
1 | print("Waiting for 'ready'...") |
The Full Code (for reference)
1 |
|
On the Python side, this script runs the handshake, reads the x,y,dist CSV stream, converts each point to 3D, and plots it live as the scan runs:
1 | import time |
And here’s the super duper GPT version — same idea, but it dumps the scan into a grid, then denoises it (neighbor-consistency + largest connected component) so you keep only the real surface:
1 | import time |
Joke
If you read until here, congrats, you’re done with my nonsense.
I have a gift for you.
What is the best language in the world?
A) JavaB) PythonC) C++D) ALL of the ABOVE
Answer D, soPython + Java + C = Phavac
Go to phavac.com for the mirror of pigtt.com
