[Tutor] Seismometer alarm

Ted tchannel at cableone.net
Sun Jan 4 14:17:43 CET 2015


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 arduino........and 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



More information about the Tutor mailing list