Arithmetic Operation Using Arduino

Hye,

I want to do some arithmetic operation (addition) on Arduino by using RS232 as serial communication. The sensor that I used is Ludlum 375 to detect radiation. From the coding I attached, I only get the output = 7.0 instead of ex: 7.0000010 (ludlum output + 7.0) where the value of 0.0000010 is the ludlum output.

#include<SoftwareSerial.h>

SoftwareSerial gtSerial(1,2);          //Rx,Tx
byte rx_byte = 0;                      //Store Data byte incoming data from Ludlum 375/2
String inString = "";
String inString2 = "";
String MyString;
String MyFinalString;
String endstring = "000010\r\n";
char myChar2[15];

void setup(){
   Serial.begin(2400);                   //open port for serial port 1
   gtSerial.begin(2400);                 //open port for serial port 2
  }
  void loop() { 

if (Serial.available()) {
    char inChar = Serial.read();          //declare inChar
    char myChar = inChar;                 //declare myChar
    
    inString = myChar;
    Serial.print(inString);

inString2 = inString.substring(1,6);

  //Serial.println(inString);
  //Serial.println(inString2);
  float b = inString2.toFloat();          //convert string to float
  Serial.print(inString2);
  Serial.println(b);
  float a = 7.0;
  float c = a+b;
  
  MyString = String (c,1);
  MyFinalString = "000"+ MyString + endstring;

  delay (500);
 
 MyFinalString.toCharArray(myChar2,15);
 //Serial.println(myChar2);
   gtSerial.write(myChar2);

 }}

Ludlum 375:

https://www.bing.com/images/search?view=detailV2&ccid=UvkDlPbW&id=D0BC6868993E104235FA557B82D901256524A65A&thid=OIP.UvkDlPbWhBOltkRby2WWHAHaFk&mediaurl=https%3A%2F%2Fludlums.com%2Fimages%2Fcom_hikashop%2Fupload%2Fm375.jpg&exph=1354&expw=1800&q=ludlum+375&simid=608045173166377748&ck=DF5D13CDEBDFD48408D163318F88FB3F&selectedIndex=0&FORM=IRPRST&ajaxhist=0

What processor board are you using? 32-bit or 64-bit floats? Your expectations of accuracy / resolution may be unrealistic.

I'm using Arduino Uno with IC max 232 as the serial interface.

Then, you can expect 6 (maybe 7) significant figures when using the only float type available on an 8-bit AVR ---- 32-bit, single precision.

gfvalvo:
Then, you can expect 6 (maybe 7) significant figures when using the only float type available on an 8-bit AVR ---- 32-bit, single precision.

Thank you sir, can you help me to figure out the problem on my command in Arduino because the output that I get is seems like it cannot detect the arithmetic operation that I write.

lilynatasha:
Thank you sir, can you help me to figure out the problem on my command in Arduino because the output that I get is seems like it cannot detect the arithmetic operation that I write.

Well, he did figure out the problem, just not a solution. We're not magicians here, if something is impossible, then there isn't a solution. the 'toFloat()' method of the String class is limited to the same limitations as the underlying data type 'float'. I suggest moving to a different board, using a 32 bit processor as mentioned. Try a Blue Pill if you're short on money.

You could also look at the Arduino arbitrary precision arithmetic library for such calculations:

Can you give an example of a “Data Frame” that is coming from Ludlum 375?

It is important to know the frame structure so that it can be correctly detected by the Soft Serial Port (SUART Port) of UNO. Is there any pre-amble (Marker for beginning of frame) and post-amble (Marker for ending of frame)?

Just run the following sketch and check if there is anything being printed on the Serial Monitor of UNO. This is a function check of UNO+SUART Port + TTL<---->RS232 Converter + Ludlum 375.

#include<SoftwareSerial.h>
SoftwareSerial gtSerial(3, 2);         //Rx,Tx; do not use DPin-0, 1 

void setup()
{
  Serial.begin(2400);                   //open port for serial port 1
  gtSerial.begin(2400);                 //open port for serial port 2
}

void loop()
{
  byte n = gtSerial.available();
  if( n!= 0)
  {
    char x = gtSerial.read(); //expecting ASCII coded bytes are coming from Ludlum 375
    Serial.print(x);
  }
}