Good day!
For more than half a year I own a cheap Chinese 150mm electronic shtangel, in the instructions for which the phrase “digital interface” is written. The possibility of outputting to a computer interested right away, but I matured for this feat just now.
Initially, the motivation was simply curiosity, “so that it was!” And “suddenly, someone asks, but I have!”, Later (already in fact, “it worked!”) There was also a real use in the project with a home-made CNC machine tool.
')
Introductory
The main character , in spite of its cheapness (about $ 8), is nevertheless a very accurate device:
Principle of operation: capacitive sensor.
Everything is connected with the movement of the small plate (the head of the shangel) along the large (the scale of the shangel), while the uncharged part of the large plate is charged and seems to be a charge flowing through the capacitor formed by these plates is proportional to the movement of the small plate. Something like this.
Search
Initial searches for information about the digital interface have shown that many have seen it, some even know, but no one knows how to use it.
An in-depth search on non-Russian resources yielded more productive results. It seemed at first - everything is quite simple and understandable, chewed on oscilloscopes, shot on YouTube, etc., but there was no final and working “at once” option.
So, the main problem was the search for information.
The second problem was the manufacture of the plug to this connector (which, in general, is not a connector at all, but just bare tracks on the board). Contacts stubbornly refused to hold on. In the end, I guessed to insert the legs from the LPT port into a piece of lash. The thing turned out to be unreliable, but for the test it is quite suitable. For the future, I decided without fail to solder directly to the board and bring out my connector (pin CD-IN from the motherboard).
Decision
Stumbling on
an article on instructables.com decided to repeat this feat.
To begin with, I’ll give you pictures of the brazenly steeped out of there with the location of the contacts on the compass and the basic wiring diagram (I don’t see any reason to redraw myself, but it’s unforgivable to give out as my own):
Pins:
Scheme:
To match the voltages, I used a 200 Ohm resistor as recommended. There was no condenser for 10µF and I put 100µF out of the dead motherboard.
Result
Having coped with the soldering, he began to write a sketch. By the way, in the absence of a mock-up board, he got out of the situation, having collected the scheme on the “crib” from the IDE-port, from the same motherboard.
The sketch given in the above article earned without question, but did not bring satisfaction.
The Chinese sketch from comments, to work “at once” - refused, but made a much more serious impression, as a result, it was subjected to serious “finishing”.
Here's what came out of it (or the finished sketch for Arduino UNO, version IDE 0022):
//CyberKot ( ... ! Shadow) // Arduino, COM- // int dataIn = 11; // , int clockIn = 2; // clock, , ( attachInterrupt) int isin = 0; //=1 =0 int isfs = 0; // int index; // unsigned long xData, oData; // ( ) int ledPin = 13; // 13 (, , ) int ledState = LOW; // long previousMillis = 0; // long interval = 500; // long previousGetMillis = 0; long Timeout = 8; // float stringOne; // char charBuf[5]; char charBuf2[8]; void setup(){ digitalWrite (dataIn, 1); digitalWrite (clockIn, 1); pinMode (dataIn, INPUT); // dataIn pinMode (clockIn, INPUT); // clock 2 attachInterrupt(0,getBit,RISING); // clock 2 Serial.begin(9600); delay(500); index = 0; xData = 0; oData = 999; } void loop(){ if ((index !=0) && (millis() - previousGetMillis > Timeout) ) { // index = 0; xData = 0; }; if (index >23) { // if (oData !=xData) { /* , , if (isin==1){ // Serial.print("inch: "); stringOne =xData*5/10000.00000; stringOne *=pow(-1,isfs); Serial.println(floatToString(charBuf2,stringOne,5,5)); }else { // Serial.print("mm: "); stringOne =xData/100.00; stringOne *=pow(-1,isfs); Serial.println(floatToString(charBuf,stringOne,2,5)); }; */ if (isin==1){ // if (isfs==1){ // Serial.print("inch: -"); }else { Serial.print("inch: "); } stringOne =xData*5/10000.00000; Serial.println(floatToString(charBuf2,stringOne,5,5)); }else { // if (isfs==1){ // Serial.print("mm: -"); }else { Serial.print("mm: "); } stringOne =xData/100.00; Serial.println(floatToString(charBuf,stringOne,2,5)); }; }; oData =xData; index=0; xData=0; }; if (millis() - previousMillis > interval) { // previousMillis = millis(); if (ledState == LOW) ledState = HIGH; else ledState = LOW; digitalWrite(ledPin, ledState); } } void getBit(){ // previousGetMillis=millis(); if(index < 20){ if(digitalRead(dataIn)==1){ xData|= 1<<index; } } else { if (index==20) // isfs=digitalRead(dataIn); if (index==23) // isin=digitalRead(dataIn); }; index++; } // float char * floatToString(char * outstr, double val, byte precision, byte widthp){ // , , ( ), char temp[16]; byte i; // double roundingFactor = 0.5; unsigned long mult = 1; for (i = 0; i < precision; i++) { roundingFactor /= 10.0; mult *= 10; } temp[0]='\0'; outstr[0]='\0'; if(val < 0.0){ strcpy(outstr,"-\0"); val = -val; } val += roundingFactor; strcat(outstr, itoa(int(val),temp,10)); // if( precision > 0) { strcat(outstr, ".\0"); // unsigned long frac; unsigned long mult = 1; byte padding = precision -1; while(precision--) mult *=10; if(val >= 0) frac = (val - int(val)) * mult; else frac = (int(val)- val ) * mult; unsigned long frac1 = frac; while(frac1 /= 10) padding--; while(padding--) strcat(outstr,"0\0"); strcat(outstr,itoa(frac,temp,10)); } // ( ) if ((widthp != 0)&&(widthp >= strlen(outstr))){ byte J=0; J = widthp - strlen(outstr); for (i=0; i< J; i++) { temp[i] = ' '; } temp[i++] = '\0'; strcat(temp,outstr); strcpy(outstr,temp); } return outstr; }
Total
Satisfied with the result, I decided to make the final photo, and a bit of “bosy” advertising for the effect:
Afterword
The protocol description also contains a couple of interesting buns, so there is an incentive to be touched "for the future"
- fast mode (50Hz, against 3Hz in the default mode)
- processing "absolute" position
- soft buttons "Zero" and "Mode"
[Links]