We're trying to calculate a distance with an instrument that sends out a Serial data string of 'A', 'B' or '+' that it has read from a pulse counter connected to a spring loaded drum with a chord monitored by a pulse counter.
RS485 in 19200 that we convert into RS232.
Cord is being pulled out, 'A' comes we add 2cm on the result variable, back in 'B' and we subtract, nothing happens a '+' comes by with some frequency.
Our code works at low speed is:
// result, k and penetration are variables...
while (Serial3.available() > 0)
{
result = Serial3.read();
if (result == 'A'){
penetration +=k;
}
else if(result=='B'){
penetration -=k;
}
Serial.println(penetration, 4);
}
Instead of while we've also used 'if' from time to time, it sits in a big loop anyways...
Our guess is that it somehow writes over the old data before it has recorded it..
According to manufacturer equipment has been tested with their software at the speed of gravity pulling the chord out with a weight, so the hardware must be sorted...
(Text to picture; Its shiny, its heavy, its stainless steel, its offshore gear, 1000m depth rated)
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your complete code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
There might be some minor issues with this code since its stripped from Swedish comments and the reading of other ports etc. But again, it works when going slow.
Some further background is that this instrument is going to be attached to the head of a barrel that's going to be shoved down 3-6 meters into the seafloor to gather a core samle.
Hi,
Ops 485 to 232 board,
How are you powering the drawstring?
Doesn't the device have any info on it, or is it custom made and the drawstring unit is inside the housing?
TolpuddleSartre:
What happens when you increase the speed of Serial?
But we can't since we have to adapt to the instruments baud rate that we can't alter? And if the manufacturer could get it to work in 19200 it should be possible...
We continue experimenting with additional flags and buffert-variables, and have seen some improvements.
TomGeorge:
Hi,
Ops 485 to 232 board,
How are you powering the drawstring?
Doesn't the device have any info on it, or is it custom made and the drawstring unit is inside the housing?
Thanks.. Tom...
We power the instrument (real name Penetration logger) with external 12 volts. Yea its custom made...
Half of it is drawstring housing and half is a water proof housing with some intelligence.
The data string out of the instrument pulses slowly + + + + + + + + + + + +
But when you pull the string A:s appear in o much higher frequency... As we've seen just monitoring it.
TomGeorge:
Hi,
What does;
digitalWrite(MAX485_DE, 0);
do?
Tom...
It tells the RS485 to RS232 converter which mode, in our case to read. Its hooked up to the pins DE and RE on the converter.
But we can't since we have to adapt to the instruments baud rate that we can't alter? And if the manufacturer could get it to work in 19200 it should be possible...
I wrote that you should increase the speed of Serial.
I wrote nothing about Serial3.
A baud rate of 300 can transmit 30 signs a second wikipedia says, so 9600 should be enough.
So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.
TolpuddleSartre:
So my 3.84 ms-1 is way out.
So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.
You do the arithmetic.
Another way to look at it is this. For every character that comes in, you send out at least 8 (0.0025) at half the speed. Is it any wonder why you loose incoming data?
Get out of the stone ages. 9600 baud went out with 8 track players.
TolpuddleSartre:
So my 3.84 ms-1 is way out.
So, every 2.5mm the cord moves, you receive a character.
The character takes around half a millisecond to transmit.
You then print a floating point number with four places after the decimal and a newline, and each character takes around 1 millisecond.
You do the arithmetic.
I think 1 m/s is good enough! Receiving rate is 19200, should be good enough.
PaulS:
Another way to look at it is this. For every character that comes in, you send out at least 8 (0.0025) at half the speed. Is it any wonder why you loose incoming data?
Get out of the stone ages. 9600 baud went out with 8 track players.
It doesn't matter, that baud rate that we're sending with is good enough, it's just for display.
But with the initial code the whole calculation was wrong. As long its the right value on the draw string variable we're happy. So it was probably an issue with over writing or similar.
As said, it seem to be working now with this buffer we included, we'we also tweaked down the array size quite a bit and its still happy. To long array and it stayed in the for-loop so long it was noticeable.