Python for communication with Arduino

Dear Forum,

I'm a complete Python newbie and I'd like to try something for a project. The goal is to play an mp3 file that is on my computer when somebody hits a button that is connected to the arduino. I manage to play a mp3 file from a small python program with this code:

from Tkinter import * from tkSnack import *

root = Tkinter.Tk()

initializeSnack(root)

s = Sound()

def play(): s.play()

def load(): file = root.tk.call('eval', 'snack::getOpenFile') s.read(file)

s.read('1.mp3') s.play()

root.mainloop()

Now I want to implement this in a program that reads the serial port and when it reads the line "AUDIO", it plays this music file. I tried this code: (based on something I found on the internet) But it didn't work. I'm sure I made stupid mistakes. Could somebody be so kind to correct my mistakes?

import serial from Tkinter import * from tkSnack import *

def play(): s.play()

def load(): file = root.tk.call('eval', 'snack::getOpenFile') s.read(file)

def capture():

print "Start capture"

ser = serial.Serial(4, 9600, timeout=0)

while (1): line = ser.readline() if (line == "AUDIO"): s = Sound() s.read('1.mp3') s.play()

""" ------------------------------------------- MAIN APPLICATION """

root = Tkinter.Tk() initializeSnack(root)

print "Start Application"

capture() root.mainloop()

Thanks a lot! And pardon any stupid mistakes. i'm under time pressure and I don't have the time to learn Python right now...

i'm under time pressure and I don't have the time to learn Python right now...

Homework's due soon, huh? Or are you just lazy?

What data are you getting from the serial port? Does it match what the Arduino sent?

There is no way for us to know that, since you didn't post the Arduino code.

This isn't a Python forum, you know.

Nope, homework isn't due soon. This is something I am looking into for a friend. It's for an art project and his deadline is due soon. I'm neither familiar with python and I know that this isn't a python forum. But if there is any other solution available to play an audio file on my computer using serial communication with Arduino, I'd be happy to hear!

The arduino sends at a certain point this:

Serial.println("AUDIO");

Over the COM4 port using 9600 bauds. This should trigger something that gives the command to open a .mp3 file.

I'm not looking for an easy answer and I'm not lazy either, just trying to do a friend a favor.

I managed to solve my problem using processing and the minim library. This topic can be closed.

thanks,

Brecht