How to connect an LM386 with an 8-ohm 0.5W speaker to a Raspberry Pi to play music

Can someone guide me on how to connect an LM386 with an 8-ohm 0.5W speaker to a Raspberry Pi to play music through the speaker? Here's what I've done so far with the connections:

LM386 to Raspberry Pi:

  1. VCC to 5V
  2. GND to GND
  3. IN to GPIO pin

LM386 to Speaker:

  1. GND to the negative terminal of the speaker
  2. OUT to the positive terminal of the speaker

Are these connections correct? Additionally, can someone help with the code to play music?

Can you guide us about why you believe this is a programming question, and how this uses an Arduino?

For the IC, check in the datasheet, the circuit in: Application information => typical application. That's the minimum that you need and how to connect things.

If you are talking about the module, google for lm386 module for the connections. For example: DIY Arduino Music Player with Audio Amplifier Using LM386 – QuartzComponents

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Raspberry Pi has nothing to do with Arduino. You will find plenty of info on the Raspberry Pi forums.

Most Raspberry Pi's have an audio output jack.

A digital output can be made to "work" with the "right" software but it won't work very well and I don't know how easy it is to find that software for the Pi.

You can test the amplifier with the headphone output from your phone or soundcard, or the audio output on a CD/DVD player, or your TV, etc.

Presumably you have an amplifier board with an LM386 chip. The gain of the chip will be too high, so hopefully the amplifier board has a volume control pot, and you may need some additional attenuation.