PICAXE 14 Audio Kit and micro switch

pottsy1000000

New Member
Hi

I have assembled and programmed my picaxe 14 audio kit. Early results are good and I can play an MP3 when an input button is pressed.
I want to attach a long arm micro switch which will be used to detect the casing being opened and so play the MP3. However it's not clear to me how to connect the switch to the 14M2 board.

I'm a beginner and the instructions for the main audio kit was very clear and easy to follow. But I can't find any instructions on how to attach or programme the switch.

Any help or advice would be great.
 

westaust55

Moderator
Having now had an opportunity to delve further:

The overall kit is AXE171.
At section 4.0 / page 9 the PICAXE 14M2 pin use and spares are listed.
Section 4.2 on page 12 covers switch inputs with a code example for the onboard ouch button connected to C.0.

Maybe the OP needs to clarify more precisely what additional information/assistance is required.
 

hippy

Technical Support
Staff member
I'm a beginner and the instructions for the main audio kit was very clear and easy to follow. But I can't find any instructions on how to attach or programme the switch.
Welcome to the PICAXE forum.

The AXE171 was not explicitly designed for an external switch to be added but there are two main options -

1) Wire the switch in parallel to the push button which is already fitted to the board.

2) Wire the switch with a pull-down ( or pull-up ) resistor to the LCD connector.

In the first case the activation of the switch can be determined with -

IF pinC.0 = 1 THEN

For the second -

IF pinB.3 = 1 THEN

Change the 1 to a 0 if using a pull-up rather than a pull-down resistor on the LCD connector.

Code:
         .----.----.
   LCD   |    |    | |_
   .-.   |    |      |_| Switch
B3 |O|---'    |    | |
V+ |O|--------|----'
0V |O|---.   .|.
   `-'   |   |_| 10K pull-down
         |    |
         `----'
 

rossko57

Senior Member
If this is for a music-box type project, the external switch might be better used as an on-off switch so that project is switched off (and battery life extended) when closed.
You'd then change the program so that the mp3 played automatically at start-up.
 

pottsy1000000

New Member
Hi Westaust55

Thanks for taking the time to have a look at this for me. I had a look at the manuals before I wrote the post (I should have said that in the regional, sorry)

I'm looking for the specific instruction on which pins on the switch connect to the corresponding component and pins on the board. Also how to do that e.g. With jump cables? Etc

Hippy has given some guidance on this in the reply below, so I think I just need to build on that now.
 

pottsy1000000

New Member
Hi Hippy

Thanks for the reply. It's really helpful.

If I can just build on this a little more so I'm absolutely clear.

I am a real beginner and so the circuit diagram isn't entirely clear to me.

If I connect in parallel to the existing button C.0. Then which pins on the switch do I connect to which of the solder pads? There are 3 on the switch and of course 4 on the button.

And the same question if I connect to the lcd which of the three switch connectors attach to the resistor etc.

Thanks in advance
 

pottsy1000000

New Member
Hi Rossko57

Yes that's exactly what the project is. I had intended the switch to do exactly that. At the moment my programme does a loop looking for the switch value to be in an on state.

How would you recommend the program to be to use the switch as an on/off button?

Thanks for your help
 

hippy

Technical Support
Staff member
If using your microswitch as an on-off power switch you don't need to connect it to the AXE171 board. Just cut the red battery wire and insert the switch in-line with that.

You then don't have to monitor the switch in your program; if the program is running the switch has been activated. You can probably simply remove your loop.
 

pottsy1000000

New Member
Hi everyone,

OK, so I've added the switch in line with the red battery lead, modified my program to simply initialise, set the volume and play and it works a dream.

I've had to add a small 1s pause between the initialisation and play command, which I didn't need when using the button the play the tune, else subsequent plays were too loud for the speaker (didnt seem like it was setting the volume), but that seems to have done the trick.

Thanks for your help everyone
 

erco

Senior Member
I've had to add a small 1s pause between the initialisation and play command, which I didn't need when using the button the play the tune, else subsequent plays were too loud for the speaker (didnt seem like it was setting the volume), but that seems to have done the trick.
I start every program with a short delay (PAUSE 255) to let all the voltages stabilize before the program runs.
 

westaust55

Moderator
A pause at the start of a program can be useful for a number of reasons:
1. Allowing some time before any tightly looped code that may give difficulty in downloading a new program - often needing a hard reset.
2. When following a download, the PE auto opens the terminal window ready to accept data from the PICAXE - the terminal window takes a finite time to start and typically needs around 0.5 sec program delay if there are SERTXD or SEROUT commands sending data to the terminal window almost immediately the PICAXE program commences.
3. LCD displays take a finite time to initialise hardware (after the voltage rises above a given level and within a predetermined/specified time) and the initialise of the interface (eg as 4 or 8 bit parallel) may be missed if the PICAXE sends setup/initialise data to soon after power up.
 

hippy

Technical Support
Staff member
I've had to add a small 1s pause between the initialisation and play command, which I didn't need when using the button the play the tune
As westaust55 describes, hardware takes time to be ready and that applies to the SPE035 as well. It is likely that the SPE035 was fully initialised by the time the play button was pressed after turning on, but not when interacted with immediately after powering on.
 
As westaust55 describes, hardware takes time to be ready and that applies to the SPE035 as well. It is likely that the SPE035 was fully initialised by the time the play button was pressed after turning on, but not when interacted with immediately after powering on.
The SPE035 manual says to wait 4 seconds for the player firmware to read in the file data from the TF card. Seems a long time to me but it does say that is a max.
 
Top