Hi All.
I've been searching all over the web for this problem. I Can't find anny tutorials that works.
I have a Arduino Duemilanove, with a temp sensor, 2 led lights and two pushbuttoms.
What I wanna do, is to make a software for windows in visual basic.
And I need to communicate between Arduino and computer.
I've made a soft and managed to turn led on of by pressing buttoms on skreen, but I don't manage to show temp sensor value in visual basic.
Later I'd like to have several temp sensors showing on screen.
Annyone know how to read serial communication from arduino?
HEEEELP :-/
-Andy
- Code *
- arduino *
#include <math.h>
int ledPin = 10; // the number of the LED pin
int buttonPin2 = 2; // the number of the pushbutton pin
int incomingByte;
double Thermistor(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = (Temp - 273.15); // Celcius
//Temp = ((Temp * 9.0)/ 5.0 + 32.0); // Fahrenheit
return Temp;
}
void setup() {
Serial.begin(19200);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
}
void loop(){
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 'A') {
digitalWrite(ledPin, HIGH);
}
if (incomingByte == 'B') {
digitalWrite(ledPin, LOW);
}
}
Serial.println(int(Thermistor(analogRead(0))));
//delay(100);
}
- Visual Basic *
Imports System.IO
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Shared _continue As Boolean
Shared _serialPort As SerialPort
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With SerialPort2
.Close()
'Set the serial port you want to use.
.PortName = "COM6" 'You MUST put 'COM' before the COM number.
'Set baud rate, parity, data bits, and stop bits.
.BaudRate = 19200
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
'Set DTR and RTS
.DtrEnable = True
.RtsEnable = True
'Set number of bytes before DataRecieved event is raised.
.ReceivedBytesThreshold = 1
'Open serial port.
.Open()
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SerialPort2.Write("A")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort2.Write("B")
End Sub