Hi
i'm running a sketch on my arduino uno, connected to an app on my pc (windows 7, 64bit).
it uses serial communication to connect, and it works fine for about one hour (it's very inaccurate, sometimes 20 minutes, sometimes 5 hours) and then it suddenly seems to 'switch' COM port.
When I connect my arduino, it says COM3, wich is my arduino. After a while it suddenly seems to connect to a new COM port, COM4. This means the old one is still active (COM3, since the number increases), but is not recognized anymore.
i have no idea on how to solve the problem, since i don't do anything special but Serial.read() and Serial.println()
here's the arduino code:
#include <PinChangeInt.h>
#include "profiles.h"
#define FBLED 11
#define FBBTN 10
#define TWTLED 9
#define TWTBTN 8
#define MAILLED 6
#define MAILBTN 7
#define RSSLED 3
#define RSSBTN 2
#define ONLED 5
#define dataStart 1 //start of heading
#define dataEnd 4 //end of transmission
#define notifData 17 //device control 1
#define msgData 18 //device control 2
#define frndData 19 //device control 3
#define delData 20 //clear all facebook data
Profile fb(FBLED, FBBTN);
Profile twt(TWTLED, TWTBTN);
Profile mail(MAILLED, MAILBTN);
Profile rss(RSSLED, RSSBTN);
bool done = true;
unsigned long pingTmr = millis();
void setup()
{
Serial.begin(9600);
/*
fb.msgs = 1;
twt.ntfs = 9;
mail.mail = 3;
rss.feed = 11;
*/
PCintPort::attachInterrupt(FBBTN, sendFacebookRequest,RISING);
PCintPort::attachInterrupt(TWTBTN, sendTwitterRequest,RISING);
PCintPort::attachInterrupt(MAILBTN, sendMailRequest,RISING);
PCintPort::attachInterrupt(RSSBTN, sendRssRequest,RISING);
analogWrite(ONLED, 150);
}
void loop()
{
while(Serial.available()>1)
{
int tmpByte = Serial.read();
if(tmpByte == notifData)
fb.ntfs = Serial.read();
else if(tmpByte == msgData)
fb.msgs = Serial.read();
else if(tmpByte == frndData)
fb.frnd = Serial.read();
else if(tmpByte == delData)
{
fb.setNull();
analogWrite(fb.ledPin, 0);
}
}
updateAll();
}
void updateAll()
{
fb.update();
twt.update();
mail.update();
rss.update();
}
void sendFacebookRequest()
{
Serial.println("facebookHTTP");
fb.setNull();
analogWrite(fb.ledPin, 0);
}
void sendTwitterRequest()
{
Serial.println("twitterHTTP");
twt.setNull();
analogWrite(twt.ledPin, 0);
}
void sendMailRequest()
{
Serial.println("mailHTTP");
mail.setNull();
analogWrite(mail.ledPin, 0);
}
void sendRssRequest()
{
Serial.println("rssHTTP");
rss.setNull();
analogWrite(rss.ledPin, 0);
}
#include "Arduino.h"
#ifndef profiles_h
#define profiles_h
struct Profile
{
volatile uint16_t msgs;
volatile uint16_t ntfs;
volatile uint16_t frnd;
volatile uint16_t mail;
volatile uint16_t feed;
volatile uint16_t total;
volatile uint16_t alerted;
volatile uint8_t ledState;
uint8_t ledPin;
uint8_t btnPin;
unsigned long lastMillis;
Profile(uint8_t, uint8_t);
void update();
void setNull();
};
void sendFacebookRequest();
void sendTwitterRequest();
void sendMailRequest();
void sendRssRequest();
#endif
#include "profiles.h"
#define ONLED 5
void sendFacebookRequest();
void sendTwitterRequest();
void sendMailRequest();
void sendRssRequest();
Profile::Profile(uint8_t _led, uint8_t _btn)
{
msgs = 0;
ntfs = 0;
frnd = 0;
mail = 0;
feed = 0;
total = 0;
alerted = 0;
lastMillis = millis();
ledState = 0;
ledPin = _led;
btnPin = _btn;
pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT);
}
void Profile::update()
{
total = msgs + ntfs + frnd + mail + feed;
//total = (total>=5) ? 5 : total;
if(millis() - lastMillis > 500)
{
if(alerted < total)
{
if(ledState == 255)
ledState = 0;
else
{
ledState = 255;
alerted++;
}
analogWrite(ledPin, ledState);
}
else if(total > 0)
analogWrite(ledPin, 255);
lastMillis = millis();
}
}
void Profile::setNull()
{
msgs = 0;
ntfs = 0;
frnd = 0;
mail = 0;
feed = 0;
total = 0;
alerted = 0;
ledState = 0;
}
the PC code I use to write to the arduino is this:
Dim tmpByteList As Byte() = {17, notifs, 18, Asc(msgsStr) - 48, 19, friends}
notifCom.Write(tmpByteList, 0, 6)
with notifCom being the serial port (arduino)
I don't have any other commucation but this, which happens once a minute.
thanks for reading this, and hopefully it can get solved.
Nick