Pages: [1]   Go Down
Author Topic: Seeking help for gmail notification led project  (Read 136 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Everyone!

I recently built a simple 5 LED email notification box that lights up when I have new emails. For the project I used a combination of a few other code-bits I found and pieced them together to work on Ubuntu. Essentially this is a 3 part process. The arduino is programmed to recieve eiather an 'M' or 'N' through the serial port. The 'M' and 'N' come from a small python program which uses feedparser to check my account for new emails. The python program currently runs in a loop in a shell script which checks gmail every 30 secounds.

HERE IS MY PROBLEM!

I am connected to the arduino through serial, I am successfully recieving if I have new mail or not (Using echo debug in python program and testing it), When the python program runs the lights are successful in flashing BUT they flash no matter what.

I am using a mail variable set to HIGH or LOW based on weither I recieve a "M" or "N" through the serial. The mail variable is then directly feed into my digitalWrite command like so..

 digitalWrite(outPin1, mail);

The problem is that no matter if the mail variable is high or low the lights are still blinking. If you all need me to post more info like the python program or shell script which I don't think is the problem then I certainly will! Here is the sketch im using and where the problem I believe lies...

// led wired + to pin 12, resistor to positive +5v

int outPin1 = 13; // Output connected to digital pin 13
int outPin2 = 12;
int outPin3 = 11;
int outPin4 = 10;
int outPin5 = 9;
int mail = HIGH; // Is there new mail?
int val; // Value read from the serial port
void setup()
{
 pinMode(outPin1, OUTPUT);
 pinMode(outPin2, OUTPUT);
 pinMode(outPin3, OUTPUT);
 pinMode(outPin4, OUTPUT);
 pinMode(outPin5, OUTPUT);
 Serial.begin(9600);
 Serial.flush();
 mail = HIGH; // start off with lights out
}

void loop()
{
 // Read from serial port
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val);

   if (val == 110) // n = 110 in dec
   {
     mail = HIGH;  // HIGH is off because led is connected to +5v on the other side
   }

   else if (val == 109) //109 = m in dec
   {
     mail = LOW; // LOW is on because led is connected to +5v on the other side
   }
 }

 // blinking series to run if mail is LOW
 delay(500);
 digitalWrite(outPin1, mail);
 delay(800);
 digitalWrite(outPin2, mail);
 delay(800);
 digitalWrite(outPin3, mail);
 delay(800);
 digitalWrite(outPin4, mail);
 delay(800);
 digitalWrite(outPin5, mail);
 delay(800);
}



Thank you a ton in advance for any advice/help you can give for this problem.

Happy Hacking,
Trent
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HERE IS AN IMAGE OF MY COMPLETED BOX!!! IT IS MADE OUT OF AN IPHONE 5 BOX!


Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code says "// blinking series to run if mail is LOW" but there is no check for the state of the mail variable, you run the blink sequence unconditionally. If you only want it to blink when mail is LOW, you need to add an "if(mail == LOW)" condition.

Also note that if you want to compare a received character with the character literals 'n' or 'm' you can just put those directly in your code - you don't need to specify the ascii code.

Code:
if (val == 110) // n = 110 in dec

Is identical to:

Code:
if (val == 'n')

In my opinion your code would be clearer if you made the mail variable a boolean which was set true/false to indicate the presence of mail, rather than mis-using the HIGH/LOW values.
« Last Edit: July 13, 2014, 06:15:05 pm by PeterH » Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok I will try this, thanks for pointing ansii out to my attention. Those notes are actually from the old program before I changed it so most don't apply. Thanks for the response
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made the changes you suggested. I changed mail to a boolean and used that to create if statements to run the lights how I want them to. Still, no matter what I do the first if statement is running even though my shell is telling me I have no new emails. Anyone else have an idea on this one?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took out some of the lights so i could just focus on getting it to work.. here is what it is currently at.
Now all the lights are ON for some reason? and I cant get them to turn off.. could it be a scope problem? I noticed I have 3 closing brackets at end?


// led wired + to pin 12, resistor to positive +5v

int outPin1 = 13; // Output connected to digital pin 13
int outPin2 = 12;
int outPin3 = 11;
int outPin4 = 10;
int outPin5 = 9;
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
void setup()
{
 pinMode(outPin1, OUTPUT);
 pinMode(outPin2, OUTPUT);
 pinMode(outPin3, OUTPUT);
 pinMode(outPin4, OUTPUT);
 pinMode(outPin5, OUTPUT);
 Serial.begin(9600);
 Serial.flush();
 mail = HIGH; // start off with lights out
}

void loop()
{
 // Read from serial port
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val);

   if (val == 'n') // n = 110 in dec
   {
     mail = false;
     delay(500);
     digitalWrite(outPin1, LOW);
     delay(800);
     digitalWrite(outPin1, HIGH);
   }

   else if (val == 'm') // 109 = m in dec
   {
     mail = true;
         delay(500);
      digitalWrite(outPin1, LOW);
   }}}
Logged

Online Online
Sr. Member
****
Karma: 19
Posts: 402
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try this to turn blinking on and off on outPin1.

You can add the other LEDs.

BTW, Serial.flush  >> what does that do for you?

Code:
// led wired + to pin 12, resistor to positive +5v

int outPin1 = 13; // Output connected to digital pin 13
int outPin2 = 12;
int outPin3 = 11;
int outPin4 = 10;
int outPin5 = 9;
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
unsigned long blinkInterval = 250UL;
unsigned long startTime;
void setup()
{
  pinMode(outPin1, OUTPUT);
  pinMode(outPin2, OUTPUT);
  pinMode(outPin3, OUTPUT);
  pinMode(outPin4, OUTPUT);
  pinMode(outPin5, OUTPUT);
  Serial.begin(9600);
  Serial.flush();
  startTime = millis();
  mail = false; // start off with lights out
}

void loop()
{
  // Read from serial port
  if (mail) blinkLEDs();
  else allLedsOff();
  if (Serial.available())
  {
    val = Serial.read();
    Serial.println(val);

    if (val == 'n') // n = 110 in dec
    {
      mail = false;
    }
    else if (val == 'm') // 109 = m in dec
    {
      mail = true;
    }
  }
}

void blinkLEDs()
{
  if (millis() - startTime >=blinkInterval)
  {
    digitalWrite(outPin1, !digitalRead(outPin1));
    //put your other pins here
    startTime += blinkInterval;
  }
}

void allLedsOff()
{
  digitalWrite(outPin1, LOW);
  // turn your other leds off here
}
« Last Edit: July 13, 2014, 08:36:41 pm by BulldogLowell » Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took out some of the lights so i could just focus on getting it to work.. here is what it is currently at.
Now all the lights are ON for some reason? and I cant get them to turn off.. could it be a scope problem? I noticed I have 3 closing brackets at end?

Now you only update the LED state when you receive data on the serial port. Unless you've changed what you're trying to achieve, this is a backwards step.

Can you explain exactly what behaviour you are trying to achieve?

Also, in future when posting code please encode it in code tags.

Finally, I suggest you get into the habit of putting each { and } on a separate line and then use the tools / autoformat feature to sort out the indentation.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: