rfid music

Ask questions about projects relating to: aerodynamics or hydrodynamics, astronomy, chemistry, electricity, electronics, physics, or engineering.

Moderators: AmyCowen, kgudger, bfinio, MadelineB, Moderators

Locked
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

rfid music

Post by deleted-274944 »

hello sir/ma'am
im working on the Sound like Rfid project
actually the COM port allows me to access only one application at a time..

example:
if i configure the putty or hyper terminal then i can read the tag data on the putty/hyperterminal console but when i try and run the python code ,then it shows me an error
..it says "access denied'

later if i first run the python code, the code runs without error .. but the configure for putty/hyperterminl doesnt happen.. it say "unable to open the COM port" in putty /hyperterminal
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

Yes, it is always the case that only one application can access a COM port. If you use PuTTY to look at the tag info, you absolutely have to close the port and exit PuTTY in order to use the port in Python. Consider though, why you ran PuTTY in the first place:

1) To find out the COM port address. The easiest way was to let PuTTY figure it out and give you a list.

2) To confirm that the reader was connected and working, and to give you the 10 digit codes out of each of the tags. Once you've done that, you can actually uninstall PuTTY if you want to (although there's no reason to) since all of your work on this going forward will be in Python.

There's nothing wrong. It's supposed to work that way. If you have some weird case where exiting PuTTY isn't enough and you have to restart Windows (I'm not quite sure what you were suggesting), then that would be wrong, but Windows has done weirder things than that. Sometimes you just have to roll with the weirdness. But rest assured that you won't be using PuTTY for this again after you have Python reading the tags.

Howard
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

thanks for the previous reply

ok.. so i ran the python idle as adminstrator ( just to remain safe)
1. I ran the showtags.py ( changed the COM port to //./COM3) .Without any errors i could run the code.

2.I ran the playsounds.py program using Pygame (with the help of putty, i read the tag data from reader to the putty console)
it gave me 12digit number "02005CBD9172". i discarded the last to digits as specified that they are identifiers

Code: Select all

[pygame.mixer.Sound("220-A.wav"), "02005CBD91", "A3"]
i changed the codes respective to the tags.

finally i saved the .WAV files in the same folder where both the codes (showtags.py and playsounds.py ) exist

BUT I CAN'T PLAY THE AUDIO FILES.

i encountered no errors while running the code.. any idea why are the audio files not playing via playsounds.py code ?
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

The two programs separately won't play sounds when you move the tag around. You need to write your own program that combines the tag reading function of showtags with the sound playing function of playsounds. If you start with showtags.py and make a copy of the file, perhaps called Brandons_code.py, you'll see a section that says

Code: Select all

# This is a stub of a 'data handler' that will get called by the rest of the 
# program when a complete tag comes in from the reader
def handle_data(data):
      print("data=",data)
      # This is where you would use the data for something.
	  # Right now it simply shows it on screen.
So instead of just printing the tag information on screen, write a little of piece of code that calls a sound player, and copy/paste the relevant sections of playsounds.py into your code to make the sounds.

Does that help?
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

:(
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

That's not a happy face.

To make sure I understand what you're having a problem with, is it that pygame won't play audio at all? Or is it that you can play audio and you can read tags but you're not sure how to paste them together? Looking back at the conversation so far, I realize that there are several ways to interpret what you said. If you're having trouble getting pygame to work, that's an issue we should work on first. I did a quick Google search for "pygame won't play audio +windows" and found a bunch of good discussions which suggest several fixes.

Howard
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

i just have problem with running both playsound and showtags fuctions together.. i tried to copy paste the playsounds in showtags but i dint have any luck.. i have lost my hopes ..

Code: Select all

# This is a stub of a 'data handler' that will get called by the rest of the 
# program when a complete tag comes in from the reader
def handle_data(data):
      print("data=",data)
      # This is where you would use the data for something.
     # Right now it simply shows it on screen.
does not display anything .. although i can read the tag data on the hyperterminal and putty too..

i have putty/hyperterminal ,pygame all working fine..
just that i cant figure out how to combine and run both the functions together.. :(
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

Yes indeed, that can be frustrating. But you understand that I can't just write your project code for you... So let's see if I can give you a gentle push up that hill.

You start with a copy of showtags.py. It has a section up at the top that does some housekeeping stuff, defines 'handle_data' to do something with the data when a tag is read, and then goes into an endless thread looking for data from the reader. When it finishes reading a tag, it calls 'handle_data' to do something with the data. As presented, all it does is print the tag to the screen. It looks something like this is you remove all the program content:

Code: Select all

import serial
import threading
import time
import sys

port = '/dev/cu.usbserial-AH012QEW'

# This is the data rate of the RFID reader
baud = 2400

# Open a connection to the serial port using the information above
serial_port = serial.Serial(port, baud, timeout=0)

# This is a stub of a 'data handler' that will get called by the rest of the 
# program when a complete tag comes in from the reader
def handle_data(data):
      print("data=",data)
      # This is where you would use the data for something.
	  # Right now it simply shows it on screen.

def read_from_port(ser):
      (a bunch of Python code removed here)
And you also have playsounds.py that has a bunch of housekeeping stuff necessary for making sounds with pygame.

It sets up some stuff:

Code: Select all

import time
import pygame
import sys
pygame.init()
pygame.mixer.init()
bells = [
	  #                    filename      tag data      friendly
      #                    for the       for the tag   name for
      #                    note          that plays    this note
      #                                  this note
      [pygame.mixer.Sound("220-A.wav"), "3501D5A69A", "A3"],
      ...
and includes a routine to 'play_a_bell'. In that example you pass it a name like 'A4', 'B4', etc. so that it can scan through the list and decide which of the sounds to play. You got that working too, so you're much closer than you think.

Imagine you took the housekeeping and setup things from playsounds and added them a copy of showtags. You're making one NEW program by combining the guts of playsounds to showtags.

1) Take the setup guts from playsounds and add them to showtags.

2) When you get to the list of music files and note names, see where the tag data is? Replace those tags with the ones you read from the tags you have. The example data in the program is from the tag set I bought - which won't help you.

3) Copy 'play_a_bell' into your new program. In that piece of code, it compares the 'A4' you passed as an argument to 'bells[2]' - which means to use the variable 'i' for the row number and to use element 2. Remember that elements in a list start with the number 0, so element 2 is the third one - or the short note name. BUT the tag is element 1, so if you changed 'if s == bells[2]:' to 'if s == bells[1]:', do you see why the program would now play a bell sound based on your tag?

4) In handle_data it prints the tag and then says in the comment that this is a good place to do something better. Maybe:

Code: Select all

play_a_bell(data)
I hope this helps. All you're doing now is combining the setups for the two systems that help Python with the tag reader and sounds, and use the data handler function in one of the programs to call the sound player from the other. You can make it much more awesome once you get this working - maybe it could change from one type of sound to another? Maybe you could build in a cool jukebox function? Try the steps I outlined above and see if that doesn't at least get it making sounds from the tags.

Howard
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

Code: Select all

import serial
import threading
import time
import sys
import pygame

# The name of the actual serial port will depend on the operating system
# and your computer's configuration. The easiet way to find it is to try
# read the tags in a serial terminal emulation program (as discussed in
# the project description)
port = 'COM4'

# This is the data rate of the RFID reader
baud = 9600

# Open a connection to the serial port using the information above
serial_port = serial.Serial(port, baud, timeout=0)

# This is a stub of a 'data handler' that will get called by the rest of the 
# program when a complete tag comes in from the reader
#def handle_data(data):
 #     print("data=",data)
      # This is where you would use the data for something.
	  # Right now it simply shows it on screen.

# This sample program plays two tunes using the handbell sample files
# from the Science Buddies project "Sounds like RFID". To run this, you
# need Python 3, pyGame and the handbell WAV files from that project idea.

# Before we can use the pygame functions to play sounds, we have to
# let the module set itself up. You just do this once at the beginning.

# This is a short program that reads data coming from the RFID reader, one
# character at a time. The data coming in is 10 chararcters of useful information
# followed by 2 characters that indicate the end of the tag. It takes each incoming
# character and decides if it's a character a human can read or if it's one of the special
# end-of-tag characters. When it thinks it's done with the tag, it calls the 'handle_data()'
# progam we defined just above.
def read_from_port(ser):
	  # Let's start with an empty storage area for the incoming data
      new_data = ""
      while True:
			# Read in one character
            reading = ser.read(1)
			# If we got one, the 'length' will be 1. If not, we have nothing to look at
            if len(reading) > 0:
				  # A standard CR character (ASCII 13, or 0x0D) tells us we have all the data
                  if b'\r' == reading:
						# If the data is complete, call our data handler to do something with it
                        handle_data(new_data)
						# clear the storage area and get ready for new data
                        new_data = ""
                  elif reading >= b'0' and reading <= b'F':
						# The character is human readable and will be in the range 0-9 or A-F,
						# so stick it on the end of the storage area to build up the incoming data string
                        new_data = new_data + reading.decode()
 
# read_from_port() is intended to run in the background as a separate thread
thread = threading.Thread(target=read_from_port, args=(serial_port,))
thread.start()

# With the data collection thread running, we can go do something else.
print ("Go ahead and wave a tag near the reader.")

# This test program has nothing else to do. Yours might and this is where you'd
# do that.
while True:
      # wait here forever. You have to have something in the loop so
	  # we'll just keep assigning the value 0 to the variable a. It's
	  # wasting time while the other thread does all the work.
	  # You could have the program do something else if you wanted to.
      a = 0

pygame.init()
pygame.mixer.init()

# This is one way to play the sound. This doesn't allow you
# to play more than one sound at a time. It also makes it hard to
# use different sound files if you want to switch quickly between
# bell sounds and something else. We don't recommend this method, but
# it's here as an example of one way you could play sounds.
#
# Tell pygame the name of a file you want to play
pygame.mixer.music.load("329-E.wav")
# Tell pygame to play the file
pygame.mixer.music.play(0)
# The time.sleep(1) function tells Python to wait for 1 second before continuing.
# This is enough time to play the sound file.
time.sleep(1)
pygame.mixer.music.load("293-D.wav")
pygame.mixer.music.play(0)
time.sleep(1)
pygame.mixer.music.load("261-C.wav")
pygame.mixer.music.play(0)
time.sleep(1)
pygame.mixer.music.load("293-D.wav")
pygame.mixer.music.play(0)
time.sleep(1)
pygame.mixer.music.load("329-E.wav")
pygame.mixer.music.play(0)
time.sleep(1)
pygame.mixer.music.load("329-E.wav")
pygame.mixer.music.play(0)
time.sleep(1)
pygame.mixer.music.load("329-E.wav")
pygame.mixer.music.play(0)

# With the song complete, wait for 5 seconds.
time.sleep(5)

# ---------------------------------------------------------------

# This is a better way to make sounds. We preload the sound files
# in lists (we do that earlier in the program) and we can just call
# on pygame's player to play them. The 'play_a_bell()' routine
# just needs to know the short name we assigned the sound. It will find
# it and start the sound playing. It plays in the background and you
# can play multiple sounds at once.
#
# What would happen if you made multiple lists? Or could a list contain
# more than one kind of sound?
#
#
# Each of these lists is a sound, space you might use to store a RFID
# tag ID, and a friendlier name you can use to search. These tags are
# simply examples and they won't work with whatever RFID tags you might
# have. If you use this method, you need to read the data from your own
# RFID reader and tags, and substitute in your own data.
bells = [
      #                    filename      tag data      friendly
      #                    for the       for the tag   name for
      #                    note          that plays    this note
      #                                  this note
      [pygame.mixer.Sound("220-A.wav"), "02005CBD9172", "A3"],
      [pygame.mixer.Sound("247-B.wav"), "02005CBD91", "B3"],
      [pygame.mixer.Sound("261-C.wav"), "02005C3241", "C3"],
      [pygame.mixer.Sound("293-D.wav"), "020sBD91", "D3"],
      [pygame.mixer.Sound("329-E.wav"), "005CBD9172", "E3"],
      [pygame.mixer.Sound("349-F.wav"), "005fBD91", "F3"],
      [pygame.mixer.Sound("392-G.wav"), "50007E2E5454", "G3"],
      [pygame.mixer.Sound("440-A.wav"), "50007E2E54", "A4"],
      [pygame.mixer.Sound("494-B.wav"), "007E2E5454", "B4"],
      [pygame.mixer.Sound("523-C.wav"), "50007dfE54", "C4"],
      [pygame.mixer.Sound("587-D.wav"), "50ghgj5454", "D4"]
]

# given the tag OR the friendly name, start the bell sound. This
# routine searches by the friendly sound name, but if you searched
# the entry for the RFID tag, imagine the possibilities...
def play_a_bell(s):
	  # len(bells) tells us how many of those individual lists
	  # there are in the list 'bells'. Look at each one.
	  # If, for example, the user asks for "C3", look
	  # at each list for a "C3" in position 2 of the list.
	  # When we see one, start playing the sound file for
	  # that note.
      for i in range(0,len(bells)):
            #print (bells[i][2])
			# Does the friendly name in this list match what we're looking for?
            if s == bells[i][2]:
				  # Yes! Play the sound.
                  bells[i][0].play(loops=0, maxtime=0, fade_ms=0)
                  break;                  


# Let's make some music! Play a "C"
play_a_bell("C3")
# Wait one second
time.sleep(1)
# Play that same C again
play_a_bell("C3")
# Wait another second
time.sleep(1)
# Play a "G" above that previous C
play_a_bell("G3")
# You get the idea...
time.sleep(1)
play_a_bell("G3")
time.sleep(1)

play_a_bell("A4")
time.sleep(1)
play_a_bell("A4")
time.sleep(1)
play_a_bell("G3")
time.sleep(1)
this is wat i managed to do .. i had tried the same thing even before but it dint help me out ..
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

You are on the right track. I rearranged some of your cut-and-pastes, added one line into handle_data() for you and removed the things you didn't need. Unfortunately I don't have access to a machine that can run Python today, but this should be pretty close to working. You had the right idea but maybe it wasn't clear to you how things worked and why they worked the way they did.

See if this makes sense to you and give it a try:

Code: Select all

    import serial
    import threading
    import time
    import sys
    import pygame

    # The name of the actual serial port will depend on the operating system
    # and your computer's configuration. The easiet way to find it is to try
    # read the tags in a serial terminal emulation program (as discussed in
    # the project description)
    port = 'COM4'

    # This is the data rate of the RFID reader
    baud = 9600

    # Open a connection to the serial port using the information above
    serial_port = serial.Serial(port, baud, timeout=0)

    # Set up the pyganme sound support
    pygame.init()
    pygame.mixer.init()


    # Each of these lists is a sound, space you might use to store a RFID
    # tag ID, and a friendlier name you can use to search. These tags are
    # simply examples and they won't work with whatever RFID tags you might
    # have. If you use this method, you need to read the data from your own
    # RFID reader and tags, and substitute in your own data.
    bells = [
          #                    filename      tag data      friendly
          #                    for the       for the tag   name for
          #                    note          that plays    this note
          #                                  this note
          [pygame.mixer.Sound("220-A.wav"), "02005CBD9172", "A3"],
          [pygame.mixer.Sound("247-B.wav"), "02005CBD91", "B3"],
          [pygame.mixer.Sound("261-C.wav"), "02005C3241", "C3"],
          [pygame.mixer.Sound("293-D.wav"), "020sBD91", "D3"],
          [pygame.mixer.Sound("329-E.wav"), "005CBD9172", "E3"],
          [pygame.mixer.Sound("349-F.wav"), "005fBD91", "F3"],
          [pygame.mixer.Sound("392-G.wav"), "50007E2E5454", "G3"],
          [pygame.mixer.Sound("440-A.wav"), "50007E2E54", "A4"],
          [pygame.mixer.Sound("494-B.wav"), "007E2E5454", "B4"],
          [pygame.mixer.Sound("523-C.wav"), "50007dfE54", "C4"],
          [pygame.mixer.Sound("587-D.wav"), "50ghgj5454", "D4"]
    ]


    # given the tag OR the friendly name, start the bell sound. This
    # routine searches by the friendly sound name, but if you searched
    # the entry for the RFID tag, imagine the possibilities...
    def play_a_bell(s):
         # len(bells) tells us how many of those individual lists
         # there are in the list 'bells'. Look at each one.
         # If, for example, the user asks for "C3", look
         # at each list for a "C3" in position 2 of the list.
         # When we see one, start playing the sound file for
         # that note.
         # ** This is a modified version that uses the tags instead of the friendly names
          for i in range(0,len(bells)):
                #print (bells[i][2])
             # Does the tag data in this list match what we're looking for?
                if s == bells[i][1]:
                  # Yes! Play the sound.
                      bells[i][0].play(loops=0, maxtime=0, fade_ms=0)
                      break;

    # This is a stub of a 'data handler' that will get called by the rest of the
    # program when a complete tag comes in from the reader
    def handle_data(data):
    #     print("data=",data)
          # This is where you would use the data for something.
          play_a_bell(data);

    # This is a short program that reads data coming from the RFID reader, one
    # character at a time. The data coming in is 10 chararcters of useful information
    # followed by 2 characters that indicate the end of the tag. It takes each incoming
    # character and decides if it's a character a human can read or if it's one of the special
    # end-of-tag characters. When it thinks it's done with the tag, it calls the 'handle_data()'
    # progam we defined just above.
    def read_from_port(ser):
         # Let's start with an empty storage area for the incoming data
          new_data = ""
          while True:
             # Read in one character
                reading = ser.read(1)
             # If we got one, the 'length' will be 1. If not, we have nothing to look at
                if len(reading) > 0:
                  # A standard CR character (ASCII 13, or 0x0D) tells us we have all the data
                      if b'\r' == reading:
                      # If the data is complete, call our data handler to do something with it
                            handle_data(new_data)
                      # clear the storage area and get ready for new data
                            new_data = ""
                      elif reading >= b'0' and reading <= b'F':
                      # The character is human readable and will be in the range 0-9 or A-F,
                      # so stick it on the end of the storage area to build up the incoming data string
                            new_data = new_data + reading.decode()

    # read_from_port() is intended to run in the background as a separate thread
    thread = threading.Thread(target=read_from_port, args=(serial_port,))
    thread.start()

    # With the data collection thread running, we can go do something else.
    print ("Go ahead and wave a tag near the reader.")

    # This test program has nothing else to do. Yours might and this is where you'd
    # do that.
    while True:
          # wait here forever. You have to have something in the loop so
         # we'll just keep assigning the value 0 to the variable a. It's
         # wasting time while the other thread does all the work.
         # You could have the program do something else if you wanted to.
          a = 0
