iTranslated by AI
Investigating the Operating Principle of SonarPen
Recording Audio Data During SonarPen Operation to See How It Works
Since the SDK is proprietary and doesn't seem to be publicly available, I'm simply testing it by combining an iPad with a compatible app (MediBang Paint).
What is SonarPen?
-
http://sonarpen-japan.com/
- Official site
-
https://blog.mistlake.net/archives/573
- Review article. My SonarPen came in a much more compact package.
SonarPen is a pressure-sensitive stylus for tablets. While typical styluses transmit pressure information via electromagnetic resonance or Bluetooth wireless, SonarPen uses audio feedback via the tablet's 3.5mm earphone/microphone jack.
...Well, it works exactly as you might imagine.
The developer himself has posted development articles on hackaday.io, and the shared expertise is quite interesting.
A good example would be the iOS detects the existent of a 1k ohm resistor between the MIC and Ground line to tell if the earphone has a MIC on it. Similarly, a Samsung Android device needs the resistor to be 1.4k ohm to confirm a MIC on an earphone. So my stylus has a 1.5k ohm resistor on its circuit for broader compatibility.
A little thing worth mention is all iOS devices sold in EU countries have a lower maximum earphone volume than the ones sold outside.
One mystery is that the SonarPen comes with two types of tips with different disc diameters: one for iOS (left in the photo) and one for Android (right), with the Android one being larger. Perhaps there's an assumption that it's better not to apply too much pressure to the screen on Android devices.
In any case, the conductive rubber tip with a disc is a very common configuration for cheap tablet styluses. SonarPen can also be used as a non-pressure-sensitive touch pen even when not connected to the headphone jack.
How It Works
SonarPen is simply an "audio loopback cable" that returns the outputted audio as a microphone input. The volume of that loopback changes according to the pen pressure and button state.
In fact, by treating the SonarPen as an audio loopback dongle, it can even be used for measuring audio round-trip latency with tools like RTL Utility (Wait, what?). This means the volume doesn't drop to zero even when the pen isn't touching the screen.
The principle is very analog, but it has the advantage of providing functionality on closed platforms like iOS or game consoles, as long as the device can handle audio input and output.
Recording Audio During Operation
This time, I recorded the audio using two types of headset splitter cables (one for splitting a headset into PC connections and its inverse), an Amazon Basics distribution adapter, and a USB audio input.
Audio Output from the Tablet
It seems to use a sine wave of around 440Hz for sensing. Additionally, it only uses the right channel.
...For example, if you consider detecting button presses with a filter, it feels like a waveform with more varied components might be better.
Safety Measures
Looking at the waveform above, the amplitude is at full scale from -1.0 to 1.0. Listening to this for a long time would likely be deafening, but it seems no specific safety measures are included.
On my end, when I inserted standard music earphones, the audio output automatically turned OFF after about 0.5 seconds, but I couldn't tell if this was an iPad feature or an effect of the SonarPen SDK. With the EarPods that come with the iPod or a line-in for recording, the sine wave continued to be audible normally.
(I am testing with iPad's "Reduce Loud Sounds" turned OFF.)
Since mono headset earphones using the CTIA standard often have the left channel and MIC wired together while the right channel is disconnected, using only the right channel for sensing might be a way to ignore the sensing audio when swapping between a SonarPen and a standard headset.
Audio Input to the Tablet
The audio returning from the SonarPen seems designed so that higher pen pressure results in higher volume.
↓ In this capture, I am gradually increasing the pressure and then releasing it.
Since it's also affected by the microphone gain on the device side, apps like ibis Paint provide a dedicated calibration UI.
Button
It wasn't clear what kind of effect the button has. In fact, the official website advises turning off Siri to make the button work, giving the impression that it's not very stable.
↓ In this capture, I am pressing and releasing the button twice.
Unlike pen switches on Wacom tablets, the SonarPen button seems intended to be used while the pen is away from the screen.
Impressions
Since it's getting power in the form of an audio signal, I wonder if it could have been made into an active stylus. Well, I suppose that might be difficult if there's a requirement for the pen tips to be cheap and replaceable. It seems devices like the iPod also automatically measure impedance and such, so it might not be very reliable as a power source.
I looked into this because I wondered if it could be used from a browser via WebAudio or similar, but since there's no way to implement palm rejection aside from the audio part, it might be tough for practical use.
The behavior mentioned in the safety measures section, where the audio automatically turns OFF with certain earphones, is quite a mystery. I wonder if I should write an app that outputs audio and test it. Come to think of it, there is feedback even at zero pressure, so if the gain is zero for a certain period or if the noise floor is high, it could just be considered that something other than a SonarPen was plugged in and the output could be stopped.
Audio Input as a Peripheral Interface
What many people associate with the SonarPen is likely the Square magnetic card reader ( https://web.archive.org/web/20120822034147/http://proteanpayment.org/?p=45 ). While the earphone jack itself is heading toward obsolescence, the SonarPen can operate normally with digital audio adapters, so new applications might still be possible.
Other methods, such as inputting from an Arduino using FSK ( http://www.creativedistraction.com/demos/sensor-data-to-iphone-through-the-headphone-jack-using-arduino/ ), were effective ways to establish peripherals using only standard OS features without writing hardware device drivers.
Discussion