This experiment may or may not end up using an arduino as a go between- the initial goal was to operate a servo via android phone as simply as possible withough a pile of drivers, libraries, and custom configuration, but now its evolved into a PWM experiment. Most recently I got an OTG audio adapter that seems to work fine to output audio to headphones, speakers or whatever from the USB-C plug. Great! So the way that works is it includes a tiny DAC circuit in the plug, and outputs analog audio as expected.
It was my hope that I could use an app like PWM buddy to then control a servo. Unfortunately, it seems like: A) PWM buddy doesn't work or is no longer supported. and/or B)Maybe I need to amplify or clarify the "audio" output from the source in order for the servo circuit to interpret it properly.
Ok, so taking a step back, I thought maybe I could skip the app and instead send a signal directly from my laptop. I did this by using +5v from a usb port, and trying to use either of the audio output channels from a 3.5mm audio out cable (I twisted grounds together from these ports).
So far my servo only does its initial powerup twitch but doesn't respond to any signals.
I used this online tone generator here to try some different profiles, frequencies, & volume to no effect. It seemed like the square wave at 1500hz would be a good starting point but so far nothing. Am I thinking about this whole process the wrong way? I also tried 50hz- I guess that's the value a servo expects to see, right? then Thanks for any help to clarify my understanding of PWM vs. Audio. Is there a generator profile specifically to 50hz servos? I haven't been able to find one.
Well, at first, the audio outputs are usually AC-coupled, so you just can't send PWM to those outputs alone because there is no DC offset to operate the motor.
At second, at least you need a proper current source to drive a motor; the headphone amplifier can't draw so much current and usually it's just limited by a series resistor to protect the amp.
At third, of course you can try to send a differential signal coded in L and R channels of the stereo input, but you will need to build a differential amplifier at the motor side and a buffer element such as a MOSFET transistor or something which can interrupt a DC from a sufficient voltage source to drive the DC motor.
Thanks for the reply! I think your first two comments are at least partly addressed by connection to the USB (for +5v) and the shared ground. I'm not sure but at least that was the intent on my end. The servo itself is quite small and seems to draw less than 100ma without a load.
When you refer to the "motor" you're still talking about the servo(-motor) right? Just so I'm clear. I thought the circuit inside the servo might be able to manage it. One of few relevant videos that I was able to find after posting was this one where a guy seems to do exactly what I was proposing, although he did use an external battery. His video isn't super clear or well documented (and its quite old) but if it's legit that's about what I had in mind and it sounds like I may just need to refine the audio output more.
It is far from sure that the audio amplifier will go sufficiently high or low to be seen as a logical high or low by the servo
Most likely your audio amplifier will not be able to send asymmetrical signals (with more high than low) as it has a series capacitor in the output (or in the input, or halfway).
So, if you put your audio to max volume, you might be able to set your servo in the middle.
Frankly, you are on a hiding to nothing here, for the reasons mentioned and others. The audio output of a PC or phone will be AC coupled and has zero mean voltage whereas a servo expects a signal between zero and (typically) 5V. Yes, a servo includes a driver to decode the pulse width and drive the motor accordingly, and you do need a +5v power supply capable of the motor start current. IIRC these R/C type servos expect to see a pulse that varies between 1 and 2ms length depending on where you want to drive the servo. In the R/C application these are sent every 20ms or so, as they "time division multiplex" signals for several servos together with a synchronising signal. So for one servo you'd need to generate a short 1 - 2ms variable width pulse every ~20ms, which is not the sort of waveshape that an audio output can readily handle.
If you really really want to control a servo from Android a better way would be to have an app feed numbers over a serial link to an Arduino then have the Arduino generate variable pulse widths to drive the servo. The serial link could be Bluetooth or USB OTG.
I got that part- initially I was just trying to elicit any response from the servo but I see why that didn't work now. Then I was trying to manually design PWM pulses, and then I was trying to get an app to do it for me- surprised there are very few. I did find a nice, working one called "gluemotor" that seems to do just about exactly what I want, so that's out of the way. Also note that the cable I'm talking about started life as a OTG to 3.5mm audio adapter, so it has its own DAC and tiny circuit built into the plug.
edit: sorry, (kinda) that this ended up not being an arduino question- I had assumed one would be required but delighted to have simplified. Now I have to go learn Android programming...sigh.
Congratulations!
No Arduino, but it does what you wanted!
Thanks for sharing your result.
Would be nice if you could elaborate a bit more on how you fixed this....
Sure, that app was the real MVP, and it was featured on hackaday (a version of it which requires an external battery pack). In my particular case, I used these cool little microservos that I've used on other projects. They are HK-5320 low voltage/low torque but great for stuff like this because they draw such low current. Often you can get away with power meant for logic and control- I used these also on a DJI Mini 2 as a drop release servo tied directly into the motherboard & front LED light. Works great! Anyway, so the other detail is the OTG adapter. At first I was a little bummed that my phone needed that instead of having the traditional 3.5mm jack, but it actually worked out because I just referenced the pinout of USB-C and so could tap into the power that wouldn't otherwise be available in an audio jack port. It's easy to cut back the rubber boot and access the PCB. Ignore the wire colors because they are nonsensical but the contacts are labeled. I found an easy-to-solder resistor to get my vcc near the base. The ground is not the audio ground but rather any of the 4 power ground pins on the outside of the USB-C array. Here's a photo.
There are lots of adapters but this is the example I used which is shown in the above link.
Volume all the way up of course. My phone example is a tiny PVG100 Flew it on a foam glider today- flies nice!
Thanks! Hope that helps!
Thanks- this is resolved though. I wanted a wired solution and also wanted to draw servo power from the phone, so this was the best for my project. All I have now is the phone, a servo, and this connecting wire. Very reliable!