You will have trouble with your tag data though. The tag data should be 10 digit numbers (in base 16) consistently and what you have in your list of lists is clearly not that. You might want to go back and run showtags.py again and copy the data down carefully. Each tag will have 10 and only 10 digits.

Howard
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

Code: Select all

import serial
import threading
import time
import sys
import pygame

    # The name of the actual serial port will depend on the operating system
    # and your computer's configuration. The easiet way to find it is to try
    # read the tags in a serial terminal emulation program (as discussed in
    # the project description)
port = 'COM4'

    # This is the data rate of the RFID reader
baud = 9600

    # Open a connection to the serial port using the information above
serial_port = serial.Serial(port, baud, timeout=0)

    # Set up the pyganme sound support
pygame.init()
pygame.mixer.init()


    # Each of these lists is a sound, space you might use to store a RFID
    # tag ID, and a friendlier name you can use to search. These tags are
    # simply examples and they won't work with whatever RFID tags you might
    # have. If you use this method, you need to read the data from your own
    # RFID reader and tags, and substitute in your own data.
bells = [
          #                    filename      tag data      friendly
          #                    for the       for the tag   name for
          #                    note          that plays    this note
          #                                  this note
          [pygame.mixer.Sound("220-A.wav"), "02005CBD91", "A3"],
          [pygame.mixer.Sound("247-B.wav"), "50007E2E54", "B3"]
    ]


    # given the tag OR the friendly name, start the bell sound. This
    # routine searches by the friendly sound name, but if you searched
    # the entry for the RFID tag, imagine the possibilities...
def play_a_bell(s):
         # len(bells) tells us how many of those individual lists
         # there are in the list 'bells'. Look at each one.
         # If, for example, the user asks for "C3", look
         # at each list for a "C3" in position 2 of the list.
         # When we see one, start playing the sound file for
         # that note.
         # ** This is a modified version that uses the tags instead of the friendly names
          for i in range(0,len(bells)):
                #print (bells[i][2])
             # Does the tag data in this list match what we're looking for?
                if s == bells[i][1]:
                  # Yes! Play the sound.
                      bells[i][0].play(loops=0, maxtime=0, fade_ms=0)
                      break;

    # This is a stub of a 'data handler' that will get called by the rest of the
    # program when a complete tag comes in from the reader
