float or double, how to shift the decimal ?

Hello,
I use Arduino to drive a rf shield, this shield accept AT command, as bellow:

Serial.println(“AT+DMOSETGROUP=0,144.0000,144.0000,0000,4,0000”); //step/tx/rx/ctssrx/squelch/ctsstx

i have no issue with variable, except the frequency up/down for the TX and RX frequency (140.0000) i use float, so the result in serial monitor is:

0,144012.5000,144012.5000,0000,4,0000

and not like as except

0,144.01250,144.01250,0000,4,0000

what is the best way to shift the dot like as above ?

i have looked for var “double”, without any success

thx

#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);

#define DRA_RXD 7   // The Arduino IO line that is connected to the DRA818's TXD pin. 3.3V only
                  // We *receive* TTL 3.3V Serial from the DRA818 on this pin.
#define DRA_TXD 6   // The Arduino IO line connected to the DRA818's RXD pin.
                    // We *send* TTL serial to the DRA818 on this pin.

SoftwareSerial dra_serial(DRA_RXD, DRA_TXD);    //for DRA818

int bw = 0; // Bandwith in KHz (0 = 12.5KHz or 1 = 25KHz)
float freq_step = 12.5; // 12.5 or 25khz

float FTX;
float FRX;

String tx_ctcss = "0000"; // CTCSS frequency (0000 - 0038); 0000 = "no CTCSS"
String rx_ctcss = "0000"; // CTCSS frequency (0000 - 0038); 0000 = "no CTCSS"
int squ; // Squelch level (0 - 8); 0 = "open"


//Rotativ encoder
volatile boolean modif;
volatile boolean up;
#define PINA 2
#define PINB 3
#define INTERRUPT 0 


void setup ()
{
  
  lcd.init();
  lcd.clear();
  lcd.backlight();
  
  Serial.begin(57600);
  dra_serial.begin(9600);
  delay (10);
  dra_serial.println(F("AT+DMOSETVOLUME=8")); // Sound at 8 level
  dra_serial.println(F("AT+DMOSETGROUP=0,144.0000,144.0000,0000,4,0000")); // 12.5khz TX RX CTSS SQU CTSS

  //rotativ encoder
  digitalWrite (PINA, HIGH);     
  digitalWrite (PINB, HIGH); 
  attachInterrupt (INTERRUPT, Int, CHANGE);
    
  int i = 1;
  
}
//////////////////////////////////////////////////////////////////////////////
// Interrupt
void Int()
{
  if (digitalRead (PINA))
    up = digitalRead (PINB);
  else
    up = !digitalRead (PINB);
  modif = true;
} 
//////////////////////////////////////////////////////////////////////////////
void loop()
{  
  frequence();
  freq_send();
}
//////////////////////////////////////////////////////////////////////////////

[b]void frequence()
{
    {
    if (modif)
  { 
    if (up) FTX = constrain( FTX + freq_step, 144000, 146000);
    else    
    FTX = constrain( FTX - freq_step, 144000, 146000);
    modif = false;     
   { 
    if (up) FRX = constrain( FRX + freq_step, 144000, 146000);
    else    
    FRX = constrain( FRX - freq_step, 144000, 146000);
    modif = false;      
  }
  }
  lcd.setCursor(0, 0);
  //lcd.print ("TX");
  lcd.print (FTX); 
  }
  {
  lcd.setCursor(0, 1);
  //lcd.print ("RX");
  lcd.print (FRX); 
  }[/b]

}

void freq_send()
{
  //"AT+DMOSETGROUP=0,144.0000,144.0000,0000,4,0000"  
  //dra_serial (9600);
  //delay (10);
  dra_serial.print ("AT+DMOSETGROUP="); // Begin message
  dra_serial.print (bw, 1);
  dra_serial.print (",");
  dra_serial.print (FTX,4);
  dra_serial.print (",");
  dra_serial.print (FRX,4);
  dra_serial.print (",");
  dra_serial.print (tx_ctcss);
  dra_serial.print (",");
  dra_serial.print (squ);
  dra_serial.print (",");
  dra_serial.println (rx_ctcss);

  // Serial Arduino debug
  Serial.print(bw,1);
  Serial.print(",");
  Serial.print(FTX,4);
  Serial.print(",");
  Serial.print(FRX,4);
  Serial.print(",");
  Serial.print(tx_ctcss);
  Serial.print(",");
  Serial.print(squ,1);
  Serial.print(",");
  Serial.println(rx_ctcss);
}

Don't use float, it has round-off errors. Build it piece by piece with integers and '.'.

What do you suppose this line does:

  dra_serial.print (FTX,4);

What happens when you change it to:

  dra_serial.print (FTX,2);

if you want to go from 14000 to 140, you divide by 100? Am I missing anything?

econjack: What do you suppose this line does:

  dra_serial.print (FTX,4);

What happens when you change it to:

  dra_serial.print (FTX,2);

0,144012.50,144012.50,0000,1,0000

KeithRB: Don't use float, it has round-off errors. Build it piece by piece with integers and '.'.

yes but how to store 12.5 value ? if float is not a good candidate ?

Simply don't store 12.5 but 125 and print a point. Store it in the resolution you want. If you want mm resolution, save it in mm even if you want to print cm. Converting it to cm isn't that hard. Same his here.

byte var = 125;

Serial.print(var / 10);
Serial.print('.');
Serial.print(var % 10);

Or wrap it nicely in a function.

Surely printing spaces between values is a reasonable thing to do.

Thereseemstobenogoodreasontocrameverythingtogether.

CTSS tone frequencies are always rounded to 1/10ths. I doubt that you have to send anything more than "144" or maybe "144.0" to the AT command.

aarg: CTSS tone frequencies are always rounded to 1/10ths. I doubt that you have to send anything more than "144" or maybe "144.0" to the AT command.

its not CTSS, its the frequency, i'll not use CTSS, so i leave 0000,0000 without problems. my goal is to start from 144.0000 and end to 146.0000 with 12.5 or 25khz

i only use var for squelch, step 12.5/25k, and frequency, but frequency value use "." so i don't know how to combine 144 plus the step value

like: ("AT+DMOSETGROUP=0,144.0125,144.0125,0000,1,0000") ("AT+DMOSETGROUP=0,144.0250,144.0250,0000,1,0000") ("AT+DMOSETGROUP=0,144.0375,144.0375,0000,1,0000") ("AT+DMOSETGROUP=0,144.0500,144.0500,0000,1,0000") ("AT+DMOSETGROUP=0,144.0625,144.0625,0000,1,0000")

thx you all, i 'll looking for a solution with your informations, and i'll do some test when i'll get the shield.

By the way, what region are you in? Because transmitting at 144.0125 Mhz could walk on some very sensitive spectrum in most places.

aarg: By the way, what region are you in? Because transmitting at 144.0125 Mhz could walk on some very sensitive spectrum in most places.

144 to 146 is HAM 2 meters (i'm in EU), no problem if you got a license

finally i have fixed my issue with float

thx everybody