Tim Bratcher

I have always wanted to add sounds to my layout and have been looking for a DIY approach, so I could have maximum flexibility.  I came across micro MP3 players on a website (usually in the context of an Arduino) and decided to see if I could make it work with a microchip.com microcontroller (in this case, a PIC16F15356).  I got it to work, which was pretty amazing.  The little MP3 player cost a whopping $1.89 from ebay and the microcontroller rang in at about $0.75,  The most expensive part is the micro SD card, but I think I might have a better solution for that . . . using a USB flash drive (which are considerably less expensive). 

The linked video shows my "proof of concept," and gives an overview of how I might employ it on the layout.  As I get farther along, I'll report back.

Here's the video:

Tim

Reply 0
Juxen

Awesome!

I'd been wondering about this same issue for quite some time now. I don't have the coding ability like you wizards do, so I figured I'd rely on MP3 players, random mp3 tracks of silence, and a randomizer. Your solution is way better.

Reply 0
Neil Erickson NeilEr

Code and schematic

That idea looks, and sounds, like it would have a whole lot of possibilities! How about an ir detector in there as well? It could sense the presence of a train or operator and add some additional variation. When a train arrives at a station the crowd noice would come up and announcements begin ...
 

If you use an inexpensive buck converter it might be easy to tap off the DCC bus, or rails, to step down to 5 volts as well. In fact, the whole biz might fit in a freight car aka Soundraxx Sound Car. They must have added in an accelerometer to trigger angry cows (LOL) or just the sound of a refrigerator compressor going on and off. 
 

Please consider posting a DropBox or Google Drive link to the schematic and your test code. It would take a couple weeks to get the parts but I would look forward to trying to incorporate some random sounds on my layout. Thanks!

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Jim at BSME

Option

Of course you can always use an Arduino Pro mini, which does cost ($4/ea in 5 qty on ebay) more than just a microprocessor, but connections would be easier in my opinion. The cost of pro minis has gone up, if you find cheaper ones they likely don't come with free shipping. And you can use Geoff Bunza's code, see the article Geoff did in December 2016 issue.

This link takes you directly to the sound projects:  http://mrhpub.com/2016-12-dec/online/html5/index.html?page=177&noflash

While Geoff uses an Arudino Uno for his article, everything he does can be done with the smaller pro-mini or nano form factor. Also on page 16 of the article talks about controlling the projects with a PIR detector.

- Jim B.
Baltimore Society of Model Engineers, Estd. 1932
O & HO Scale model railroading
Check out BSME on: FacebookInstagram
Reply 0
AzBaja

I have a little set up that

I have a little set up that plays Mech Reefers in front of the Sunkist Packing house (I would like to do this with the other 6 Fruit/Vegetable/Cold Storage/packing platforms on the layout).  This might be a better option to look into and have it detect what reefers are on what spots so a track of 6 or 8 makes more noise than the single reefer sitting on a siding.  

That is just way to wordy of a video get to the point.  We do not need to know every power connection etc. we all know how to do this just show how the device works and what it does.   post a schematic of the wiring etc.  This could of been done under 5 minutes.

AzBaja
---------------------------------------------------------------
I enjoy the smell of melting plastic in the morning.  The Fake Model Railroader, subpar at best.

Reply 0
Tim Bratcher

You're living proof that you