def handle_data(data):
    #     print("data=",data)
          # This is where you would use the data for something.
          play_a_bell(data);

    # This is a short program that reads data coming from the RFID reader, one
    # character at a time. The data coming in is 10 chararcters of useful information
    # followed by 2 characters that indicate the end of the tag. It takes each incoming
    # character and decides if it's a character a human can read or if it's one of the special
    # end-of-tag characters. When it thinks it's done with the tag, it calls the 'handle_data()'
    # progam we defined just above.
def read_from_port(ser):
         # Let's start with an empty storage area for the incoming data
          new_data = ""
          while True:
             # Read in one character
                reading = ser.read(1)
             # If we got one, the 'length' will be 1. If not, we have nothing to look at
                if len(reading) > 0:
                  # A standard CR character (ASCII 13, or 0x0D) tells us we have all the data
                      if b'\r' == reading:
                      # If the data is complete, call our data handler to do something with it
                            handle_data(new_data)
                      # clear the storage area and get ready for new data
                            new_data = ""
                      elif reading >= b'0' and reading <= b'F':
                      # The character is human readable and will be in the range 0-9 or A-F,
                      # so stick it on the end of the storage area to build up the incoming data string
                            new_data = new_data + reading.decode()

    # read_from_port() is intended to run in the background as a separate thread
thread = threading.Thread(target=read_from_port, args=(serial_port,))
thread.start()

    # With the data collection thread running, we can go do something else.
print ("Go ahead and wave a tag near the reader.")

    # This test program has nothing else to do. Yours might and this is where you'd
    # do that.
while True:
          # wait here forever. You have to have something in the loop so
         # we'll just keep assigning the value 0 to the variable a. It's
         # wasting time while the other thread does all the work.
         # You could have the program do something else if you wanted to.
          a = 0
edited the tags since i have limited tags..
these are the scrrenshots
Image
https://drive.google.com/file/d/0B1mwZ1 ... sp=sharing

Image
https://drive.google.com/file/d/0B1mwZ1 ... sp=sharing

still does nothing .. :(
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

Now you get to learn the fine art of debugging.

Sprinked throughout the code are commented statements like " #print (bells[2])". They're in place because whent eh code was originally written it was handy to see where the code was and what its was doing. After it worked, the extra stuff on the screen became annoying and slowed things down. You could start by stategically uncommenting some of those print() statements and see what that tells you. You may want to add some new ones depending on what you suspect. The one I quoted above came from play_a_bell() and showed what the loop was comparing against. It would show the friendly note name but you'd want to change that to " #print (bells[1])" to show the tag instead.

Start by having the programs print everything as is works, then turn off the prnting when you no longer find it useful. I don't see any glaring errors in your code and the screenshot looks exactly as it should. When the program is working, it doesn't display anything. Also, it's sometimes easier to debug a computer program with friends. A second pair of eyes will often help you see things you missed.

Howard
deleted-274944
Posts: 8
Joined: Mon Mar 02, 2015 8:22 am
Occupation: Student
Project Question: Computer Science
Project Due Date: 6th march 2015
Project Status: I am finished with my experiment and analyzing the data

Re: rfid music

Post by deleted-274944 »

could u please mail me the code ??
i have been trying n working on this project since months..
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

As I said, the last code you posted looks like it ought to work. I can't tell without connecting an RFID reader up to a machine and try it, and I can't do that until the middle of next week I will do that, but honestly - you've already got something that should be making noise. If you add in a few print statements you'll be able to see what the program is doing and you'll probably figure it out before I can help you.

If you plan to write any programs of your own, you'll need to get the hang of figuring out what your code is doing. I know it's frustrating and you've been working on this for a while. Take a deep breath and give the print statements a try. I think you'll find that it's not as hard as figuring out how to combine the program functions.

Howard
deleted-249560
Posts: 496
Joined: Thu Nov 20, 2014 1:35 pm
Occupation: Science Buddies content developer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: rfid music

Post by deleted-249560 »

While I was waiting to get to a machine to test this on, another student who has done the project tried that last verison posted above and except for

Code: Select all

# This is the data rate of the RFID reader
    baud = 9600
it seemed to work correctly. The baud rate of the RFID reader is 2400, so you need to change those lines to

Code: Select all

# This is the data rate of the RFID reader
    baud = 2400
and you should have better luck.

He had to change the serial port to the one on his machine and the tags, of course, but it works properly when you fix the baud rate and point to the right COM port and tags.

Howard
Locked

Return to “Grades 6-8: Physical Science”