[Tutor] Seismometer alarm Python
Hi Folks, I have a small python code to write. It has at least three parts, 1,2 and 3. I think I have 1 and 3 working. I do not know how this Tutor@python.org works, but if someone can email me I can explain my questions. I do not wish to get into too much detail, on this first email. Basically, I am receiving a list of numbers (int)? on a serial port in python. I want to add a trigger, which will play an alarm file on the computer when these numbers reach a certain condition. Actually two conditions, or two IF’s?First IF..if the number/average, go up or down by (x percent)..Second IF, if the number/average stays above or below this average for (x number of seconds) If both conditions are met a .wav file plays on that computer. Thanks, Ted ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Seismometer alarm
On 03/01/15 19:19, Ted wrote: > Alan Thank you so much for the reply, attached is a screenshot of a > 4.9M earthquake in Challis Idaho, about 150 miles north. > this is what I need the alarm for. > > I am using Python 2.7? and Windows 7. > > 1. Should I reply-all, or ok to you? or either? ReplyAll please, that way you get responses from everyone not just me. And that's a very good thing, trust me! :-) 3. The data is coming from a serial port from an arduinoand I think this is a "string" Yes, in Python2 it will be, in Python 3 it will be a bytestring but you can ignore that for now! :-) > I think I need to see it as an (int)? But I don't know how. > As you can see here is where I placed that. > myData = int (arduinoSerialData.readline()) Thats exactly correct. int() converts the string to a number. Just to confirm myData = int (arduinoSerialData.readline()) is this line written right. ()) > I want to add an IF as you can see below, and this seems to work, > but I am not sure I am seeing (int), because the numbers don't seem right. Tell us what you see and what you expect. I now think, this is is correct, so I will go to the next step. > The good news, is I do see the data in python, either a string or int??? > The good news, is I can play the sound file as it is below. Great, we'll look at it in more detail. > import serial #Import Serial Library > import time # Slows the print > import winsound > arduinoSerialData = serial.Serial('com7', 9600) #Create Serial port > object called arduinoSerialData # Don't change this. > myData = (arduinoSerialData.readline()) > > What happens if you print myData here? > > while (1==1): use while True: instead of the equality test. I understand. >myData = int (arduinoSerialData.readline()) > if myData >33500: >print(arduinoSerialData.readline()) Here I would like to see it > printed, AS WELL AS, doing the following. Note this is printing the next thing from Arduino but not storing it anywhere. You are throwing it away... HERE IS MY MAIN GOAL, Here I do want to go to the next step..and not throw the numbers away. 1. These numbers come it very fast 18 per second? and I can’t change that. I want these number to trigger an alarm. 2. Perhaps I need to say, save these numbers for 30 seconds, and give me one average number every 30 seconds. If that average number, increases or decrease by 10% go to the next step. if not do nothing. 3. Now the average number has increased or decrease by, say 12%next 4. If this average number stays above/below this 10% for 30 seconds, trigger the alarm. 5. Hopefully both the IF’S (10%), and (30) seconds, would be changeable, as I don’t know for sure these conditions. It may be 12%, and 40 seconds. >time.sleep(1) #Slows to 1000ms >soundfile = "c:\Windows\Media\Alarms\Alarm.wav"#Song/Track > to play(MUST be wav) Windows paths can be troublesome due to the \ characters which Python treats as special, you should prefix them with r to tell Python to ignore the \ soundfile = r"c:\Windows\Media\Alarms\Alarm.wav" Alternatively use Unix style / instead: Thank you I understand. soundfile = "c:/Windows/Media/Alarms/Alarm.wav" Please let me know if, I need to change my Q&A’s style. I really need help, I have no python knowledge, and I am very appreciative. Thanks, Ted -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Seismometer alarm
Hi Dave, and All, I hope this reply is in the correct form. If not please advise. Here is what I have to date. 1. on line 7 below, myData = int (arduinoSerialData.readline()) Is this written correctly? I think the data coming from the arduino is strings, and I think I need int? Is this correct? I don't understand the .readline()) but if it is correct, that's okay. 2. on line 8 below, if myData >32500: This seem to work. The number is meaningless, I just want to try an IF statement, and if I change it the printout reflect that change, so I think it is working. 3. Here is my goal: These numbers range from a center point of about 32768, coming from the arduino, when all is quiet. If an earthquake occurs, they will go up or down. A range of about +500 and or -500. Normally they will do both, up 500, then down 500, then over a few minuets return to 32768. I don't know how, but I want this to trigger, the alarm sound file, below which seem to work okay. Maybe I need to create an average number of say 30 seconds, worth of data? If that average number, increases or decrease by 10% go to the next step. if not do nothing. Now say the average number has increased or decrease by, 12% Go to the next condition. If this average number stays above/below this 10% for more than 30 seconds, trigger the alarm. The reason for this second condition, is to eliminate false alarms, normal footsteps or electrical spike happen all the time, but only for a few seconds, then the numbers return to normal. An Earthquake's number will be similar, BUT the fluctuations will last longer than 30 seconds. Hopefully both the IF’S (10%), and (30) seconds, would be changeable, as I don’t know for sure these conditions. It may be 12%, and 40 seconds. This approach may not be the way to achieve this goal, so I am open to all suggestions. Thanks, Ted import serial #Import Serial Library import time # Slows the print import winsound arduinoSerialData = serial.Serial('com7', 9600) #Create Serial port object called arduinoSerialData # Don't change this. myData = (arduinoSerialData.readline()) while True: myData = int (arduinoSerialData.readline()) if myData >32500: print(arduinoSerialData.readline()) time.sleep(1)#Slows to 1000ms soundfile = "c:/Windows/Media/Alarms/Alarm.wav" #Song/Track to play(MUST be wav) winsound.PlaySound(soundfile, winsound.SND_FILENAME) -Original Message- From: Dave Angel Sent: Sunday, January 04, 2015 7:35 AM To: tutor@python.org Subject: Re: [Tutor] Seismometer alarm On 01/04/2015 08:17 AM, Ted wrote: On 03/01/15 19:19, Ted wrote: Alan Thank you so much for the reply, attached is a screenshot of a 4.9M earthquake in Challis Idaho, about 150 miles north. this is what I need the alarm for. Ted, I don't know what mail program you're using, but you're not doing a reply, you're leaving a new message, which breaks the thread. Further (and probably related), you're not adding the ">" characters in front of the parts you quote, and in fact, many times you're just adding to the end of an existing line. You're also not trimming the quoted parts, to what's relevant in your reply. For example, your message ends with Alan's footer, making it look like he wrote it. As a result, it's practically impossible for most of us to follow what you're saying now, and what's already been said. A few comments. 18 strings per second is not very fast; I wouldn't worry about that, unless your device has some other strange requirements. Timing can be awkward for a beginning programmer. Can you just count to N messages, like 18*30 or so? putting a readline() function inside a print function call is one way to be sure you can't process that number in some other way. Save it in a variable, and then (conditionally) print that variable. I'd also suggest you always label your prints, so you can tell in what part of your code that particular print was called. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Ideas for Child's Project
Hello, All, I too have an idea for students. I build seismometers for schools. A simple toy slinky spring/magnets/coil/plumbing parts. For students 10 to 90. please visit if interested http://tc1seismometer.wordpress.com/tc1-a-simple-solution/ This uses an Arduino Uno and simple amplifier, and free software. Presently working with this group "tutor" to add an alarm to python code. Cheers, Ted -Original Message- From: Jim Gallaher Sent: Wednesday, January 07, 2015 6:49 AM To: tutor@python.org Subject: Re: [Tutor] Ideas for Child's Project Good day Stephen, I have a few recommendations. Make Magazine has a lot of fun projects that use Python programs along with either a Raspberry Pi or an Arduino to create interactive projects. Arduino is more for electronic/programming based projects, but you can, say for example, attach an LED to a breadboard and program the LED to flash at certain intervals using a fairly simple Python script. The hands on and visual results of seeing what a program does might keep your son's interest better and longer, especially at his age. Make Magazine's website is makezine.com Raspberry Pi is very Python friendly and there's add on boards you can use along with Python. geek gurl diaries has video tutorials on programing with Python and raspberry that are focused towards the youngsters. Her website is www.geekgurldiaries.co.uk Hope that helps! Jim Gallaher On Tue, Jan 6, 2015 at 1:46 PM, Stephen Nelson-Smith wrote: Hello, My son is interested in programming, and has dabbled in Scratch and done a tiny bit of Python at school. He's 11 and is going for an entrance exam for a selective school in a couple of weeks. They've asked him to bring along something to demonstrate an interest, and present it to them. In talking about it, we hit upon the idea that he might like to embark upon a prorgamming challenge, or learning objective / project, spending say 30 mins a day for the next week or two, so he can show what he's done and talk about what he learned. Any suggestions for accessible yet challenging and stimulating projects? Any recommendations for books / websites / tutorials that are worth a look? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A new Kent essay: A Brief Introduction to Beautiful Soup
On 10/23/07, Dick Moores <[EMAIL PROTECTED]> wrote: > <http://personalpages.tds.net/~kent37/kk/9.html> And if you're in the Manchester, New Hampshire, USA area, perhaps you can stop by Thursday night and witness Kent himself presenting his essay and a follow-on scrum using Beautiful Soup to parse out a couple of web pages: http://dlslug.org/pipermail/python-talk/2007-October/000639.html -- Ted Roche Ted Roche & Associates, LLC http://www.tedroche.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] sorting variables
I am using pygame and i have three variables that i want to sort (var1, var2 and var3) and be able to refer to them later in a statement that will use them in sorted order: the statement i am using is: objSprites = pygame.sprite.OrderedUpdates(var1, var2, var3) and i want var1, var2 and var3 to show up in the statement in order of their value so if var1 = 9, var2 = 3 and var3 = 5, i want my statement to be equivalent to objSprites = pygame.sprite.OrderedUpdates(var2, var3, var1) i was thinking of doing something like objSprites = pygame.sprite.OrderedUpdates((var1, var2, var3).sort) but i don't think thats gunna work any help much appreciated __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] sorting / outputting varibales
If i input the following in python: var1 = 7 var2 = 9 var3 = 5 args = [var1, var2, var3] args.sort() then if if type: args the output is [5, 7, 9] but i want the output to be [var3, var1, var2] is there a function that will output the variable names in the order they have been sorted instead of the variable contents themselves? thanks __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sorting / outputting varibales
Thanks Kent, and Evert, and everyone, I really appreciate the advice on etiqutte and all your help. I will think through my questions much more thoroughly before any further inquiries and will 'reply to all' as advised. --- Kent Johnson <[EMAIL PROTECTED]> wrote: > ted b wrote: > > > Here's the code i am using, but its a lot of if / > > thens and i'm trying to find a better way: > > > > if var1.value > var2.value > var3.value: > > objSprites = pygame.sprite.OrderedUpdates > > (var1, var2, var3) > > Did you see Evert's reply to your original question? > It was pretty close > to the mark. Though you had not said anything about > the .value > attributes until now. > > Try this: > from operator import attrgetter > vars = [ var1, var2, var3 ] > vars.sort(key=attrgetter('value')) > objSprites = pygame.sprite.OrderedUpdates(*vars) > > This will sort the vars list by the value attribute > of each list item, > then pass the list as the parameter list to > OrderedUpdates(). > > Kent > > PS Please use Reply All to reply to the list. > __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] class accessing another's updated property
I want class One to be able to access access class Two's value property after its been updated. Everytime I try (by running, say testTwo().value) I get the __init__ value. The update method fro class Two is called elsewhere in the program, and I want class One's "getTwo" method to access class Two's updated value and give me '9' but i get '1' Here's the code: class One: def __init__(self): self.value = 3 def getTwo(self): print "testTwo's updated value", Two().value class Two: def __init__(self): self.value = 1 def update(self): self.value = 9 Thanks in advance! Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] selecting elements from a list that do not meet selection criteria
Is there a way i can select all elements from a list that do not meet selection criteria. I want to be able to select elements that have values of, say, < 1 but only if at least one of the elements has a value of > 0. What i mean is, for example, in the code below, if one of the elements of "list 'a'" has a value greater than 1, then i want to print all the other elements in the list (i.e., class One and class Three) and to do otherStuff associated with those classes. Right now, it prints those elements that *do* have values of > 0, (i.e. class Two). But in situations where all of the classes have values set to 0, then i don't want anything selected. I don't want to just use something like "if x.value() != 0" or "if x.value() < 1" since those would give results if all elements were less than 1, and i only want to select elements of the list that are less than 1 if at least one of the elements is > 1. Here's the sample code: class One: def value(self): return 0 class Two: def value(self): return 1 class Three: def value(self): return 0 a = [One(), Two(), Three()] for x in a: if x.value() > 0: print x x.otherStuff() Thanks in advance!!! :))) Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how. http://overview.mail.yahoo.com/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] affecting all classes if one class is affected by an event - pygame
I am trying to figure out how to make a class instance respond the same way as another class instance if the other is affected by some event. I have been playing around with inheritance, and have tried other stuff, but i am somewhat of a newbie and I have been having difficulty (but you guys, particularly Kent, have really been helping me a lot : For example, in the pygame code below, i have set it up so that the boxes will stop if they are above the barrier and hit it. Well, that's what i want to happen, but if one of the boxes hits the barrier, the other box keeps going. Is there a way i can have both boxes stop if either of them hit the barrier. I was hoping there was a way that i could have the info from one class get passed to the other classes so i could stop the other box (or stop all or only some other boxes if i add lots more). Should i make another class? Another method? Globals? Here's the code: #/usr/bin/env python import pygame from pygame.locals import * pygame.init() class testBox1(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.Surface((25,25)) self.image.fill((255,0,0)) self.rect=self.image.get_rect() self.rect.center = (30,90) def update(self): # check for user input and move left, right, up or down keys = pygame.key.get_pressed() if keys[pygame.K_w]: self.rect.center = (self.rect.centerx, self.rect.centery-4) if keys[pygame.K_s]: self.rect.center = (self.rect.centerx, self.rect.centery+4) if keys[pygame.K_a]: self.rect.center = (self.rect.centerx-4, self.rect.centery) if keys[pygame.K_d]: self.rect.center = (self.rect.centerx+4, self.rect.centery) # see if the rect hit the barrier self.checkPos() def checkPos(self): # if box rect moves below barrier's rect, halt box's position if ((self.rect.bottom > testBarrier().rect.top) and (self.rect.top < testBarrier().rect.top)): if ((testBarrier().rect.right > self.rect.right > testBarrier().rect.left) or (testBarrier().rect.right > self.rect.left > testBarrier().rect.left)): self.rect.bottom = testBarrier().rect.top class testBox2(testBox1): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.Surface((25,25)) self.image.fill((0,0,255)) self.rect=self.image.get_rect() self.rect.center = (80,50) class testBarrier(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image=pygame.Surface((30,4)) self.image.fill((0,0,0)) self.rect=self.image.get_rect() self.rect.center = (50,150) def main(): screen = pygame.display.set_mode((100,300)) pygame.display.set_caption("testing") background=pygame.Surface(screen.get_size()) background=background.convert() background.fill((255,255,255)) screen.blit(background, (0,0)) box1=testBox1() box2=testBox2() barrier=testBarrier() allSprites=pygame.sprite.Group(box1, box2, barrier) clock=pygame.time.Clock() keepGoing=True while keepGoing: clock.tick(30) for event in pygame.event.get(): if event.type==pygame.QUIT: keepGoing=False allSprites.clear(screen, background) allSprites = pygame.sprite.OrderedUpdates (barrier, box1, box2) allSprites.update() allSprites.draw(screen) pygame.display.flip() if __name__ == "__main__": main() Thanks for all your help!!! :) -ted Be a better sports nut! Let your teams follow you with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to iterate and update subseqent items in list
Can you suggest a good way to iterate through the remainder of list and update them? Ex: Thing1.value = 0 Thing2.value = 1 Thing3.value = 0 Thing4.value = 0 Things = [Thing1, Thing2, Thing3, Thing4] I want to iterate through 'Things' and if 'Thing.value' > 0, then I want to set all values for that and the subsequent 'Things' in the list to 2 So that i'd end up with Thing1.value = 0 Thing2.value = 2 Thing3.value = 2 Thing4.value = 2 Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python connecting to an exchange server
On 1/24/07, Jalil <[EMAIL PROTECTED]> wrote: > > I would basically want the python code to parse the appointsments in my > outlook calendar. > Then it's most likely you don't want to talk to exchange at all, but rather talk with Outlook. Outlook supports a COM Automation interface and you can use it to do most of the things Outlooks does via the GUI, although some of them are rather difficult. An example of COM Automation with Outlook and Python can be found: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266625 A paper on COM Automation and Outlook I wrote some time ago (in a different programming language) has some pretty good references at the end: http://www.tedroche.com/Present/2003/OutlookAutomation.html -- Ted Roche Ted Roche & Associates, LLC http://www.tedroche.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] 3 recent short essays by Kent Johnson
On 3/26/07, Dick Moores <[EMAIL PROTECTED]> wrote: > "Python Decorators," "The path module" and "List Comprehensions." > <http://personalpages.tds.net/~kent37/kk/index.html> > > Dick Moores If you're in or near New Hampshire, join the Python SIG (http://www.pysig.org) and you might get the change to see Kent deliver these live as the "Kent's Korner" portion of our meetings - fourth Thursday of the month, in Manchester, NH. Details: http://www.pysig.org -- Ted Roche PySIG Rabble-Rouser ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sending email as html
On Fri, Sep 5, 2008 at 6:42 PM, Tim Johnson <[EMAIL PROTECTED]> wrote: > > I've been using smtplib for years to send plain text emails programmatically. > Now I have a customer who is requesting that I (at least) investigate sending > invoices by email as html. I'm a big fan of sending invoices as PDFs. The invoices can have as rich text and graphics as you want, print well, and work cross-platform. > I would appreciate examples, URLs to documentation or discussions of the topic > and even an argument to the contrary of sending email with embedded html. Google "HTML Email is Evil" for a pretty succinct summary. -- Ted Roche Ted Roche & Associates, LLC http://www.tedroche.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Installation Aborts
Im trying to install 3..4.1. I downloads OK but about ¾ the way through it aborts. Im new to this can anyone give me any help? Since the above is happening I downloaded 2.7.7. It seems to install OK but when I try to run the GUI interface nothing happens. Any help here? Thanks in advance, Ted ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Please excuse and ignore prior message.
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] 2.7.7 Initial Problem
I got a reply. I did what was suggested with no results. I'm trying 2.7.7. I have a 64 bit 3.2 GHz AMD processor with 8gb of memory running Windows 7 Home Premium and 587gb of free disk space. It seems to install OK but when I try to run the GUI a window opens and quickly closes. That's all. Any other suggestions or people I should ask? Thanks again, Ted ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor