yashsingh1/xdaforums huggingface dataset:
[Samsung Galaxy Nexus] Sea Shadow:
Easy simple TOSLINK for GNEX

Hello everyone,

First post here, I registered specifically to contribute to this topic.

First a HUGE thanks to everyone who contributed to this thread, I don't think I could ever press "thanks" enough. I recently got my own Nexus (i515 on VZW). At any rate I have a background in hardware hacking and as such I thought I would tackle the pogo pins. Much to my delight everyone here has done an amazing job of figuring it all out. At this point the only contribution I have to make is a quick dirty toslink adapter.

Ok so to keep things simple:

I wired up my own attiny85 with a 1.8v regulator and flashed the code by Matridom. I configured it for how I wanted (Car dock, AC charging, audio connected). After some testing to make sure that the phone was properly linking up with the attiny, I pulled out a 74HCT541N non-inverting line buffer.

I just hooked up VCC (5v), GND, and hardwired both enable lines to ground (to enable the chip). After that it was a simple matter of taking the raw data from the center pin and dumping it into the input of the chip. I hooked up a red LED and resistor to the output stage and ran the light stream into a standard home theater amp.

ET VOILA!

Audio :D

Edit: TLDR we can now build our own fully featured dock with digital and analog outs for ~$20-30

Edit x2: I will design a full board based on this notion. I will upload the design and parts list once I test it and make sure everything is working fine. It will include TOSLINK out (maybe SPDIF out), 3.5mm Analog out, rapid charge, and jumpers for: car/desk, AC/USB, and audio on/off. It will be a few weeks before I am done so please be patient.
[Samsung Galaxy Nexus] pchuk815:
THANK YOU! Now I have to convince my wife to get me that soldering iron I want for my birthday...
[Samsung Galaxy Nexus] subvertz:
Got my iron heating up......

too bad I'll have to wait for parts (they don't have a nice fry's or radio shack equivalent here in Norway.)
[Samsung Galaxy Nexus] zuberio:
Hi Sea Shadow, great job!

How do you plan to convert the digital audio from the middle pin into analog audio out for the 3.5mm jack?
[Samsung Galaxy Nexus] Sea Shadow:
Glad to be able to make a helpful contribution. I finally woke up after spending all night tinkering at the local hackerspace testing out that circuitry. It occurred to me this morning, that the implications of such an easy digital out are greater than I realized.

