I am an Arduino newbie and working on my first real project (after doing a number of the exercises). The idea is to create a method of watering plants when a sensor reports that the moisture level is low (I am known for killing my herbs). Once working I will offer it to the family so want to keep the costs down. The system will be controlled by an application running on a serial connected PC, written in Visual Basic.net, which I am quite familiar with. The sketch code is:
/* Arduino Automatic Watering System
*/
#include <SoftwareSerial.h>
const int rxPin = 2; // pin used to receive data from PC
const int txPin = 3; // pin used to send data to the PC
SoftwareSerial serial_pc(rxPin, txPin); // new serial port on pins 2 and 3
int number = 0;
void setup() {
Serial.begin(9600); // built in serial port
Serial.println("On board port ready.");
serial_pc.begin(9600); // initialise PC serial port
Serial.println("Externsl port ready.");
}
void loop() {
//Check for operator input
funcAbort();
serial_pc.println(number);
delay(10);
//Serial.print("*");
Serial.println(number);
//Check for operator input
funcAbort();
delay(5000);
number ++;
}
// Functions
/* Read input from the operator via the Serial interface
RAT Replace with input from the network controller
*/
void funcAbort() {
int incomingByte;
char incomingChar;
while (Serial.available() > 0) {
//Read operator input byte by byte
// maybe use Serial.readBytes to get the whole string?
incomingByte = Serial.read();
incomingChar = char(incomingByte);
if (incomingChar == 'a') { // SIngle quotes for single characters
Serial.println();
Serial.println("Aborted");
delay(100);
//Exit with status zero (no errors)
exit(0);
}
else
{
Serial.print(incomingChar);
}
}
}
The circuit is simple as well, one connection from GND to the RS232 ground pin, Arduino pin 2 to the RS232 XMT pin and one from pin 3 on the Arduino to the RS232 RCV pin.
As I am new, I wrote a simple serial interface in VB.net and an Arduino sketch to test the link, and was dismayed when I saw the garbage I received on the PC when I ran the monitor. The serial monitor on the Arduino correctly showed a number counting up:
My monitor showed garbage instead of the expected numbers:
I assumed I has made a mistake in my monitor software, so I ran the sketch against a PuTTY serial monitor and got more garbage, which indicates to me the problem was at the Arduino end. After much Googling and searching the Forum I am at a loss to explain the problem The baud rates all match, though I experimented with different rates on the monitors to see if that had any affect (none).
So, can anybody see what I am doing wrong?