- Mon Jan 05, 2015 3:55 pm
#178379
I believe that only certain pins can be used for Rx when using SoftwareSerial library. Which pins on the Pro-Mini support SoftwareSerial Rx?
Where electronics enthusiasts find answers.
#define LINE_START 0
#include <Arduino.h>
#include <SoftwareSerial.h> // http://arduino.cc/en/Reference/softwareSerial
const byte RS485_A_PIN = 13; // Rx Pin
const byte RS485_B_PIN = 12; // Tx Pin
SoftwareSerial windTracker(RS485_A_PIN, RS485_B_PIN); // (Rx, Tx)
void setup()
{
windTracker.begin(9600); // opens serial port, sets data rate to 9600 bps
Serial.begin(9600);
delay(4000);
Serial.println("RS-485 test");
delay(500);
}
void loop()
{
readData();
}
void readData()
{
char windSpeed[5];
char windDirection[4];
byte b;
if (windTracker.available() > 25)
{
b = windTracker.read();
if ( b == LINE_START)
{
for (byte s = 0; s < 4; s++)
{ windSpeed[s] = windTracker.read(); }
windSpeed[4] = '\0';
windTracker.read(); // read the space character
for (byte d = 0; d < 3; d++)
{ windDirection[d] = windTracker.read(); }
windDirection[3] = '\0';
float windSpeedKnots = atof(windSpeed) * 1.94384;
int iWindDirection = atoi(windDirection);
Serial.print(windSpeedKnots);
Serial.print("\t");
Serial.println(iWindDirection);
}
}
}