SoftwareSerial data transmission (Solved)

Hi, I have been trying to send float data from one module to another. I want to convert the float temperature data to a string and send the string. I can do the first part but when I try to Do Serial.print(TempStr); I get random numbers on the receiver hand. I don't want to convert it to binary and I need to do this as quickly as possible! Thanks for your help.

Thoughts and prayers without your code.

My original code has some other stuff in it but this is an example of what I want

//transmitter
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11);
void setup() {
  Serial.begin(9600);
  HC12.begin(9600);
}
void loop()
{
  HC12.write("Test");
}
//reciever
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11);

void setup() {
  Serial.begin(9600);
  HC12.begin(9600);
}
void loop() {
  while (HC12.available())
  {

    Serial.println(HC12.read());
  }
}

I want the receiver to print “Test”

I want the receiver to print "Test"

Does it by any chance print T e s t

I need to do this as quickly as possible

When is your assignment due?

No but I kinda figured it out it prints 84 101 115 116 which is decimal for Test so I did something and right now it does what you are saying T e s t

jremington: When is your assignment due?

I need it by tomorrow night

Ok so what I really need is, I have about 15 different float values (some of them are integers) I need to send these values within a specific order using SoftwareSerial.

so I did something

Are you going to let us in on the secret of what you did ?

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

float value = Serial.parseFloat();

This will read the next numeric value from your input stream.

If each line of input only has one number:

  if (Serial.available())
  {
    float value = Serial.parseFloat();
    while (Serial.available())
      Serial.read(); // Clear out any characters left in the buffer
    if (value - (int)value < 0.0001)
    {
      // Integer
      Serial.println((int)(value + 0.5));
    }
    else
    {
      // Float
      Serial.println(value);  // Will show 2 decimal places by default
    }
  }

The part that tries to tell Integer from Float probably won’t work right with negative numbers.

masterrg:
I need it by tomorrow night

So I tried decimal to the ASCII method, but if I add the other values data will get corrupted.
What I need is to send about 15 different float/double values using software serial.
Thanks for your help btw.

johnwasser:

float value = Serial.parseFloat();

This will read the next numeric value from your input stream.

If each line of input only has one number:

  if (Serial.available())

{
    float value = Serial.parseFloat();
    while (Serial.available())
      Serial.read(); // Clear out any characters left in the buffer
    if (value - (int)value < 0.0001)
    {
      // Integer
      Serial.println((int)(value + 0.5));
    }
    else
    {
      // Float
      Serial.println(value);  // Will show 2 decimal places by default
    }
  }



The part that tries to tell Integer from Float probably won't work right with negative numbers.

I tried this and it didn’t work

"It didn't work" is the lamest problem description possible.

Really, read and play with Robin2's serial input basics tutorial.

masterrg:
I tried this and it didn’t work

Works fine for me for positive values. As I mentioned, it doesn’t correctly identify integers less than 0.
This version fixes the problems with negative numbers:

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


void loop()
{
  if (Serial.available())
  {
    float value = Serial.parseFloat();
    while (Serial.available())
      Serial.read(); // Clear out any characters left in the buffer


    int rounded = value + 0.5;
    if (value < 0)
      rounded = value - 0.5;


    float decimal = value - rounded;


    if (decimal < -0.00001 || decimal > 0.00001)
    {
      // Float
      Serial.println(value);  // Will show 2 decimal places by default
    }
    else
    {
      // Integer
      Serial.println(rounded);
    }
  }
}