Hi,
I'm new to the Arduino and tried to connect my dial gauge with it. For this I used a data cable of Mitutoyo with an USB port at it's end. Then i connected the cable with an USB-adapter which splits the port into pins. These pins are now connected to the Arduino Uno. My goal is to see the measurments in the serial monitor.
I found this code on the internet, where they connected a dial gauge without an USB-cable to the Arduino.
int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
int dat = 2; //mic Data line goes to pin 2
int clk = 3; //mic Clock line goes to pin 3
int i = 0;
int j = 0;
int k = 0;
int signCh = 8;
int sign = 0;
int decimal;
float dpp;
int units;
byte mydata[14];
String value_str;
long value_int; //was an int, could not measure over 32mm
float value;
void setup() {
Serial.begin(9600);
pinMode(req, OUTPUT);
pinMode(clk, INPUT_PULLUP);
pinMode(dat, INPUT_PULLUP);
digitalWrite(req, LOW); // set request at high
}
void loop() {
digitalWrite(req, HIGH); // generate set request
for ( i = 0; i < 13; i++ ) {
k = 0;
for (j = 0; j < 4; j++) {
while ( digitalRead(clk) == LOW) {
} // hold until clock is high
while ( digitalRead(clk) == HIGH) {
} // hold until clock is low
bitWrite(k, j, (digitalRead(dat) & 0x1));
}
mydata[i] = k;
}
sign = mydata[4];
value_str = String(mydata[5]) + String(mydata[6]) + String(mydata[7]) + String(mydata[8] + String(mydata[9] + String(mydata[10]))) ;
decimal = mydata[11];
units = mydata[12];
value_int = value_str.toInt();
if (decimal == 0) dpp = 1.0;
if (decimal == 1) dpp = 10.0;
if (decimal == 2) dpp = 100.0;
if (decimal == 3) dpp = 1000.0;
if (decimal == 4) dpp = 10000.0;
if (decimal == 5) dpp = 100000.0;
value = value_int / dpp;
if (sign == 0) {
Serial.println(value, decimal);
}
if (sign == 8) {
Serial.print("-"); Serial.println(value, decimal);
}
digitalWrite(req, LOW);
delay(100);
}
I hoped it would work for me aswell, but sadly it doesn't. I have some ideas what causes the problems but I'm not sure if I'm right and how to solve them.
My ideas:
The cable of the dial gauge has a DATA-button. The datas are only sent when this button is used. Then it sends one Measurment, even if the button is hold for a while. On a Windows PC the data is sent as the value and an Enter (jumps into the next row). Is this a problem for the Arduino?
Maybe the USB-adapter only send datas from the pins to the USB-port and not the other way around.
Maybe the code does not work?
I already did some tests and sort out the following problems:
The cable is broken: works completly fine with my PC, I can use it in Excel, Word, the Editor and the Browser
My arduino software on the PC does not work: I tried to print "Hello" and it worked
That dial gauge is powered from 1.5V LR44 cell. Thus its not going to be compatible with a 5V Arduino or
even a 3.3V Arduino without some sort of level shifting. Presumably the USB adaptor cable does
this in some fashion, but it might only then be visible as USB packets.
wvmarle:
Both that USB adapter and that dial gauge are USB client devices. They will not talk to one another.
If you get an Arduino that can act as USB host (Yun? Leonardo?) you should be able to get it to talk to the dial gauge directly. No USB adapter.
I used this to connect the USB adapter and the dial gauge so they should communicate, right ? If not, is it possible to use the USB-B port of the Arduino Uno to connect the dial gauge with it?
I looked for an Arduino Yun and saw that it's pretty expensive. After reseaching I found a 'USB Host Shield' for the Arduino Uno. With that extra device a Mouse or Keyboard can be connected to the Arduino. The exact same features are described as functions for the Yun too. From my perspective it seems like I could use the Host Shield aswell or am I missing something ?
lomars:
I looked for an Arduino Yun and saw that it's pretty expensive. After reseaching I found a 'USB Host Shield' for the Arduino Uno. With that extra device a Mouse or Keyboard can be connected to the Arduino. The exact same features are described as functions for the Yun too. From my perspective it seems like I could use the Host Shield aswell or am I missing something ?
Looks like it will do the job, though at 24 Euros it sounds pretty expensive to me. The Yun even more expensive than that? I'm used to pay something like 1.5 Euro for a Nano, a little less for a Pro Mini...
MarkT:
That dial gauge is powered from 1.5V LR44 cell. Thus its not going to be compatible with a 5V Arduino or
even a 3.3V Arduino without some sort of level shifting.
Does that USB Host Shield include level shifting or do I have to buy an extra device for that ?