As we know, our phones use the Texas Instruments TWL6040 chip [blasted anti-spam measure - sorry can't link to the datasheet] for the codec. While this is a decent chip, it is still not a high end piece of hardware. Well with our SPDIF/TOSLINK connection, that issue is now moot. We can build our own digital output docks and run the audio right into a hifi DAC.

Anyways I digress, to answer your question Zuberio: The solution is a bit round about. I plan on designing an optional circuit that will take the SPDIF and will decode it into an I2S data stream (Similar to I2C but this is for audio). I will then take that data stream and run it into a basic DAC with line level output. After that its a simple filter stage and off to the 3.5mm jack.

The whole circuit will likely be released under some form of the Creative Commons license but I haven't decided which one yet.
[Samsung Galaxy Nexus] pdxbill:
You could take this up a notch, too and add some plug detect circuitry so the dock will properly inform the phone POGO_ID_AUDIO or POGO_ID_NO_AUDIO based on if the audio is plugged in our not.

Can't wait for the results :cool:

--Bill
[Samsung Galaxy Nexus] zuberio:
Actually - this could be done with the correct 3.5mm jack hardware. Just attach the jumper points that Sea Shadow already mentioned including for yes/no audio to the 3.5mm jack hardware pins that are N/C or N/O depending on if there's a plug inserted or not.
[Samsung Galaxy Nexus] Sea Shadow:
This is true, but this would also require you to redock the phone if you add/remove the audio. Granted this does bring up the idea, why not just permanently enable the audio... scratch that. The auto switching is going to be the best solution. That way your phone will use the built in speaker if there isn't audio plugged in.

Ok so I'll axe the pin headers for the audio and put in an auto-sense function. Also now that we are talking about this, is there any reason to charge at USB rates? I mean sure someone could have a power supply that only gives 500mA but should I just hard wire it for AC charge rates? Then again, a jumper is trivial and one of those "set it and forget it" things.
[Samsung Galaxy Nexus] Matridom:
I like to subscribe to the kiss philosophy. I don't think you need a switch for car vs desk mode, I don't think many people will take there car dock into the house and such. If it's a set it and forget it, leave it as setting in the code, it will make the spring easy. Now the audio Jack is intriguing, i think i could get it so that connecting the audio causes the signaling to renegotiate. All that would really be needed is a way to temporally ground out the 5vcc going to the phone.

Sent from my Galaxy Nexus
[Samsung Galaxy Nexus] pdxbill:
This is easy. Just look at the 2 data pins on the USB connector. If they are shorted together, you get 1A. If not, then 500mA.

--Bill
[Samsung Galaxy Nexus] soundwire:
The official Samsung car dock does it this way...the phone is in no audio mode until the 3.5mm headphone is plugged in. It looks like it also resets the controller so you don't have to un-dock then dock the phone. Its probably turning off the +5v to the phone...but that I haven't confirmed.
[Samsung Galaxy Nexus] zuberio:
I like charging at usb rates. I feel my battery lasts longer and cycles better with slow charges.
[Samsung Galaxy Nexus] Sea Shadow:
I personally would want to use SPDIF or TOSLINK in desktop mode for the desktop dock I am making; but at the same time if I were to use another circuit for my car, I would definitely want it in car mode and likely analog audio output. Also, it seems that some people want to force their phone to charge at a certain rate. Rather than force people to get different types of chargers or manually short the data pins, I'll just make it jumper definable. Not all high current chargers have their D+ and D- pins shorted together and besides a jumper uses one less data pin on the micro-controller. I want to make the circuit as safe as possible for the devices that will be plugged into it and this includes accounting for all manner of charger.

After thinking about it, I think I will go with auto sense audio, but the charge rate and dock mode is going to be jumper configurable. The entire circuit will also be through hole. Well maybe not the micro usb socket, but I'll certainly try to find one that is.

Sure,

we

can just reprogram our individual chips to make the dock do what we want. However, I want to design a circuit that is as user friendly as possible. I would venture to say most people on here don't have access to an ICSP, and aren't super familiar with Arduino, let alone AVR studio. If I wanted to just build to my tastes, the entire thing would use tiny SMD tech and would have a switchmode power supply built into the circuit, but this will be for the masses so I will keep it simple.
[Samsung Galaxy Nexus] pdxbill:
For safety, the auto select would be the best option, as pulling 1A out of a 500mA charger would make it nice and toasty warm.

There could be a "best of both worlds" with a 3-pin jumper:

Pin 1 - 5V

Pin 2 - Micro GPIO

Pin 3 - USB D-

Also, drive 5V to USB D+. Then you can have:

No jumper: 500mA charge

Pins 1-2 jumped: 1A charge

Pins 2-3 jumped: Auto select
[Samsung Galaxy Nexus] Sea Shadow:
As far as I'm aware the attiny can only do tri-state output(ish) not input; so while the idea is good, it won't work as suggested. Also it is worth mentioning that the attiny is running at 1.8v to simplify the interface with the phone, as such we can't use 5v logic with the chip; since each IO has 2 internal diodes (ground to pin, and pin to VCC). Granted that doesn't stop us from running jumpers from the vReg to the pins.

The only workable auto select I can think of would eat up more pins than we have for the attiny. We would need to establish a self challenge where the system sends out data on one pin and checks for the return of the data on another pin. Then we would need to use another 2 pins for forcing the phone into 500mA/auto and 1A/auto.

While we really have 6 IO pins, for practicality reasons I would prefer to not make life any more difficult for the few of us who do want to reflash them. Thus we are limited to 5: 2 are already tied up to the phone communications, 1 for Car/Desktop dock, 1 for the audio auto sense circuit, and 1 left over for charge select.

While less common, I have come across more than a couple of chargers that tied one or both of the data pins high or low. If one of those chargers was hooked up to our circuit and we weren't careful, we could have a shoot through, and that is also a real quick way to ruin someone's day.

Not that the idea is bad, we just need to keep on hacking at the problem. I mean if we have to we could jump up to the attiny84 for the extra IO.

Possible solutions

-Switch to a uController with more pins.

-Use lots of resistor networks and use an analog input pin to keep track of several jumpers with one pin. (it's quite the fancy trick to pull off and would be more work then I am willing to do)

-Along with the 2nd suggestion, rewrite the code to only use 1 pin for the phone communications.

-Or KISS and leave it with jumpers
[Samsung Galaxy Nexus] Matridom:
Perhaps it is my lack of knowledge in the programming language, but i was under the impression that a pin could not be changed from input to output during the running of the code. When I did try to get it on one pin, it would not work properly. hence the reason I kept it on two pins. I will however defer to the experts on this point.
[Samsung Galaxy Nexus] zuberio:
Leave it with jumpers or DIP switches is my vote.

Any news on the design?
[Samsung Galaxy Nexus] Sea Shadow:
Hello, sorry for the delay. Life for someone working in QA can get pretty hectic (I'm sure many here can relate).

I'm still working on circuit revisions. Currently I have designed it for jumpers and am trying to simplify the parts count. Since I have the line buffer chip I have a hunch that I can revise the circuit to run on 5v, that would remove the need for a voltage regulator for the uController. I'm still picking out parts for the analog out. Also trying to find a good source for toslink transmitters. I have found a few, just narrowing down the sources.

I want to make it as easy as possible to assemble, which makes it much more difficult to design. I'm use to designing around my abilities; surface mount everything with traces practically on top of each other. However, this circuit should be able to be built by anyone who can use a soldering iron decently.
[Samsung Galaxy Nexus] jonnyg1097:
I am no expert with what is going on in this thread but I was wondering, if you were to be making your own DIY dock, could you (in theory) when doing the audio out instead of doing the audio for headphones wire it for actual speakers that would be in the docking station?
[Samsung Galaxy Nexus] Mach3.2:
You could wire the speakers directly to the PCB.
[Samsung Galaxy Nexus] Sea Shadow:
Yes you can do this, but its not as simple as just running the lines from the analog out to a set of speakers. The docks are typically designed to put out a line level out signal. This is a fixed level and not specifically amplified (at least not much). You would need to expand the circuit and add in a dedicated amplification circuit to boost the signal enough to power some speakers. Since you brought this up, I'll toss in a set of pin headers that will break out the analog signal for anyone who may want to do this (I may end up designing a board for that too when I get around to making my own desktop dock using this circuit).

EDIT: Oh and I forgot to mention, I was able to get rid of the voltage regulator by using the line driver to play with the signal coming from the phone. So now this whole project will run straight off of 5v (charger), and is relatively safe for setting up an auto sensing circuit. I will not incorporate that into this first release of the circuit, but I will try to add it in later. A simple voltage divider cuts the signal down for the phone while the line driver boost the signal coming from the phone.
[Samsung Galaxy Nexus] jonnyg1097:
Awesome. Now I can consider building my own dock.
[Samsung Galaxy Nexus] Sea Shadow:
Another quick update:

I whipped up a small PCB (1"x2") for testing out the revised code. Everything works as intended and there are 3 jumpers used to configure the dock mode, charge mode, and audio mode. The circuit uses pull up resistors to default to car mode, USB charge rate, and audio output disabled. Jumpers shunting each pair of pins gives you, desktop mode, AC charging, and audio output enabled (when audio output is enabled the phone's speaker is disabled and audio is piped through the dock).

Currently the only audio output is a pin header for driving a TOSLINK transmitter (or a red LED jammed into the receiver). I'm still working on the SPDIF/toslink decoder but the dock control circuitry is complete. Will have to order the parts for the analog audio output later this week.

I'm not making any promises but hopefully I'll have the audio side done sometime next week.
[Samsung Galaxy Nexus] imaweasal:
I don't know how high of an audio quality you're doing for, but I know a friend who got a toslink to rca converter box online for his home stereo system for like $20 on amazon. I know that something like that would be high enough quality for me in the car.
[Samsung Galaxy Nexus] Sea Shadow:
Delayed due to emergency

Hello,

As some of you are aware there are many wildfires burning across the western US. One occurred near my parent's home and I spent this past week helping evacuate friends and neighbors. Their home was on the border of the evacuation area and luckily they were able to stay in their house, but many of our friends were evacuated and we moved lots of belongings out of harms way.

The fire has since burned away from the town they live in, and we are fortunate in that no homes were lost (some damaged). However there is lots of cleanup to be done and lots of stuff to be moved about.

As such, this project will be put on hold for a week or two so I can assist in cleanup efforts and help people get their valuables back into their homes.

Sorry for the delays,

Sea Shadow
[Samsung Galaxy Nexus] imaweasal:
Not a problem at all SS. My car dock and associated hardware isn't coming for a few weeks, so this project is on the back burner for me. Good luck out there.
[Samsung Galaxy Nexus] zuberio:
Best of luck, take whatever time you need.

This thread has gotten me interested in Arduino and ATTiny85 programming so I ordered some stuff off DigiKey and am patiently waiting for 'tinker time' :)
[Samsung Galaxy Nexus] CNLiberal:
I have read the entire thread (a week ago), and did a search, but didn't find this question asked. If someone did, my "search-fu" is highly lacking. What are the prospects of putting the phone into Car Dock mode and USB OTG? I would like to have the phone in my car be my new "head unit" and then connect the audio out to an amp and then the OTG cable to a USB powered hub. The hub would have an SSD for music. Would this be at all possible? Has anyone tried that with the docks built in this thread? Thanks!
[Samsung Galaxy Nexus] pdxbill:
The docks on this thread are talking about using the 3 "pogo-pins" on the side the GN, not the USB port. The pogo-pins on this device do not support USB.

Now, the Nexus 7 tablet may be different. It has 4 pogo pins, which is what you would need to support USB, and Jelly Bean now supports USB Audio...

--Bill
[Samsung Galaxy Nexus] CNLiberal:
I meant plugging in both the USB OTG (using the usb port) and docking in a car dock simultaneously (using the pogo pins).
[Samsung Galaxy Nexus] zuberio:
Interesting ... I'll test when I get home tonight if I can charge over the pogo pins while doing OTG Host via the USB.
[Samsung Galaxy Nexus] zuberio:
Tested and failed - can't do OTG while charging via the pogo pins.

Tested on GNex running AOKP M5 + Franco Kernel

Only +5V and GND pins were connected, no intelligence on the middle pogo.
[Samsung Galaxy Nexus] mikedyk43:
Just a thought. You're not in "fast charge" mode when you tested were you?
[Samsung Galaxy Nexus] CNLiberal:
Well, it was worth a try. I kinda figured it wouldn't work as the pogo pins and USB +5v/GND pins are both connected to the same USB switch (FSA9480) internally. Was just hoping for a miracle. It looks like my only hope will be the Samsung Galaxy Tab for an in-car head unit replacement. Right now, it appears to be the only tablet that can fast charge and provide USB OTG simultaneously. Thanks for your assistance!
[Samsung Galaxy Nexus] subvertz:
I have tried it before in fast charge and USB mode. Connecting the OTG did nothing if it was already pogo charging, and if you connected OTG first, it would not pogo charge. I haven't tried with jellybean, but its a hardware thing. Will give it a shot on the drive home from work, just in case.
[Samsung Galaxy Nexus] zuberio:
Hi Matridom,

I finally got off my lazy butt and tried modifying your code to use high/low inputs on pins 1, 2, & 3 of the ATTINY85V-10PU to allow for external (physical switch) setting of the 3 possible phone modes. Could you take a look and tell me what you think?
[Samsung Galaxy Nexus] Matridom:
Looks good, i only have 2 small suggestions:

1. The section that checks the high/low status of the pin assignments is in the setup section( 3 if statements), this means that it will only run once, when the circuit is powered up. If the options are changed, redocking the phone won't be enough, you will have to power cycle the whole circuit. Put your code into a function and plug it in this if statement:

if(pulseLength > initializationTime){ //if the pulse is long enough to trigger the signalling routine

pulseLength = 0; //clear out the pulse length so that it does not trigger again
signalling = true; //flag the signalling routine
settingMode = 1;

}

2. You are assigning the "Reset" pin to an input, my understanding on the process is that if you do this, you can no longer re-write the chip (I could be very wrong on this)

I think if you really want to go to this type of setup, it might be a smart idea to go to a 16 pin chip (attiny44/84). Have an additional subroutine that checks the status of the 3 configuration pins, if it changes, sends a signal to a new pin that would activate a relay that would cause an interruption of the 5vcc going to the phone. This would cause the phone to re-signal the chip and update it's options.
[Samsung Galaxy Nexus] zuberio:
Excellent suggestions, both of them!

I've moved the 3 if-else statements to the location you indicated (way better location that allows a check every time the phone is docked instead of having to power cycle the circuit after a setting change). I didn't put them in their own function though ... copy/paste is easier.

Instead of going to a 16 pin layout, I opted to reassign the ledPin to the audioPin and leave the reset pin alone. From reading the data sheet, pin 1 can be used as a 'weak' pin ... which means it only resets on a pulse longer that a certain length. Thanks for pointing this out because my previous setup would have constantly been resetting the chip!

Updated sketch attached.

[EDIT] Please also take a look at your revised schematic that now includes mode setting switches. Am I doing this right?
[Samsung Galaxy Nexus] Matridom:
I can't seem to find any errors in the code, looks like you just need to test it out in actual hardware.

Suggestion, in your hardware diagram, install an interrupt button in the 5vcc going to the phone, then you just hit a button to cut power to the phone and cause it to re-establish the changed options on the dock. The normal state for this switch would be "on".

edit: your switches look wrong, see here for a working simple example:

http://arduino.cc/en/Tutorial/DigitalReadSerial
[Samsung Galaxy Nexus] subvertz:
I'm pumped about how this is going!
[Samsung Galaxy Nexus] zuberio:
So the ATTINY85 requires pull-down resistors instead of pull-up? Based on this instructable I'm supposed to use pull-up resistors .... or somehow manage to activate the built-in pull-up resistors inside the chip.

Either way I'll test it out on a bread-board and adjust accordingly (with progress posts :) ).

I like your suggestion about the +5V interrupt. I've actually already got a 3 switch DIP in-line with the pogo pins on my dock to allow me to use the dock as a glorified phone holder when not charging. That should do the interrupt trick.
[Samsung Galaxy Nexus] CNLiberal:
Alright, I want to build this dock. However, I don't want to purchase an Arduino kit. If I bought the appropriate chip, could one of you program it for me (I'd pay shipping both ways)? Also, I want to pair the SPDIF out to this device. I want to use the TOSlink fiber out. The reason being, this is going in my Tahoe (to an Alpine CDA-9855 with RCA input). I am trying to avoid ground loops and alternator noise. Using fiber should accomplish that. I thought I read that someone was trying to figure out a way to get an LED to power the fiber TOSlink connector (and that was all that was left for digital audio out). Did anything come of that? Other than that, is this circuit done? Thanks for all your efforts!
[Samsung Galaxy Nexus] zuberio:
Actually, I bought enough parts and stuff to make 4 copies of my circuit. Once it's tested and working/built I'm planning on trying to sell 3 to offset the cost of the one I'm keeping. They'll just be DIY drop-in boards with 3 connectors for pogo pins, 2 connectors for +5V & GND, and 1 connector for the middle pogo pin should you want to use the SPDIF out.

For your purposes, you want to take the SPDIF out and run it through a non-inverting buffer (think amplifier) and use the output of that to run a red LED for your TOSlink. Sea Shadow was the one to test this and figure it out.
[Samsung Galaxy Nexus] CNLiberal:
How much were you thinking of charging for the board?

I have no idea how to build the non-inverting buffer. Is this what Sea Shadow was talking abouit?

Would you be willing to include that chip and the TOSlink adapter as well? I hate to ask this of you, but my hardware soldering skills pretty much maxed out at adding a resistor to a microUSB male adapter to get Car Mode enabled on my I777. Thanks for your consideration!
[Samsung Galaxy Nexus] zuberio:
No more than $20 for the board ... I haven't really decided yet.

Yes, that's what Sea Shadow used. It would probably be a nice exercise to throw in the buffer + led; if only to test the audio over my computers SPDIF in ... because that's the only place I have it. If my local electronics store has a non-inverting buffer + TOSlink adapter I'll throw it in.

I don't know how soon I'll be able to get on this though .... It could be 2 to 3 weeks before it's tested and built.
[Samsung Galaxy Nexus] CNLiberal:
I haven't really seen a complete, all in one post on the components used to build this. My biggest question was, how are you connecting all these components together? A breadboard? Special PCB? Maybe if it wasn't too difficult, I could put it together myself, but I haven't seen dedicated parts list yet. It seems there were several posts with different parts used. What did you use?

I'd gladly pay the $20 for this! I just purchased that Fiio D3 SPDIF->Analog adapter. I'll have my local car audio shop hack it into my truck too (along with another component I need added).
[Samsung Galaxy Nexus] zuberio:
Once I've tested it on a breadboard, I'll post a parts list + whatever else you need. Then you can decided if you want to DIY or buy :)