Author Topic: Built in speaker/piezo click effect  (Read 9186 times)

0 Members and 1 Guest are viewing this topic.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Built in speaker/piezo click effect
« on: Wed, 08 April 2015, 06:23:48 »
One of the keyboards I loved in the past was the ABC77 from the Luxor ABC806 and ABC802 computers. A certain feature was the key click effect built into the keyboard. It's that sound I'd like to have in my keyboard, as an option to enable. Preferrably on all keys but the modifiers.

It sounded like this: https://youtu.be/JgZ5yfSE584?t=30s

The original sound circuit was based on the 555 timer (or rather half a 556) and looked like this:
96694-0

To begin with, I'm setting this up on a breadboard to see if I can get the sound right.

Then this will, depending on results, be replicated as closely as possibly with pwm in the teensy or with the 555 circuit connected and activated by a teensy data pin.

The only problem I see is that I'm not a coder. Haven't been programming since like 15 years back, so I'm going to need some help with modifying TMK to make this work… if anyone is up for the challenge.. probably not that difficult for someone who knows this kind of stuff. Ideas, anyone?

Offline Wilba

  • * Maker
  • Posts: 464
  • Location: Melbourne, Australia
  • Keyboard Stuff Person
    • wilba.tech
Re: Built in speaker/piezo click effect
« Reply #1 on: Wed, 08 April 2015, 22:40:41 »
If you're using TMK, it's pretty easy to set up a pin to use hardware PWM at an audio frequency to generate the beep sound. I use a pin for PWM brightness control, which drives a transistor to sink current through LEDs. You'd do it the same way, except sinking current through a speaker. I can definitely help you with the coding.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #2 on: Thu, 09 April 2015, 02:00:51 »
If you're using TMK, it's pretty easy to set up a pin to use hardware PWM at an audio frequency to generate the beep sound. I use a pin for PWM brightness control, which drives a transistor to sink current through LEDs. You'd do it the same way, except sinking current through a speaker. I can definitely help you with the coding.

Excellent! Thanks! :) I've analyzed the sound and it seems to be a square wave (of course) with a frequency of approximately 2080Hz and a duration of 10-15ms.

I'm using TMK. Modified the gh60 files to suit my layout and matrix. I'm using the esc key as fn0 with the action layer tap key feature, so if the modifiers are excluded from the clicking, the esc should not click if held down as a modifier. Also, some kind of key combination to activate/deactivate the clicking function would be nice. But let's start with the beep/click sound :)
« Last Edit: Thu, 09 April 2015, 06:32:00 by Yoe »

Offline vvp

  • Posts: 887
Re: Built in speaker/piezo click effect
« Reply #3 on: Thu, 09 April 2015, 09:53:35 »
I use simple piezo buzzer directly connected to a digital output of a controller. When the output is changed from 0 to 1 or vice verse (only one value change), it generates quite pleasant "click" sound.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #4 on: Thu, 09 April 2015, 13:43:30 »
I use simple piezo buzzer directly connected to a digital output of a controller. When the output is changed from 0 to 1 or vice verse (only one value change), it generates quite pleasant "click" sound.

Well… I my primary goal fails for some reason, this could be an option. Are you using a "passive" piezo buzzer (transducer)?

Thanks for the tip :)

Offline vvp

  • Posts: 887
Re: Built in speaker/piezo click effect
« Reply #5 on: Thu, 09 April 2015, 17:18:05 »

Offline Wilba

  • * Maker
  • Posts: 464
  • Location: Melbourne, Australia
  • Keyboard Stuff Person
    • wilba.tech
Re: Built in speaker/piezo click effect
« Reply #6 on: Thu, 09 April 2015, 19:54:42 »
If you're using TMK, it's pretty easy to set up a pin to use hardware PWM at an audio frequency to generate the beep sound. I use a pin for PWM brightness control, which drives a transistor to sink current through LEDs. You'd do it the same way, except sinking current through a speaker. I can definitely help you with the coding.

Excellent! Thanks! :) I've analyzed the sound and it seems to be a square wave (of course) with a frequency of approximately 2080Hz and a duration of 10-15ms.

I'm using TMK. Modified the gh60 files to suit my layout and matrix. I'm using the esc key as fn0 with the action layer tap key feature, so if the modifiers are excluded from the clicking, the esc should not click if held down as a modifier. Also, some kind of key combination to activate/deactivate the clicking function would be nice. But let's start with the beep/click sound :)

If you don't plan to use LED backlighting, you could reuse the backlight actions in TMK for controlling the clicking function. Due to how TMK is structured, there's a shortage of identifiers for adding more actions.

I recommend using two hardware timers, one that directly controls the PWM output of a pin, the other as a simple timer connected to an ISR with a 1ms period. Key down events that should cause a click will set a counter to 15 (for 15ms). The ISR decrements that counter and enables sound output if the counter is greater than zero.



 

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #7 on: Fri, 10 April 2015, 01:52:07 »
If you're using TMK, it's pretty easy to set up a pin to use hardware PWM at an audio frequency to generate the beep sound. I use a pin for PWM brightness control, which drives a transistor to sink current through LEDs. You'd do it the same way, except sinking current through a speaker. I can definitely help you with the coding.

Excellent! Thanks! :) I've analyzed the sound and it seems to be a square wave (of course) with a frequency of approximately 2080Hz and a duration of 10-15ms.

I'm using TMK. Modified the gh60 files to suit my layout and matrix. I'm using the esc key as fn0 with the action layer tap key feature, so if the modifiers are excluded from the clicking, the esc should not click if held down as a modifier. Also, some kind of key combination to activate/deactivate the clicking function would be nice. But let's start with the beep/click sound :)

If you don't plan to use LED backlighting, you could reuse the backlight actions in TMK for controlling the clicking function. Due to how TMK is structured, there's a shortage of identifiers for adding more actions.

I recommend using two hardware timers, one that directly controls the PWM output of a pin, the other as a simple timer connected to an ISR with a 1ms period. Key down events that should cause a click will set a counter to 15 (for 15ms). The ISR decrements that counter and enables sound output if the counter is greater than zero.

I don't plan to use LED backlighting, so that sounds good.

So, if I get this right I can set a second 555 as a monostable circuit to create a 10 to 15 ms pulse to the PWM 555 with a trig pulse from the Teensy. Not sure how the 555 works, but I guess a new trig will make the timer start over. May need an inverter or two too... http://www.ohmslawcalculator.com/555-monostable-calculator

Offline Wilba

  • * Maker
  • Posts: 464
  • Location: Melbourne, Australia
  • Keyboard Stuff Person
    • wilba.tech
Re: Built in speaker/piezo click effect
« Reply #8 on: Fri, 10 April 2015, 02:02:53 »
I'm not an expert at 555 timers, I usually just adapt other people's circuits.

For this, I'd probably adapt the circuit from Le Dominoux:


It's essentially what you need - a trigger pulse driving a fixed duration output pulse.

Though honestly, I wouldn't even bother with the 555 and go straight to coding the ATmega to do what I want.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #9 on: Fri, 10 April 2015, 02:31:13 »
I'm not an expert at 555 timers, I usually just adapt other people's circuits.

For this, I'd probably adapt the circuit from Le Dominoux:


It's essentially what you need - a trigger pulse driving a fixed duration output pulse.

Though honestly, I wouldn't even bother with the 555 and go straight to coding the ATmega to do what I want.

Oh, I thought that was what you meant with "hardware timers". So there are hardware timers in the ATmega? Well then! Let's do it all in the Teensy! :) You see why I need help with this.. :D

Offline Wilba

  • * Maker
  • Posts: 464
  • Location: Melbourne, Australia
  • Keyboard Stuff Person
    • wilba.tech
Re: Built in speaker/piezo click effect
« Reply #10 on: Fri, 10 April 2015, 02:49:29 »
Yeah, what I meant was, use one hardware timer on the ATmega to drive one output pin at the desired audio frequency. Set the duty cycle to the desired pulse width (i.e. 50% will get you the square wave typical of "beep" sounds).

I already use a hardware timer/PWM output for brightness control: https://github.com/Wilba6582/tmk_keyboard/blob/master/keyboard/planck/backlight.c
That code can be adapted to become the audio output. You would need to free up PB7 if you are already using it, or adapt the code to use a different pin connected to that timer, or a different timer/pin combination. In your case, I think resoldering one wire is probably easier than getting your head around the ATmega timer register  ;D

I think I'll just hunt in my parts bin for a piezo and try to get beeping going on my Planck and then link you to the TMK code.




Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #11 on: Fri, 10 April 2015, 03:19:54 »
I don't think I'm using PB7, but I'm using the gh60 files, so matrix.c must be modified to remove the PB7 (rev B pin.. I belive I'm using PB0 from rev A) from the pin confiuration.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #12 on: Sun, 12 April 2015, 00:56:18 »
Turns out I my piezo was experimented to death in the past, but I've ordered a bunch of new ones. So if this works out nicely, I can but this clicker in all my keyboard projects :) How's the beeping coming? (No rush, just curious.)

