Serial question, sending sensor data from MicroView/Uno to Uno

Hi everyone!

Though using a MicroView, so far the basics are just like the Uno. But mentioned anyway.

I have a serial connection functioning with characters (like words) but unable to see why the data is different to what's being sent.

I've tried copying many other serial scripts with this one being the closest yet to working. The MicroView has a temperature sensor and I need to send this information to the Uno.

The sender has a temperature sensor, so I'm simulating the 18.50 here.

Sender code:

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
}

void loop() {
  Serial.println(18.50);
  delay(1000);
}

Receiver code:

int incomingByte = 0; // for incoming serial data

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, 5);
  }
}

For some reason, I'm getting this;

The byte size was set to 5 so even when changing that, no impact.

I even changed the sender value to 3 digits, with no change.

The 5 means you're printing results in base 5.
Lose it.

If you're expecting to see "18.50" at the receiver, you've got some work to do - the values you receive are ASCII.

Thanks for helping!

I've removed it, now receiving;

It's like a really bad rounding.

No that's really good ASCII, in decimal.

49 == '1' == 0x30
56 == '8' == 0x38

Sorry, I didn't see the end of your message.

That makes sense.

So I would be better converting the float into an integer, then converting from ascii to a number.

Any other advice on how to transmit data from the devices? I hit a brick wall with i2c but maybe that's seeming like I'll need to go over it again.

If I wanted to send and receive a float as accurately as possible, I'd use Serial write to send all four bytes of the float value as binary, but that throws up all kinds of synchronisation issues.

Tell us what you want to do, not how you think it should be done.

(I2C at 100kHz will be faster than serial at 9.6kHz)

Sorry mate, I guess I was trying to have a go before I just posted the desired outcome and look like I wanted it all done for me.

I want to collect data from a LM35DZ temperature sensor using a MicroView and transmit it to an Uno.

Once the Uno can see it, I plan to data log it. But just needed help getting it from the MicroView.

Here's my working sensor code, I had planned to then add in working serial program afterwards and exchange the temperature value into the fixed number location somehow.

#include <MicroView.h>
#define LM35Pin 0
 
float Temperature;
 
void setup()
{
  Serial.begin(9600); 

  analogReference(INTERNAL);

  uView.begin();        // start MicroView
  uView.clear(PAGE);      // clear page
  uView.print("Grrrrrr");  // display HelloWorld
  uView.display();
}
 
void loop()
{
  Temperature = analogRead(LM35Pin) / 9.31;
  Serial.print("Current temperature (oC): ");
  //Serial.println(Temperature);
  Serial.print(Temperature,5);

  uView.clear(PAGE);      // clear page
  uView.display();
  uView.setFontType(0);
  uView.setCursor(0,0);
  uView.println("Temp:");
  uView.display();
  uView.setFontType(2);
  uView.print(Temperature);  // display HelloWorld
  uView.display();
   
  delay(1000);
}

Maybe Serial Input Basics - updated might give you some ideas; it describes options for the receiver side of the communication. You can test it with e.g. serial monitor.

Example 2 will basically be a match for your sender code although example 3 might be better after you have adjusted the sender. One of the examples shows how to convert from ascii to float using atof.

Exactly what I'm after, I'm just attempting a receiver script.

With little success lol... but trying :roll_eyes:

I've managed to make some progress. But if the Serial is used for anything other than the data, the output gets ruined.

I also only need the last four digits, but if I can't use the serial for anything else, I'm thinking maybe my MicroView i2c is damaged.

So far this is my closest shot to the answer....

Sender Code

#include <MicroView.h>
#define LM35Pin 0
 
float Temperature;

int value = 180;
 
void setup()
{
  Serial.begin(9600); 

  analogReference(INTERNAL);

  uView.begin();        // start MicroView
  uView.clear(PAGE);      // clear page
  uView.print("Grrrrrr");  // display HelloWorld
  uView.display();
}
 
void loop()
{

  Temperature = analogRead(LM35Pin) / 9.31;
  Serial.print("Current temperature (oC): ");
  //Serial.println(Temperature);
  Serial.print(Temperature,5);

  value = Temperature * 100;

  Serial.write(value / 256);
  Serial.write(value % 256);
   delay(500); // Allows all serial sent to be received together

  uView.clear(PAGE);      // clear page
  uView.display();
  uView.setFontType(0);
  uView.setCursor(0,0);
  uView.println("Temp:");
  uView.display();
  uView.setFontType(2);
  uView.print(Temperature);  // display HelloWorld
  uView.display();
   
  delay(1000);
}

Receiver Code

//Receiver Code

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

void loop() {
  int val;

      
      while (!Serial.available()){}
//delay(100); //allows all serial sent to be received together
    byte b1 = Serial.read();
    while (!Serial.available()){}
  //  delay(100); //allows all serial sent to be received together
    byte b2 = Serial.read();

    val = b2  + b1 *256 ; 
    Serial.println(val);
}

Comms receiver com output

Tempted on sensor output, 20.62!!!! Ignoring the multiplication, any thoughts how I can turn this into a number I can give a variable name in the code so the slave can save it to an SD card.

Is using the serial going to inhibit any other serial functions.