## Stroboscope Guitar Tuner With RPi-Controlled LEDs

rfrizz
Posts: 5
Joined: Sun Mar 10, 2019 4:14 pm

### Stroboscope Guitar Tuner With RPi-Controlled LEDs

I have spent a while with goog searching for answers, but I can't quite find the answers. I have seen an Arduino project for this, but I do not know how good it is, and I want to do it with a Raspberry Pi. For anyone not familiar with tuning a stringed instrument with a stroboscope, I have a short explanation at the end.

I want to make a true stroboscope for tuning guitars and basses. There are commercially available chromatic "strobe" tuners available, but they really microprocessor based, and perform a fast Fourier transform to determine the frequency of the string, and it makes a row of lights appear to move the way a string would look under a strobe light. They are good, but they cost US\$75-\$120, and they are not as good as a true stroboscope tuner.

I want to start with a simple project, so a strobe at 440Hz (which is the international standard "concert pitch") will be enough.

The first question is feasibility. For a strobe to be good enough, the frequency needs to be accurate to within roughly 0.1 milliseconds. Also, an LED needs to be able to turn on and off for around 1ms, or maybe 10-20us -- microsecond AKA millionths of a second.

From what I can tell, a regular LED can do this. The other questions are 1) can a RPi can illuminate the LED for this period; and 2) can a RPi make it cycle at 440Hz, ±0.05Hz?

One other question is the complexity of a program required. If a simple loop based on the system clock will do this, it would be on the level of an easy-peasy assignment in an introductory C class.

So, thoughs?

How a strobe tuner works:
Stroboscopes work by illuminating a vibrating string with a rapidly flashing light at the desired frequency. When a vibrating string's frequency matches the strobe's, the string appears to be stationary, but if its frequency is a little higher or lower, it appears to move slowly, and the greater the difference between the two frequencies, the more rapid the apparent motion.

A tuned guitar's A string -- the second-largest -- vibrates at 110Hz. If the strobe is flashing at 110Hz it will appear to be stationary, but if the string is tuned down to 109Hz, it will appear to be moving back and forth at one cycle per second. If the string is at 111Hz, it will look the same as at 109Hz.

If the string is at 108Hz or 112Hz, it will be 2 cycles per second. At 107Hz/113Hz, 3 cycles per second, and so on. When tuning a string, you first get it close, and then use the strobe to fine tune it. As the strings frequency approaches the strobe's frequency, it appears to swing more and more slowly until it stops. At that point, it is at the right pitch.

Burngate
Posts: 5930
Joined: Thu Sep 29, 2011 4:34 pm
Contact: Website

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

I would think the Pi is the wrong tool for the job.

Yes, a Pi could illuminate a LED for the required short time, but No, it couldn't do so at precisely the right rate, and certainly not using the standard Raspbian (Linux) operating system.
That's because it's not only running your program - it's also going off on its own, looking after the rest of the system.

A simple crystal oscillator and divider chain could more easily produce what you require, and the divider chain could be controlled by a Pi to produce the other frequencies you want.

You're asking for 440 ±0.05 Hz.
That's about 0.01%, so you'd have to watch the string for a long time to see it cycle

Heater
Posts: 12960
Joined: Tue Jul 17, 2012 3:02 pm

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

I'm pretty sure it can be made to work on a Pi.

For a start, don't we have PWM generators that can be set to various frequencies?

In the last resort one can toggle a GPIO pin in software from a spare core of a multi-core Pi at up to 50MHz with only occasional 5us jitters.

Burngate
Posts: 5930
Joined: Thu Sep 29, 2011 4:34 pm
Contact: Website

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

While I was writing wot I rote, I had in the back of my mind both of those options, and it took just over an hour for someone to find the holes in my argument.

It rather depends on what you consider easy or complex, in terms of either software or hardware.

I would consider using the Pi's hardware PWM generators to be towards the easy end of software, whereas using a separate core would be towards the complex end.

