I use an Arduino Uno Rev 2. What I was using it was for making a gmail notifier which used a python script on my computer to send serial data to the arduino using the pySerial library. Now, I've read around that when a serial data is sent to the arduino it resets automatically thus erasing any data it may have received. However just to test the hardware section with an LED connected to pin 12 I used the HyperTerminal program. My arduino code is as follows:
int outPin = 12; // Output connected to digital pin 12
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
Serial.flush();
}
void loop()
{
// Read from serial port
if (Serial.available())
{
val = Serial.read();
if (val == 'M') mail = HIGH;
else if (val == 'N') mail = LOW;
}
// Set the status of the output pin
digitalWrite(outPin, mail);
}
Now when I tested it using the HyperTerminal (without disabling the auto-reset feature) and it works fine. However when I send data using the python script, it doesn't work.
Question is: why does it work in HyperTerminal without disabling auto-reset whereas when I use the python script it doesnt? Do I HAVE TO disable the feature for the script to work?
This is the python script I've used to capture my gmail feeds (for reference)
import serial, urllib2, sys, feedparser
def main():
try:
# the best way to find this out is to launch the Arduino environment
# and see what it says under Tools -> Serial Port
ser = serial.Serial(port='COM17', baudrate=9600)
except serial.serialutil.SerialException:
sys.exit()
pwdmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
pwdmgr.add_password("New mail feed", 'http://mail.google.com/', 'my-username', 'my-password')
auth = urllib2.HTTPBasicAuthHandler(pwdmgr)
opener = urllib2.build_opener(auth)
data = opener.open('http://mail.google.com/mail/feed/atom')
d = feedparser.parse(data)
newmails = d.feed.fullcount
print newmails
if newmails > 0: ser.write('M')
else: ser.write('N')
ser.close()
if __name__=="__main__":
main()