liba2k / VINCA_reader

MIT License
41 stars 4 forks source link

Documentation #4

Open vincentchov opened 1 month ago

vincentchov commented 1 month ago

Great work on making this to replace the DTCR-03 for Vinca calipers!

Can you please clarify the instructions?

  1. Do I need to slice open a micro-USB cable to plug the individual wires to an ESP32/ESP8266 (or alternatively, use a breakout board like the Sparkfun BOB-10031?
  2. Do I leave the power wire from the micro-USB cable unplugged, in which case the ground from the USB cable goes to the GND pin on the ESP? This assumes that I'm using a ESP devkit board that is powered by a second micro USB cable.
  3. If I use PlatformIO to compile/upload the sketch, will it fetch dependencies for me, so I don't need to install "arduinoWebSockets" myself?
  4. What changes do I need to make to replace the DTCR-02 for Clockwise Tools calipers? I see a comment about using DIGR-0105 indicators (replaces DTCR-01) but not for Clockwise Tools calipers like the DCLR-1205.

Thanks!

liba2k commented 1 month ago
  1. Yes, I did use a micro-USB cable and just cut off the USB-A side.
  2. Yes, +5v unconnected and GND to the dev board GND.
  3. I think so, but not sure.
  4. As far as I know most the caliper, indicators and linear scales from most companies use the same protocol, but you will have to check for yourself.

Thanks!

vincentchov commented 1 month ago

Okay, thanks a lot! I'm having trouble connecting to the wifi AP when using an ESP8266. It keeps asking me for the password. I tried using the one hardcoded in main.cpp and also tried changing it, but no luck. I'm waiting for an ESP32-S2 to come in the mail since I have an ESP32 DevKit C V4 and it fails to compile due to a type error related to the USB keyboard library. I'll check back in if I have any success.

vincentchov commented 1 month ago

Okay so I got it to compile on the ESP32 by removing the USB keyboard-related imports. I got it to stop crashing on-boot by changing the clock pin from GPIO 7 to GPIO 34 since GPIO 7 can't be used as regular GPIO according to the pinout diagram.

Now I'm getting a lot of nonsensical values as readings. It might be that I'm not getting a good signal from my USB cable (some of the wires are very thin and aren't seated well in the terminal block I'm using on my breadboard), so I'm also going to try a micro USB breakout board.

vincentchov commented 1 month ago

Okay so I'm still having trouble. Can you please let me know if there are any specific challenges I should look out for? I've tried a few different configurations, but am still not getting correct values.

My most-recent version was soldered onto a solderable breadboard (shown below), with a ESP32-S2 Mini, without modified GPIO pins. In the diagram, it looks like I connected clock to GPIO 6 instead of GPIO 7, but I in fact placed the wire below the ESP32-S2 Mini and left the inner pins unsoldered, so SCLK is indeed connected to GPIO 7. The power rails are connected, since my solderable breadboard looks slightly different from the diagram (also shown below).

I'm starting to think it might be a timing issue. I see that MILLIS_BETWEEN_PACKETS is set to 100 (presumably milliseconds), but the README says 150ms. When connected to an oscilloscope, I could see pulses coming out of the transistors at about 60hz (period of about 166 ms).

caliper_reader_bb PXL_20240812_002623694 PXL_20240812_005029731

Thanks a lot!

EDIT: I just redrew the breadboard diagram as a perma-protoboard diagram and saw a bug: the 2.2K resistor going to the button is connected to GND. I still had issues before, since it never picked up the right value though. caliper_reader_diagrams

liba2k commented 1 month ago

I've checked, and while my setup is noisy, you can see from the measurement the time between bursts on my caliper is 135ms (see BX-AX). Are you sure you are looking at the data bursts, not the mains power 60Hz? DS1Z_QuickPrint2

vincentchov commented 1 month ago

Ah I see. I'm very new to using oscilloscopes and had help from an electronics volunteer at my local makerspace who said they themselves were new to oscilloscopes.

At any rate, do you have suggestions on how I should go about debugging this? Should I use an ESP-Prog to be able to set breakpoints? I just bought one for this project since I thought Serial.print statements would interfere with the interrupt used for reading data.

What I tried on the oscilloscope yesterday

It looked like I was getting pulses when I connected an oscilloscope probe to GND and one end of the 2.2K resistor connected to caliper clock and also for data.

Same thing when connecting to the base (B) of the 2N2222A transistors, so it seemed clock and data were making it to the transistor.

I also saw pulses when connected to the collector (C) side, suggesting that they should make it to the ESP. However, when I touched the probe to the GPIO pin (from above the board), I didn't see a regular waveform. I don't remember if it was supposed to be a square waveform or not, but it looked much noisier.

vincentchov commented 1 month ago

I really appreciate the help by the way! If I can get this to work, I plan on doing a write-up on my troubleshooting steps and provide a breadboard diagram that could be added to repo so other people can navigate the pitfalls I'm facing.

I also have a temporary branch where I've commented the code to confirm that I understand what it's supposed to do, and so I can decide where to place breakpoints if I can/should use an ESP-Prog to debug this (assumes that the circuit is connected correctly and that the issue lies in firmware).

Thanks again! 🙏

liba2k commented 1 month ago

While trying to get better wave screenshots for you, I noticed something that might be your problem. The GND from the caliper is the USB cable shielding, not the black wire (-). The black wire is not connected to the caliper side. Please also look at the screenshot, The data line is on top (yellow) and the clock is the bottom (cyan).

DS1Z_QuickPrint6

vincentchov commented 1 month ago

Sorry, I don't think I understand what you mean when you say

The GND from the caliper is the USB cable shielding, not the black wire (-). The black wire is not connected to the caliper side.

Does this mean I need to disconnect the GND wire (squared in bright green on the top left) from the micro-USB breakout board?

My cable doesn't have shielding. Are you suggesting I use a cable that has shielding and solder the GND wire (the one squared in bright green) to the shielding of the cable? In that case, the USB breakout board would only have the D+ and D- connected.

caliper_reader_bb

By the way, now that I've soldered everything together, it seems to be more stable in that I'm not getting constant readings, but they read as 0mm, 0", etc, even if I slide the caliper scales around and leave them there for a few seconds. Below shows what happens when I set the calipers to 17.21mm

  1. Set calipers to 0mm and then plug-in/turn-on; no values shown 1 - set to 0mm
  2. Slide calipers to 17.21mm; no values shown 2 - set to 17 21mm
  3. Switch unit to decimal inches; 0.0000mm appears 3 - switch unit to decimal inches
  4. Switch unit back to mm; 0.0000" appears along with some other invalid values 4 - switch unit back to mm
liba2k commented 1 month ago

Sorry, the adafruit micro usb breakout already connects the lines adafruit_micro_usb

If you have a multimeter, please use in on continuity mode (the one that beeps when the two probes are touching) and make sure you have a connection between your board GND and the metal body of the caliper, if you don't that will explain your issue. Otherwise we will have to look elsewhere. I don't have the HW for this project (I gave them all as gifts). But I will build one so we can compare, if we can't find the solution soon.

vincentchov commented 1 month ago

Okay! I confirmed that I do have continuity between the metal body of the caliper and GND. I also have continuity between the caliper and the D+ and D- pins. Same for base and collector of the two transistors. Also, the button does output values like a keyboard. The values are just inaccurate.

Please excuse the videos possibly not being playable in the browser. I needed to compress them in x265 to meet the 10MB file size limit.

Video 1 contents: check that continuity function works when probes touch, continuity on just the calipers, and continuity between the calipers and GND (both on the breadboard GND rail and on the GND pin of the USB breakout)

https://github.com/user-attachments/assets/f62baee3-0b9b-4c07-9058-4d795d8ce3aa

Video 2 contents: check for continuity between the calipers and the D+/D- pins, as well as the resistors connected to them

https://github.com/user-attachments/assets/c4db01a9-baa8-48b7-8d25-98ecc950a27b

It's not in the second video, but I got continuity when checking between the caliper body and the base of the transistors as well as the collector.

liba2k commented 1 month ago

You should not have continuity between D+/D- and the body of the caliper. I've measured the resistance between D+/D- and the body and it shows up as open circuit. If you have another breakout board, can you check that D+ & D- are not connected to the body (GND). I do see the 2.2k resistors, but maybe your pins are shorted under the board. I don't see how you get connectivity from the data lines to the body (unless you are not checking agains the body, I can't see the other probe in the second video).

vincentchov commented 1 month ago

I just noticed that I don't get continuity between D+/D with GND when the calipers are disconnected.

When the calipers are connected, I get continuity between D+/D and GND, presumably because the calipers are sending signals. This makes sense to me because I get continuity between GND and the metal body of the calipers; I should therefore get continuity between D+/D and the metal body of the calipers, right?

I'm also seeking help from a volunteer who's much more experienced than me, btw, so I might be able to get a more detailed look at it.

Thanks again!

EDIT: oh and by the way, in the second video, one of the probes is resting on the caliper jaws.

liba2k commented 1 month ago

No, you should not see continuity between D+/D- and GND when the caliper is transmitting. Please try another cable and/or another caliper. Or use a cut micro USB cable to test the continuity between the data lines and the body of the caliper.

vincentchov commented 1 month ago

Good news, it's working now!

There were two issues that we found: one related to shielding, and the other being that the D+/D- might be reversed compared to what the code expects.

What fixed it

Thanks to your hint about shielding, we were able to find out that shielding is needed, and that it should be connected to GND. I was told that I could access the shielding by soldering a wire to one of the four points on the Micro-USB breakout board where the connector was soldered onto the PCB. I ended up soldering a stranded wire to one of those four points and connected it to circuit GND (on the breadboard) to prevent a "ground loop", which previously allowed for electromagnetic interference. That issue was probably why the circuit looked correct but that I still got invalid values and at an inconsistent rate.

Also, it looks like the note "the D+ and D- lines have clock and data" might be inaccurate. After connecting the circuit to a logic analyzer, it looks like D- is clock, while D+ is data. I made a new circuit diagram accordingly.

Experimenting with USB-C

I also picked up a USB-C breakout board from Adafruit and got that to work as well, although this time, I soldered the wire on the top of the PCB and connected it to GND on the breakout board side rather than on the solderable breadboard. I was told that USB-C cables almost always use shielding, so that might prevent the issue I faced. The other end of the USB-C cable had a Micro-USB adapter on it of course since the calipers still use Micro-USB, but at least now I'm not using a weird Micro-USB extension cable that I was also told was non-standard.

I can do a write-up on the steps I took to build this circuit, and can also wait for if you have the same findings.

Thanks again!

1 - shield points 2 - shield to gnd caliper_reader_usb_c_bb.pdf caliper_reader_usb_c_bb

liba2k commented 1 month ago

Great to see that you got it work. I was never sure about the D+/D- since I've used the scope to identify them.