Pages: 1 [2]   Go Down
Author Topic: Digital Linear Gauge to RS232  (Read 1401 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Fwd & Rev Eng
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sequence is in any case 000011111110 - i used nibbles for clarity and to be aligned with the data definitions.

Decimal digits are =<1001 and <1010, aren't they?  smiley

I agree that the original poster had a long way to go and an unfair (to me) pressure but perhaps (hopefully) the thread becomes of use to someone else.

BR


ps. I missed the four types of data frames in the data sheet. Where are they mentioned?
« Last Edit: September 27, 2010, 03:29:27 am by punk » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
To be pragmatic what he is really after is a result rather than the learning experience.

Thanks for your interest in my problem.

I am making a machine that measures a camshaft.
I need to measure the cam to get information about the design of the current cam is so that I can compare the original design to the new design.

The machine uses two input devices; a rotary encoder and a linear gauge.

The idea is that I will rotate the cam (attached to the rotary encoder) and then for each position of rotation I send the value through the serial port to a VB program that I wrote.

This much I have working.

The next challenge is triggering the linear gauge to measure the position of the cam follower each time the rotary encoder changes value.

I would really prefer to do this with the Arduino if possible but it looks like code for reading this kind of device is very specialized and complex.  

There are devices called smart cables that might do what I need, I will find out today, they are about $200 I think.






Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
they are about $200

Ouch!

I suppose it's not so bad if you are using some one else's money. However, if you want to have a dabble I could finish off that code for you tonight and you can see if it works.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you think you can do it, I will gladly pay you for your efforts.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grumpy_Mike

Thanks a million for that, as soon as the cable gets here I will try it.

Until then I will try to learn something from your code, it is way over my abilty to write something like that but given enough effort I can probably understand what you are doing there.

Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I say I was doing something wrong, not delaying until the clock went high again so I deleted the old post and I have put this instead.

Code:
//Simple Ono Sokki Reader


// Pin Declarations
int dataIn = 11;   // Pin 2 from the guage
int clockIn = 12;  // Pin 2 from the guage
int modeOut = 10;  // Pin 5 from the guage
int resetOut = 13;  // Pin 4 from the guage
// wire up pin 1 from the guage to ground

// Variables
byte inputValues[13]; // place to put the input from the guage
unsigned long time = 0;
unsigned long timeStart = 0;
int out = 0;


void setup() {
  // Pin Set Up
  pinMode(dataIn, INPUT);    
  pinMode(clockIn, INPUT);
  pinMode(modeOut, OUTPUT);
  pinMode(resetOut, OUTPUT);
  digitalWrite(modeOut, HIGH);
  // Reset the guage (this might not be necessary)
  digitalWrite(resetOut, LOW);
   delay(30);  
  digitalWrite(resetOut, HIGH);

  Serial.begin(115200);
  Serial.println("Ready: ");
}


void loop(){
  getReading();
  for(int i=3; i<13; i++) { // print out the results
  Serial.print("Step ");
  Serial.print(i+1);
  Serial.print(" ");
  Serial.println(inputValues[i],HEX);
  }  
}
void getReading() { // reads 12 nibbles from the input on rising edge of the clock
  byte val=0, inputBit =0;
  boolean notFound = true;
  // try to syncronise to incomming streem looking for 0xFE
  while(notFound) {
  while(val != 0x7f) {
   while(digitalRead(clockIn) == LOW) { } // do nothing until clock goes high
   inputBit = digitalRead(dataIn) & 0x01;
   val = (val << 1) | inputBit;
   if(inputBit == 0) val = 0; // reset if it is zero
   while(digitalRead(clockIn) == HIGH) { } // do nothing until clock goes low
  }
  // look for last bit in first two nibbles
   while(digitalRead(clockIn) == LOW) { } // do nothing until clock goes high
    inputBit = digitalRead(dataIn) & 0x01;
   if(inputBit == 0) notFound = false; else val = 0;
   while(digitalRead(clockIn) == HIGH) { } // do nothing until clock goes low
  }
  // now get the data
  for(int i=2; i< 13; i++){
    inputValues[i] = getNibble();
  }
}

byte getNibble(){
  byte val = 0, inputBit = 0;
  for(int i=0; i<4; i++){
      while(digitalRead(clockIn) == LOW) { } // do nothing until clock goes high
    inputBit = digitalRead(dataIn) & 0x01;
    val = (val << 1) | inputBit;
       while(digitalRead(clockIn) == HIGH) { } // do nothing until clock goes low
  }
  return(inputBit);
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the update, the cable just arrived, I am going to wait until everyone goes home so I can have peace and quiet, get some diet coke, some cold pizza, a soldering iron and have some real fun.



Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Grumpy Mike,

Huge progres!!

First I think where the code says:

Code:
int dataIn = 11;   // Pin 2 from the guage
int clockIn = 12;  // Pin 2 from the guage

There was a typo and you meant Pin 3 from the gauge

Code:
int dataIn = 11;   // Pin 3 from the guage
int clockIn = 12;  // Pin 2 from the guage

When I connect and run it the serial monitor continuously scrolls the following:

Step 4 0
Step 5 0
Step 6 0
Step 7 0
Step 8 0
Step 9 0
Step 10 1
Step 11 0
Step 12 0
Step 13 1

Moving the measuring probe changed the values of Steps 4 through 9 between 1 or 0 values.
Is that what you were expecting, should it be returning digits from 0 to 9?

Thanks so much for your help!
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
should it be returning digits from 0 to 9?
Yes

OK spotted it. Stupid mistake. Replace:-
 return(inputBit);

with  return(val);
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks now it returns the following

Ready:
Step 4 0
Step 5 0
Step 6 0
Step 7 0
Step 8 0
Step 9 8
Step 10 5
Step 11 0
Step 12 0
Step 13 F
Step 4 7
Step 5 E
Step 6 2
Step 7 B
Step 8 F
Step 9 F
Step 10 2
Step 11 F
Step 12 F
Step 13 F
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does that tally with anything on the display?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does that tally with anything on the display?

Some of the numbers might be the same but there are never any letters in the display. I can't imagine where those would come from.

I was looking for clues in this conversion table, I wonder if it could be taking Dec input and returning Hx?

http://www.asciitable.com/





« Last Edit: September 29, 2010, 05:30:08 pm by schmidtjts » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got it!

This page gave some tips about printing

http://www.arduino.cc/en/Serial/Print

I changed the print from:

Code:
Serial.println(inputValues[i],HEX);

to

Code:
Serial.println(inputValues[i],DEC);

And now it displays the same numbers as the gauge.

One week ago this seemed like an impossible project and now thanks to your doing so much for me I can probably do the rest of the trivial stuff myself.

You must be able to make so many cool projects at will with those coding skills.

If I can ever help you with something I do know about like car problems or if you need a part machined be sure to ask.

Thanks so much!

Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 509
Posts: 31452
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you got it. I used HEX so you could see the bit pattern of the data more clearly. Hex makes a lot more sense for things like this than decimal.

Quote
You must be able to make so many cool projects
Anyway if you want to check out some of my projects you can find them at:-
http://www.thebox.myzen.co.uk/Hardware/

Cheers
Logged

Pages: 1 [2]   Go Up
Jump to: