Realizzeremo un notificatore per gmail, quando arriverà un nuovo messaggio sul nostro account di gmail, il nostro arduino lo segnalerà.
Guarda il video
Codice PYTHON:
import serial, sys, feedparser
#Settings - Change these to match your account details
USERNAME="XXXXXXX@gmail.com"
PASSWORD="PASSWORDXXWD"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
SERIALPORT = "/dev/tty.usbserial-FTE3RS4J" # Change this to your serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
print "no device connected - exiting"
sys.exit()
newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)["feed"]["fullcount"])
# Output data to serial port
if newmails > 0:
ser.write("m")
print "some mail"
else:
ser.write("n")
print "no mail"
#print data to terminal
# Close serial port
ser.close()
Codice ARDUINO:
#include <MsTimer2.h>
#include <Servo.h>
Servo myservo;
int val;
int pos;
void flash() {
static boolean output = HIGH;
digitalWrite(9, output);
output = !output;
}
void setup()
{
Serial.begin(9600);
Serial.flush();
myservo.attach(10);
}
void loop()
{
if (Serial.available())
{
val = Serial.read();
Serial.println(val, BYTE);
if (val == 110) // n = 110 in dec
{
pinMode(9,0);
pos = 0;
}
else if (val == 109) //109 = m in dec
{
pinMode(9, OUTPUT);
MsTimer2::set(150, flash); // 150ms periodo
MsTimer2::start();
pos =140;
}
}
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
Fonte
Codice PYTHON:
import serial, sys, feedparser
#Settings - Change these to match your account details
USERNAME="XXXXXXX@gmail.com"
PASSWORD="PASSWORDXXWD"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
SERIALPORT = "/dev/tty.usbserial-FTE3RS4J" # Change this to your serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
print "no device connected - exiting"
sys.exit()
newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)["feed"]["fullcount"])
# Output data to serial port
if newmails > 0:
ser.write("m")
print "some mail"
else:
ser.write("n")
print "no mail"
#print data to terminal
# Close serial port
ser.close()
Codice ARDUINO:
#include <MsTimer2.h>
#include <Servo.h>
Servo myservo;
int val;
int pos;
void flash() {
static boolean output = HIGH;
digitalWrite(9, output);
output = !output;
}
void setup()
{
Serial.begin(9600);
Serial.flush();
myservo.attach(10);
}
void loop()
{
if (Serial.available())
{
val = Serial.read();
Serial.println(val, BYTE);
if (val == 110) // n = 110 in dec
{
pinMode(9,0);
pos = 0;
}
else if (val == 109) //109 = m in dec
{
pinMode(9, OUTPUT);
MsTimer2::set(150, flash); // 150ms periodo
MsTimer2::start();
pos =140;
}
}
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
}
Fonte
Nessun commento:
Posta un commento