Welcome! Log In Create A New Profile

Advanced

Igaging digiindi digital indicator as a z probe

Posted by corry 
Igaging digiindi digital indicator as a z probe
September 04, 2015 08:55PM
There's a lot of information online, and none of it worked directly. So here it is. This should all work...unless igaging is really sneaky!

Connections: it uses a microusb connector, but it's not microusb (isn't there an Eula or something from the USB consortium saying you can't do this?). Anyhow, standard USB cable wire colors apply. Supply 3.3v to the indicator on the red wire. Black is ground. Without 3.3v coming in, the external connection circuitry won't enable. It won't run off batteries. White is the clock line, green is data (nothing like USB ).

Clock: nothing special here. Apparently the scales used a 9KHz clock. The original code I tried on an arduino generated a roughly 200KHz clock with a 95% duty cycle (did I mention how bad the online stuff was?) but the indicator took it just fine, or it seemed to on the scope. Arduino output can be directly connected to the clock pin of the indicator.

Data: this is where everything goes wrong. Data is sent 1 bit at a time with each rising edge of the clock. 21 bits total, lsb first. Everyone seems to have that part right. Data line is active low. (Which seems to have confused some.). The data line will timeout and return to logic low (voltage high) state after roughly 5ms of no clock. I'm not sure if it's clock dependant or if it's just 5ms regardless of clock frequency. That little tidbit caused some severe frustration for me not realizing it was active low, and the emi from the return to high made it look like noise on the clock line ticked another bit over lol. Yeah...I was going on the assumption that just the data was inverted for some reason smiling smiley. All you need to connect this is either a sacrificial mini USB cable (ugly) or an old back panel/front panel USB port. Pull the pins out of their plastic housing if it has one that would normally go to the motherboard for extra USB ports, and connect to the arduino appropriately smiling smiley. Easy and clean!

Data interpretation: it gets fuzzier here since most online pages about arduino and igaging are for digital read out scales, and the interpretation here is clearly going to be different for an indicator! First off raw format. You can just bit=!digitalRead(DATAPIN) if you so desire, but more efficient would be to read each bit shifting and oring, then at the end, inverting just the bits read with value^=0x001FFFFF. Now you need to sign extend. I'm treating it as a 21bit 2s compliment number in this regard, so I check if bit 21 (0x00100000) is set. If it is, I sign extend it simply by oring with 0xFFE00000. Now, it looks like a proper signed 32 but number to the microcontroller.
Zero point. Seems arbitrary. You'll need a calibration button, software trigger, or just do what I'm doing right now and assume the first read is at 0 and record that smiling smiley. On my indicator, the 0 value is -410. So I read that value in at the beginning then subtract it back out of each successive read.
Steps/mm. I admit, this is really odd. I don't have a good explanation. On my indicator it's 201 and 2/3 steps/mm. Not an even number for mm. I had thought perhaps it was inches then, but the number is equally strange. To give an idea, 201.6667 woks out to be 0.004958677677754 mm/step, not quite 5 microns as we'd expect since that would be 200 steps/mm. In inches, that value is 0.00019522353062 in per step. Perhaps this is intentional. Perhaps the manufacturing equipment is good at laying down markers at regular intervals, just not at getting those intervals to a precise value. Even if one site I read that said the data is 1s compliment, that would only change things by a factor of 1, and not changed the steps/mm. One site even offers 2560 points/inch but that doesn't add up either on the indicator! (It would be 5122.333333 steps/inch!). So I'm at a loss on that. However, I will say 201.67 gives identical readings to the indicator across the entire range, so there you have it.

Arduino code is coming soon, as well as pictures, just in case anyone else gets this stupid idea to use the indicator as a z probe smiling smiley

linked urls for the pictures. I thought there was a direct way to get to dropbox pictures....but I guess I never tried until now...
Picture (dropbox) of the indicator display along side the serial monitor
Indicator display along side the serial monitor
Using a teensy there for 3.3V native support. Otherwise you'll need a voltage divider on power and clock. The 5V arduinos can use the 3.3v input from the data line.
Picture (dropbox) of the simple hardware setup

Arduino Code....its simple enough to include here....
//pin definitions
#define CLOCKPIN 4
#define DATAPIN 3
#define STEPSPERMM 201.66666666666667
 //variables that will store the readout 
unsigned long Val;
long ZeroPos;
bool ZeroInitialized;
//Next, we need to initialize the pins to the right modes (input or output) inside the setup() function as follows:
void setup() 
{
  //clock pin should be set as output 
  pinMode(CLOCKPIN, OUTPUT);

  //data pins should be set as inputs
  pinMode(DATAPIN, INPUT);
  Serial.begin(115200);
}
// In the loop() function we will read the first 20 bits in a for loop.
void loop()
{
  Val=0;
  int bitOffset;
  unsigned long t=0;
  //read 21 bits
  for(bitOffset = 0; bitOffset<21; bitOffset++)
  {
    digitalWrite(CLOCKPIN, HIGH);

    delayMicroseconds(111);
    digitalWrite(CLOCKPIN, LOW);

    //read the pin state and shif it into the appropriate variables
    t=digitalRead(DATAPIN);
    t<<=bitOffset;
    Val |= t;
    delayMicroseconds(111);
 
  } 
  Serial.println(Val,HEX); 
  Val^=0x1FFFFF;
  Serial.println(Val,HEX); 

  if(Val&0x100000)
  {
    //its negetive sign extend
    Val|=0xFFE00000;
  }
  if (!ZeroInitialized)
  {
    ZeroPos=Val;
    ZeroInitialized=1;
    delay(20);
    return;
  }
  Val-=ZeroPos;
  Serial.println(Val,HEX); 
  float fVal=0;
      
  fVal=Val/STEPSPERMM;

  Serial.println(fVal);
  delay(20);
 
}

Edited 4 time(s). Last edit at 09/05/2015 12:31PM by corry.
Sorry, only registered users may post in this forum.

Click here to login