Offline Wilba

  • * Maker
  • Posts: 464
  • Location: Melbourne, Australia
  • Keyboard Stuff Person
    • wilba.tech
Re: Built in speaker/piezo click effect
« Reply #13 on: Sun, 12 April 2015, 22:04:36 »
Nothing yet, I couldn't find a piezo in my parts bins. Plus I'm still looking at how to hook into key press events. It would be nice if this was generic enough to use for both beep effects and backlight effects, like what Easy AVR does... i.e. backlight gets brighter the faster you type.

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #14 on: Sun, 28 February 2016, 12:07:08 »
Necro! Breakthrough in the key beep area! Got some help from a programming wiz friend, and now it works!

I dropped the idea of not having the modifiers beep. They all beep now, and I love it! I may add some kind of mute or volume control later on, but for now I'm good :)

Basically it's a modification of Tone.cpp from the Arduino library, and it's called from the Matrix.c to make a 15ms beep at 2080Hz whenever a key is pressed.

https://github.com/Trasselfrisyr/tmk_keyboard/tree/y6x/keyboard/y63b

The piezo is just soldered in between C7 and GND on the Teensy, like this:

129811-0

and the result...

https://www.instagram.com/p/BCVTHnUoVdk/?taken-by=trasselfrisyr

Offline CPTBadAss

  • Woke up like this
  • Posts: 14368
    • Tactile Zine
Re: Built in speaker/piezo click effect
« Reply #15 on: Sun, 28 February 2016, 12:07:54 »
Necro! Breakthrough in the key beep area! Got some help from a programming wiz friend, and now it works!

I dropped the idea of not having the modifiers beep. They all beep now, and I love it! I may add some kind of mute or volume control later on, but for now I'm good :)

Basically it's a modification of Tone.cpp from the Arduino library, and it's called from the Matrix.c to make a 15ms beep at 2080Hz.

https://github.com/Trasselfrisyr/tmk_keyboard/tree/y6x/keyboard/y63b

The piezo is just soldered in between C7 and GND on the Teensy, like this:

(Attachment Link)

and the result...

https://www.instagram.com/p/BCVTHnUoVdk/?taken-by=trasselfrisyr

Saw this when I woke up today. So ****ing awesome. Yoe slaying the Alps mods again :D

Offline Yoe

  • Thread Starter
  • Posts: 273
  • Location: Skellefteå, Sweden
  • Alps & ISO <3
Re: Built in speaker/piezo click effect
« Reply #16 on: Sun, 28 February 2016, 12:14:45 »
Necro! Breakthrough in the key beep area! Got some help from a programming wiz friend, and now it works!

I dropped the idea of not having the modifiers beep. They all beep now, and I love it! I may add some kind of mute or volume control later on, but for now I'm good :)

Basically it's a modification of Tone.cpp from the Arduino library, and it's called from the Matrix.c to make a 15ms beep at 2080Hz.

https://github.com/Trasselfrisyr/tmk_keyboard/tree/y6x/keyboard/y63b

The piezo is just soldered in between C7 and GND on the Teensy, like this:

(Attachment Link)

and the result...

https://www.instagram.com/p/BCVTHnUoVdk/?taken-by=trasselfrisyr

Saw this when I woke up today. So ****ing awesome. Yoe slaying the Alps mods again :D

Haha, thanks CPT! :D Maybe not slaying but perhaps nudging the Alps mod envelope a bit ;) 

Offline yangdigi

  • Posts: 79
  • Location: China
Re: Built in speaker/piezo click effect
« Reply #17 on: Sat, 26 March 2016, 20:01:45 »
Necro! Breakthrough in the key beep area! Got some help from a programming wiz friend, and now it works!

I dropped the idea of not having the modifiers beep. They all beep now, and I love it! I may add some kind of mute or volume control later on, but for now I'm good :)

Basically it's a modification of Tone.cpp from the Arduino library, and it's called from the Matrix.c to make a 15ms beep at 2080Hz whenever a key is pressed.

https://github.com/Trasselfrisyr/tmk_keyboard/tree/y6x/keyboard/y63b

The piezo is just soldered in between C7 and GND on the Teensy, like this:

(Attachment Link)

and the result...

https://www.instagram.com/p/BCVTHnUoVdk/?taken-by=trasselfrisyr
interesting work.