Hello,
I tried to look on the forum but I couldn't find a simple solution to my problem.
I am writing a VB app which would receive data from Arduino (using Firmata library).
I was able successfully to write a small app which would read analog values from Arduino.
#include <Firmata.h>
void setup()
{
Firmata.setFirmwareVersion(0, 2);
Firmata.begin(57600);
}
void loop()
{
while(Firmata.available())
Firmata.processInput();
delay(10);
Firmata.sendAnalog(0, analogRead(0));
}
Imports Firmata.FirmataVB
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FirmataVB1.Connect("COM3", 57600)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.AppendText(FirmataVB1.AnalogRead(0) & vbCrLf)
End Sub
End Class
The timer in the VB is set to 100 and basically outputs whatever value Arduino Analog(0) reads.
But what I actually wanted is much simpler and I am having difficult time finding a simple solution.
My app in Arduino does some simple calculations. It monitors the vibration of the oil-boiler (I wanted to find out if it is running or not & for how long).
I have a sensor attached and taking sample data every 10ms. If certain conditions will be met the LED on the board lights up. That is the moment I would like the VB app to be notified about this event. So the app can run for 2 hours, and no data might be sent and when the boiler will start burning oil the alert will be send to the VB app. My VB app calls Oracle database for further processing.
I would like the VB app to be notified also when the boiler will turn off. So this is the second event.
Below is the Arduino code. I marked those 2 places when I would like Arduino to call VB (using Firmata I suppose?).
If someone could help me with this one I would appreciate it.
I need to know the command which would basically send a string or a digit (0 or 1) to VB.
I also need to know with what command I can receive that signal in the VB app. Do I have use the timer also?
I am afraid I will run into problems when I will have one timer on Arduino board, and another timer in the VB. Would be great to have some synchronization - but that's probably for another day.
#include <Firmata.h>
int r1 = 0;
int r2 = 0;
int alert1 = 0;
int alert2 = 0;
int alert3 = 0;
int run = 1;
int redlight = 0;
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop()
{
r1 = analogRead(A0);
delay(10);
r2 = analogRead(A0);
delay(10);
if (run == 1)
{
if (r1>r2) { if((r1-r2)>20) { alert1 = 1; } else { alert1 = 0; } }
if (r2>r1) { if((r2-r1)>20) { alert1 = 1; } else { alert1 = 0; } }
run = run + 1;
}
else if (run == 2)
{
if (r1>r2) { if((r1-r2)>20) { alert2 = 1; } else { alert2 = 0; } }
if (r2>r1) { if((r2-r1)>20) { alert2 = 1; } else { alert2 = 0; } }
run = run + 1;
}
else if (run == 3)
{
if (r1>r2) { if((r1-r2)>20) { alert3 = 1; } else { alert3 = 0; } }
if (r2>r1) { if((r2-r1)>20) { alert3 = 1; } else { alert3 = 0; } }
run = 1;
}
else
{
run = 1;
}
// Going from sleep mode
if( redlight == 0)
{
if (alert1 == 1 and alert2 == 1 and alert3 == 1)
{
redlight = 1;
// call VB app that the value changed from 0 to 1 ********************************** <----- 1st Event
}
else
{
redlight = 0;
}
}
// Going from active mode
if( redlight == 1)
{
if (alert1 == 0 and alert2 == 0 and alert3 == 0)
{
redlight = 0;
// call VB app that the value changed from 1 to 0 ********************************** <----- 2nd Event
}
else
{
redlight = 1;
}
}
if(redlight == 0)
{
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if(redlight == 1)
{
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
}
delay(1000);
}