arduino code:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = {
0x28, 0x8A, 0xC2, 0xCD, 0x04, 0x00, 0x00, 0xA0 };
void setup(void)
{ Serial.begin(9600);
sensors.begin();
sensors.setResolution(insideThermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
}
//Serial.print("Inside temperature is: ");
//Serial.print("C: ");
Serial.print(tempC);
}
void loop(void)
{
sensors.requestTemperatures();
delay(2000);
printTemperature(insideThermometer);
}
C# code:
private void serialPort2_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string s= sp.ReadExisting();
label10.Invoke(this.myDelegate, new Object[] { s });
}
I want to simply write temperature from arduino too c# application label. If i do like in code above, it work for the first time that it sends the temperature the other times that arduino sends the temperatures i get just part of the temperature if lets say temperature is 23.50 C. Than the first time on the label it will be written 23.50 C, but when second time, third, etc... Will be just .50 or 23 etc. just parts of the temperature, what is the most simple way to write the temperature to C# app, I`m not soo good at programing so please help me with the simplest method.
Thank you for your answer in advance