Counter Data Formatting

We are using a Delta ROV Counter. We want to send the data in the format “$ ,meter /r”. We have tried the software that is provided the winch but we can’t put the comma after the value. So please help us to make the format.

Didn’t we fix this a couple days ago with a new arduino program?

Can u pls share that code? Or where it is available?

are you with Searover?

No We are Eyerov from india

Oh, sorry, I literally did this last week :slight_smile: What a coincidence.

I am going to need to log on your PC and reprogram the counter.

Hello,

You need to download and install the arduino IDE.

Create a sketch and paste this:

/* Counter-Searover.ino V1.0
 * By Etienne Demers
 * This sketch is for communication with the encoder for the DROV-CNT-001
 * Output is $0.000,meterCrLF
 */
 
#include <Encoder.h>

//Define the Encoders
Encoder Cable(2, 3);
long lCable;

char distance[100];
float Calc;
float MyMultiplier;

void setup() {
Serial.begin(38400); 
}

void loop() {
  // put your main code here, to run repeatedly:
  lCable = Cable.read();
  
  MyMultiplier = 0.001;
  Calc = lCable/4*0.3*MyMultiplier;

  Serial.print("$");

  dtostrf(Calc, 5, 3, distance);
  Serial.print(distance);
  Serial.print(",meter\r\n");

  delay(500);
}

You will need to install the Encoder library from Paul Stoffregen:
image

You will need to select the Arduino Nano and the old bootloader. Then upload the sketch.

image

Let me know if you require me to remote in and do this for you.

Cheers,
E.

We have programmed and working on it now. Can u pls share the code for changing it back to work with your software?

This is the original code:

/* Counter.ino V2.0
 * By Etienne Demers
 * This sketch is for communication with the encoder for the DROV-CNT-001
 * It allows configuration of the output string, BAUD rate and measurement unit
 * Configuration string is ^,#CMD,VALUE,|
 */
 
#include <Encoder.h>

//Define the Encoders
Encoder Cable(2, 3);
long lCable;

const byte numChars = 100;
char receivedChars[numChars];
boolean newData = false;
String MyString;

#include <EEPROM.h>
#include "EEPROMAnything.h"

struct config_t
{
  char StartChar[1];
  char Hashtag[25];
  char Prefix[25];
  char Suffix[10];
  char StopChar[1];
  boolean Separator;
  int Interval;
  char Unit[2];
  char BAUD[1];
} configuration;

char distance[100];
float Calc;
float MyMultiplier;

void setup() {
  EEPROM_readAnything(0, configuration);
 
  // put your setup code here, to run once:
  if (configuration.BAUD[0] == '1') {Serial.begin(9600);}
  else if (configuration.BAUD[0] == '2') {Serial.begin(19200);} 
  else if (configuration.BAUD[0] == '3') {Serial.begin(38400);} 
  else if (configuration.BAUD[0] == '4') {Serial.begin(57600);} 
  else if (configuration.BAUD[0] == '5') {Serial.begin(115200);} 
  else {Serial.begin(9600);} 
}

void loop() {
  // put your main code here, to run repeatedly:
  lCable = Cable.read();
  
  
  if (configuration.Unit[0] == 'M') {MyMultiplier = 0.001;}
  else if(configuration.Unit[0] == 'f') {MyMultiplier = 0.00328083989501;}
  else {MyMultiplier = 1;}
  Calc = lCable/4*0.3*MyMultiplier;
    
  if (configuration.StartChar != "") {Serial.print(configuration.StartChar[0]);}
  if (configuration.Separator) {Serial.print(",");}

  if (configuration.Hashtag != "") {Serial.print(configuration.Hashtag);}
  if (configuration.Separator) {Serial.print(",");}
 
  if (configuration.Prefix != "") {Serial.print(configuration.Prefix);}

  dtostrf(Calc, 5, 3, distance);
  Serial.print(distance);

  if (configuration.Suffix != "") {Serial.print(configuration.Suffix);}

  if (configuration.Separator) {Serial.print(",");}
  if (configuration.StopChar != "") {Serial.print(configuration.StopChar[0]);}
 
  Serial.println();



  
    GetSerial();
    if (newData == true) {
        //Do whatever needs doing when new data is received.
        if (GetHashtag("#COUNTER_RESET")= '1') { Cable.write(0);}

        MyString = GetHashtag("#COUNTER_SET");
        if (MyString != "Null") {Cable.write(MyString.toInt()*4/0.3);}

        MyString = GetHashtag("#STARTCHAR");
        if (MyString != "Null") {
          configuration.StartChar[0] = MyString.charAt(0);
          Serial.println(MyString.charAt(0));
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }

        MyString = GetHashtag("#HASHTAG");
        if (MyString != "Null") {
          MyString.toCharArray(configuration.Hashtag, 25);
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
          
        MyString = GetHashtag("#PREFIX");
        if (MyString != "Null") {
          MyString.toCharArray(configuration.Prefix, 25);
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
          
        MyString = GetHashtag("#SUFFIX");
        if (MyString != "Null") {
          MyString.toCharArray(configuration.Suffix, 10);
          //configuration.Suffix = MyString;
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }

        MyString = GetHashtag("#STOPCHAR");
        if (MyString != "Null") {
          configuration.StopChar[0] = MyString.charAt(0);
          Serial.println(MyString.charAt(0));
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
          
        MyString = GetHashtag("#SEPARATOR");
        if (MyString != "Null") {
          if (MyString != "TRUE") {configuration.Separator = false;}
          else {configuration.Separator = true;}
          Serial.println(String(configuration.Separator));
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
          
        MyString = GetHashtag("#BAUD");
        if (MyString != "Null") {
          configuration.BAUD[0] = MyString.charAt(0);
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }

        MyString = GetHashtag("#INTERVAL");
        if (MyString != "Null") {
          configuration.Interval = MyString.toInt();
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
          
        MyString = GetHashtag("#UNIT");
        if (MyString != "Null") {
          MyString.toCharArray(configuration.Unit, 2);
          //configuration.Suffix = MyString;
          Serial.println(MyString);
          EEPROM_writeAnything(0, configuration);
          delay(1000);
          }
        
        newData = false;
    }
    delay(configuration.Interval);
}

void GetSerial() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '^';
    char endMarker = '|';
    char rc;

    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

String GetHashtag(String Hashtag) {      // Get the string next to the hashtag
  char MyChars[numChars];
  char * myPointer; // this is used by strtok() as an index
  char cHashtag[sizeof(Hashtag)]; //this char is used to pass the Hashtag to Strstr function
  
    strcpy(MyChars, receivedChars); //copy the received chars to allow manipulation
    Hashtag.toCharArray(cHashtag, sizeof(cHashtag)); //load the hashtag into chashtag

    myPointer = 0; //ensures the pointer is at 0
    myPointer = strstr(MyChars,cHashtag); //look for hashtag
   
    if (myPointer != 0) { //if the strstr finds something proceed
      myPointer = strtok(myPointer,","); //load the pointer with strtok
      myPointer = strtok(NULL, ",");  //skip to the next value past the comma
      strcpy(MyChars, myPointer); // copy the pointer to a char array
      return MyChars; //return the char array and convert it to a string
    } 
    else {return "Null";} //if all fails return null
}