Eyes up! I recently hooked up a small buzzer to my ESP8266,

esp8266
gplus
(Markus Illenseer) #1

Eyes up!
I recently hooked up a small buzzer to my ESP8266, connected to Pin D9 (GPIO3) and GND. Works great with either the tone() function or digitalWrite().

BUT
When trying to re-compile and re-upload my sketch when the buzzer was connected, the upload could not connect: espcomm_sync failed
Turns out, the D9 is also the RX0 line. This confuses the ESP.

Lesson learned: Use another pin

Question left: Is there another solution? Adding a pull-up resistor?

(Erik Slagter) #2

Use a transistor (either bjt or fet). And live with the noise during uploading…

(Dougal Campbell) #3

You could toss a switch inline, and use it to disconnect during uploads.

(Markus Illenseer) #4

@Erik_Slagter How do I do that? Any example?

(Erik Slagter) #5

Easiest is to use a low power mosfet, e.g. bs170. Connect gate to the GPIO directly, or preferribly with a small resistors, 1k will do just fine (the bs170 has a gate resistance of > 1 MOhm anyway). Connect buzzer with + to supply, - to drain of mosfet, the source of the mosfet goes to common (-). Now the GPIO won’t be loaded by the buzzer. The bs170 can supply a small signal of something like 100 mA, if you need more, use a bigger mosfet.

(Erik Slagter) #6

For my ESP8266 project I did it a tad differently:

  • connect GPIO to inverting schmitt trigger (removes a lot of noise from the GPIO pin when it’s idle)
  • connect output of schmitt trigger to simple small signal audio amplifier, you may have to add a capacitor here for DC decoupling (my amplifier has one internally)
  • connect speaker to output
  • make stable noise/glitch-free tones by using one of the two UART’s, feed it with an on/off bit pattern (0xaa or 0x55), set the baud rate to select the frequency.

Works like a charm.

(Markus Illenseer) #7

This exceeds my knowledge :slight_smile: I take it, the buzzer is not a resistor such as a normal loudspeaker, but a capacitor.

This helped me to understand your idea: blog.mbedded.ninja/electronics/components/piezos

Now, where to get BS170 in a time, where the small electronic shops have vanished and quick online suppliers sell those pieces way overpriced :slight_smile: Probably I stick to my lousy design at first…

(Markus Illenseer) #8

Found a nice example:
https://wiki.wemos.cc/products:d1_mini_shields:buzzer_shield

(Thomas Runge) #9

Well, I built an alarm clock with an ESP8266. Turned out, that it reboots every now and then after firing alarm. Sometimes before the alarm, which makes it quite useless as an alarm clock. :joy: It seems to be a problem with the timer used by tone().

(Erik Slagter) #10

The ESP8266 can be easily instable if wired up not 100% right (power supply and reset/sleep pins) and also when not programmed properly. My ESP’s tend to only reset when I tell them to :slight_smile: When you’re using Arduino, all bets are off of course.

(Markus Illenseer) #11

@Erik_Slagter BS170 arrived today. Works great! Upload is no longer blocked. Next step is to solder that on a small pegboard for production use.

(Erik Slagter) #12

Nice. The advantage of a small signal mosfet is that it needs next to no current to flow for it to operate. Saves us from difficult calculations required for BJT’s :wink: