Hi there guys i am having a problem with code in Visual Studio...and i need an expert opinion
i have the arduino and DHT22 sensor,when opening the Form1 a Timer send "1" thru the serial port.When "1" is recived on arduino,it send the temperature and humidity to the VS aplicacion.The problem i have is that,since the data send by arduino is more than one character (with Serial Monitor my data looks exactly like this "24.90 Celsius 32.0% Humidity" ) i belive the Form cannot interpretate the data and gives me this error {"Conversion from string "24.90 Celsius 32.0% Humidity"to type 'Integer' is not valid."}
The code of Visual Studio is:
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Dim SReaderT1 As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.Close()
SerialPort1.PortName = "com17" 'change com port to match your Arduino port
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Encoding = System.Text.Encoding.Default
End Sub
Dim TemperatureHumidity As Integer
Private Sub TimerTick_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerTick.Tick
Try
Finally
SerialPort1.Open()
SerialPort1.Write("1")
SReaderT1 = SerialPort1.ReadLine()
SerialPort1.Write("0")
SerialPort1.Close()
End Try
TemperatureHumidity = SReaderT1
ListBoxTemperature1.Items.Add(TemperatureHumidity) ''Add the Temp/Hum to ListBoxTemperature1''
ListBoxTemperature1.TopIndex = ListBoxTemperature1.Items.Count - 1 ''Count -1 i use it just to keep the data on top''
End Sub
End Class
i am stuck in here,is there other way to read the data?thank you all of you.