For a hardware solution, many people coming here appear consider connecting an a-d chip a daunting prospect, so my suggestion would be out of the ball-park, but you've had (according to your Introduce yourself! post) some experience with hardware, and even have a rather nice digital 'scope, so it might not be beyond you.
Or use the Arduino project - people have had success interfacing Arduinos to Pis.

MarkTF
Posts: 295
Joined: Tue Mar 03, 2015 4:59 pm

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

Generating this signal is pretty trivial with the pigpio library using the hardware PWM. Frequency accuracy would be equivalent to the processor crystal (something like 50 parts per million) plus the discrete tune frequency step error which is also small at these frequencies.

As an example in Python the following code will put a 10% duty cycle 110 Hz (A2) PWM signal on pin BCM18:

Code: Select all

``````import pigpio				# Import library
pi = pigpio.pi()			# Class instance of pigpio
pi.hardware_PWM(18, 110, 100000)	# Start hardware PWM, pin 18, 110 Hz, 10% duty cycle
``````
In a darkened room room with a white LED & 300 Ohm resistor this clearly showed the string beat frequency on a guitar.

Most microcontrollers, e.g. Arduinos, have similar HW PWM capabilities. I tested also with a microcontroller-based PWM module* with the same effect. This board isn't crystal controlled so its frequency accuracy isn't very good compared to the RPi.

* - https://abra-electronics.com/voltage-re ... cycle.html

rfrizz
Posts: 5
Joined: Sun Mar 10, 2019 4:14 pm

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

MarkTF wrote:
Tue Mar 12, 2019 2:17 am
Generating this signal is pretty trivial with the pigpio library using the hardware PWM. Frequency accuracy would be equivalent to the processor crystal (something like 50 parts per million) plus the discrete tune frequency step error which is also small at these frequencies.

As an example in Python the following code will put a 10% duty cycle 110 Hz (A2) PWM signal on pin BCM18:

Code: Select all

``````import pigpio				# Import library
pi = pigpio.pi()			# Class instance of pigpio
pi.hardware_PWM(18, 110, 100000)	# Start hardware PWM, pin 18, 110 Hz, 10% duty cycle
``````
In a darkened room room with a white LED & 300 Ohm resistor this clearly showed the string beat frequency on a guitar.
Three lines of code? You rawk!

With something to boost the strobe intensity, plus a speaker all that's needed is an OLED screen, a few buttons, and some user interface coding. Put it in a plastic casing with a battery supply, and it is a working POC for something which could possibly compete with the \$125 Peterson strobes.

MarkTF
Posts: 295
Joined: Tue Mar 03, 2015 4:59 pm

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

I hadn't known about this sort of tuner prior to your posting and now you've got me motivated to try to build up one of these. I've just placed an order for 1 Watt LEDs and have sketched out some drive circuit ideas to try out. When (if?) I get around to building something I'll post an update.

I'll probably ultimately do a microcontroller based system (faster boot/easier battery requirements) rather than RPi, but concepts are the same.

rfrizz
Posts: 5
Joined: Sun Mar 10, 2019 4:14 pm

### Re: Stroboscope Guitar Tuner With RPi-Controlled LEDs

MarkTF wrote:
Thu Mar 14, 2019 1:25 pm
I hadn't known about this sort of tuner prior to your posting and now you've got me motivated to try to build up one of these. I've just placed an order for 1 Watt LEDs and have sketched out some drive circuit ideas to try out. When (if?) I get around to building something I'll post an update.

I'll probably ultimately do a microcontroller based system (faster boot/easier battery requirements) rather than RPi, but concepts are the same.
There are a couple of Arduino projects I've seen. One was guitar specific, and the other was general purpose. The general one has an LED display showing Hz, and there is a knob below the display to control frequency.

I'll go find them if you want, but you may want to try it the "hard" way since we tend to learn more that way.