[Tutor] Seismometer alarm

Ted tchannel at cableone.net
Sun Jan 4 17:10:03 CET 2015

```Hi Dave, and All,   I hope this reply is in the correct form.  If not please

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

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.

while True:
if myData >32500:
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 at 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
(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
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.

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 at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

```