You're living proof that you can't please everyone!  I made that video for my dad (who's an elderly electronics guru . . . but learned his chops in vacuum tube world (with a hint of transistors)).  He appreciates the full explanation, especially because we haven't seen each other since March because of COVID.  I decided to share it here because there is hardly any information at all about using microcontrollers and DF Mini's.  Yes, there's a fair amount out there for the Arduino's and its kin, but not "real" MCUs.

Good thing about the internet is that you control what you do and see and watch.  My advice is that if you don't want to watch something, move on to something else.  But I do have to wonder how many good ideas are not shared because people don't want to suffer the public shaming and disrespect that comes from vultures who hang about ready to pounce on someone else's thoughts, ideas, skills, or methods.  There so much good on these boards in terms of the ability to share so much information . . . I guess armchair critics are just the price we have to pay.

Reply 0
Tim Bratcher

Arduino versus PICs

Thank you for pointing out the Arduino page!  In searching through the internet, I could find a number of posts concerning the Arduino and its kin, but hardly nothing on out-of-the-box PICs.  The Arduinos are great, but costly and the size of the boards they come on can limit the ways you can use them.  The PIC I've used in the video (which is actually much more of a chip than I actually need) cost only 75 cents or so.  I could have used one that would have been in the 50 cent range.  Arduinos have less steep of a learning curve, but there's so much control over a raw PIC, once you dig into the code and how to implement it.  All of that said, the Arduinos are what originally piqued my curiosity in the microcontroller world, so my hat's off to them!

Reply 0
Tim Bratcher

Thank you, NeilEr, and yes

Thank you, NeilEr, and yes the possibilities are tremendous.  Indeed, I hadn't even through of an IR trigger to trigger sounds in a particular context and particular way.  I have created circuits with an IR trigger, and I think I'll give that a shot.  I'll let you know how it goes.  As for the code, I will post it--once I clean it up a little.  I just got it working last night, and I want to make sure it's stable.  There is no doubt that the entire thing could be installed in a freight car.  It's tiny, and I could easily use an 8 or 14 pin chip instead of the 28 pin chip I am using for testing.

The sounds are limited only by the size of the micro SD card . . . so:  a ten minute clip of a babbling brook near your stream; the sounds of a little down; sirens in the distance; a honky tonk bar; people arguing; in a wooded area, the sounds of birds chirping; foxes and wolves; machine shops and repair facilities; a shift change whistle; etc.

On my layout, I have a track bus and I have a separate five volt "structure" or "accessory" bus.  The structure bus has three wires:  +5v, Gnd, and a "separate" +5v (which I call the "control wire").  The +5 / GND are just the ordinary + / - (white and black wires).  The control wire ties to a switch on the control panel and once that switch is flipped, it sends a "high" (or +5 volts) to the microcontroller input pin, which that pin then reads as a "true" for programming purposes.  In my particular application, when the control wire is disconnected, it is "daytime."  When I put the +5v on the control wire, it is "night time."  This adds even more possibilities.  I should write a post about it sometime, but you can sort of see it here:

Please keep in mind that I made that video (like the one for the MP3) for my dad, so it's more involved than may otherwise be necessary.

 

Reply 0
Ken Hutnik huthut

Thanks for sharing!

Very neat, thank for sharing your tinkering!


Ken
My projects: Ken's Model Trains
Reply 0
Neil Erickson NeilEr

Pretty neat

Now I assume that the sounds and lights could be combined so that the welder might have a sound associated with the flashing light? That is more than pretty neat. 
 

I’d forgotten that one of our forum members, Scott Thornton, has a similar random sound generator, several actually, triggered by IR  detectors in his track to produce a variety of wheel squeal sounds on curves. 

https://forum.mrhmag.com/post/ambient-and-triggered-sound-for-the-milan-branch-12201144

Neil Erickson, Hawai’i 

My Blogs

Reply 0
Jim at BSME

re: Arduino versus PICs

Of course the heart of the Arduino is a Atmel ATMega328P MCU, which  Atmel is a competitor to MicroChip.

I am surprised you didn't find any references to the ATtiny84/85, they seem to be very popular "replacements" for the Arduino, same idea raw MCU.

- Jim B.
Baltimore Society of Model Engineers, Estd. 1932
O & HO Scale model railroading
Check out BSME on: FacebookInstagram
Reply 0
Chris VanderHeide cv_acr

Sound Car

Quote:

I have a little set up that plays Mech Reefers in front of the Sunkist Packing house (I would like to do this with the other 6 Fruit/Vegetable/Cold Storage/packing platforms on the layout).  This might be a better option to look into and have it detect what reefers are on what spots so a track of 6 or 8 makes more noise than the single reefer sitting on a siding.

The other alternative is SoundCar decoders in each reefer with the reefer unit sound - a little expensive, but you get the reefer sound wherever the cars happen to be.

Reply 0
AzBaja

I have 72 Reefers n the layout

Quote:

The other alternative is SoundCar decoders in each reefer with the reefer unit sound - a little expensive, but you get the reefer sound wherever the cars happen to be.

Chris van der Heide

It is N scale and I have 72 PFE/WFE/SFRC etc. refers on the layout... I would go broke

AzBaja
---------------------------------------------------------------
I enjoy the smell of melting plastic in the morning.  The Fake Model Railroader, subpar at best.

Reply 0
Chris VanderHeide cv_acr

Poor house

Quote:

It is N scale and I have 72 PFE/WFE/SFRC etc. refers on the layout... I would go broke

There's that I suppose.

Reply 0
Tim Bratcher

Next Level . . .

So I have taken a few more steps on this project, and here's a video update:

I have added a USB port so I can use a USB thumb drive instead of an SD Micro Card.  Here's the reason: 

The sound files on this project are mono rather than stereo, so the files are relatively small.  For example, 30 minutes of sound in mono is only about 55 MB . . . that's MEGAbytes (not GIGAbytes).  So that's tiny in comparison. 

But when I went to look for small SD Micro Cards, I couldn't find anything new under 1GB.  And those were about $10 a piece.  I could, however, find 256 MB USB thumbdrives, and those were only about $1.25.  In all my research, I've never seen anyone use the DF Mini MP3 player with a USB, but it is capable of it.  So this video shows how I did it.

Next up, I'll show how I reduced this to a project circuit board.

Reply 0
Tim Bratcher

Final Prototype

Here's a video showing the final prototype:

I've noted that my pricing is all over the board, so for curiosity, I looked it all up:

1.  PIC 16F15325 (from microchip.com):  $1.01

2.  DF Mini MP3 Player (from eBay):  $1.89

3.  14-Pin DIP Socket (from eBay):  $0.18

4.  7cm x 3cm Prototyping Board (from eBay):  $0.99

5.  1K Resistors (x3) (from eBay):  $0.03

6.  10K Resistor (from eBay):  $0.01

7.  1nF Ceramic Capacitor (from eBay):  $0.01

8.  256MB USB Thumb Drive (from eBay):  $1.80

9.  USB Socket (from eBay):  $0.49

10.  21mm 8 Ohm Speaker (from eBay):  $0.36

GRAND TOTAL:   $6.77

Best,

Tim

Reply 0
BruceNscale

Reefer Sound Using 555 Timer

Good Morning All,

Back in the day, I equipped several N scale mechanical reefers with 555 timers to generate the putt-putt diesel noise.  They used track power and earphones as the output speaker.  Two or three per train were enough to give the impression that the reefers were doing their job.

I also used farm animal novelty keychains, to add cow and sheep noises to livestock cars.  It always amused the children at shows and made the layout more entertaining.

 

 

ignature.jpg 

Happy Modeling, Bruce

Reply 0
Juxen

Kinda wishing...

I'm kind of wishing that there could be an interaction or way to combine an ambient mixer like this one:  https://www.ambient-mixer.com/ and a layout. I know there's a phone app, but I mean in terms of having a computer (like a Pi) and multiple audio channels for different points on a layout. Basically, something that you can update and modify over time or even over the internet, and has an ability to randomize sounds.

And for the really ambitious, have it tie into the layout, so that if you run a night session, you stop hearing cicadas and birds, and start hearing crickets and wind.

 

Edit: Thanks for reigniting this thread, now I'm down the rabbit hole of trying to figure out exactly how many audio channels I can set up using one Pi. Apparently, there's a kickstarter that allows for 8 stereo channels through the GPIO pins. If you can set up at least one each (or run in mono for 16 channels), then you can conceivably run 16 audio streams through one Pi, and still have all the functionality of a RPi.

Reply 0
Tim Bratcher

Juxen . . . when you say

When you say "trying to figure out exactly how many audio channels I can set up using one Pi."  What exactly do you mean?  I'm curious about "what" you'd be running through GPIO pins?  (I'm not an Arduino / Raspberry guy, so I'm not sure what audio capabilities might exist on on those platforms.

Reply 0
Juxen

So...

Most computers (Raspberry, Microsoft, etc.) come with an audio jack for audio output. However, this means that you can only run one audio "channel" or output at a time. Rather than buy and set up and keep updating a set of Raspberry Pis for every audio channel I want, I could let the computer be a computer and actually handle the outputs, running up to 8 stereo channels at a time. I paid for 1.2 GHz in a RPi 3, I may as well use it.

There's a  kickstarter campaign that allows the GPIO pins to handle the extra audio jacks. Apparently sound-loving people have been using this for a few years, so there's a capability to run multiple sounds at a time. Someone has made their own system to run 8 sounds at a time (

), so a Pi is capable of handling the load.

From there, it's a question of coding.

Reply 0
Yaron Bandell ybandell

DF Mini Player and Raspberry Pi GPIOs?

Juxen,

Why not use the GPIOs of a Raspberry Pi to start/stop DF mini players by bitbanging the GPIOs to act as a serial port to the DF player mini? You'd have full control over which tracks to play, pause, start and stop. If not enough GPIO pins on the RPi, using some GPIO pins as an I2C bus instead with some I2C I/O expander ICs will help to setup an environment that can control a lot more DF Player Minis.

Remember, when you are trying to add ambient noise to a layout, you don't have to hold the sounds in a central location and only have the speakers at the desired locations. You could go for a decentralized model where the DF Players are distributed across the layout and loaded with the desired set of sounds and the RPi simply tells these distributed DF Players to play a specific sound from a slot on their internal storage.

Reply 0
Juxen

Umm...

...if I had known that was a thing on a Pi, then I would totally have gone for it. That makes way more sense, is way easier, and is probably way cheaper.

Reply 0
Matt Goodman

Thanks Tim!

Thanks for starting this thread, and providing details, @Tim. I've considered adding audio to my layout for some time - and with this (lack of) expense, it's worth experimenting. Tying it into triggers is something I'm sure could easily be added on later. No sense biting off more than needed!

Matt Goodman
Columbus, OH, US
--------------------------
MRH Blog
VI Tower Blog - Along the tracks in pre-war Circleville, Ohio
Why I Model Steam - Why steam locomotion is in my blood

Reply 0
Tim Bratcher

The Complete Project?

4_010209.jpg 

So here's the first truly "working" prototype, along with a video explaining things a bit better.  There is one problem which have I have not fully addressed yet, and that is "switch debouncing," which is kind of a pain, especially considering that I'm using a really cheap switch.  But I can overcome it!

Here's the video: 

The key part of the video, which I've had a hard time explaining, is that this device is controlled by a "control wire" and has a day and night mode.  There is a three-wire bus running under my layout for accessories.  That bus has a black and white set of wires (which are nothing more than +5 volts and ground (normal + / - for a power supply) and then the control wire.  The control wire is nothing more than another tap from the +5 volts.  It's the same as the +5 volts powering the accessories (i.e., the "white wire"). 

The orange wire, however, is connected to an input pin on each chip, and the chip reads that +5 volts as a "true" (if it's on) or a "false" (if it's off).  This allows me to have two states--day time and night time.

The thumb drive has two folders with tracks in them.  The first folder contains "day" sounds, while the second folder contains "night" sounds.  This is all controlled by turning the switch for the orange wire (or the control wire).  This allows me to "communicate" with the chips.  As an added bonus, if I flip the switch twice, in rapid succession, then it goes into mute mode.

So that's it for now.  Time now to focus on (A) getting a better mix of the sound effect tracks (which I am doing in a free program called Audacity) and (B) trying to set it up to respond to a trigger such as an infrared emitter detector or a light dependent resistor.

I will post a schematic at some point. 

Remember that the parts for this were only $6.77.

Would appreciate your thoughts and ideas.

Reply 0
Juxen

Very awesome

I'd be very interested in learning about this circuit.

Reply 0
Reply