We’ve seen audio ports being used to establish a communications channel between a computer and a microcontroller before, but nothing quite as slick as this. [Gordon] is using a webpage running on a tablet to send Javascript to a microcontroller where the entire program is interpreted.
[Gordon] is using the Espruino Pico, a board that’s on Kickstarter right now. This tiny board is built around a javascript interpreter, allowing code to be written and updated on the fly without mucking around with bootloaders.
This technique can be expanded to provide bidriectional communication between a microcontroller and a computer. On the project Github, [Gordon] used the microphone pin on a TRRS jack to sent data to a computer. It needs two more resistors, but other than that, it’s as simple as the one-way communications setup.
[Gordon] put together a few demos of the program, including one that will change the color of some RGB LEDs in response to input on a webpage.
Nothing as slick as this? This is old as fuck
there’s no hack like an old hack
This is similar to what 80’s microcomputers did with cassette tape. Except they used frequency shift keying instead of plain 0 and 1.
Yep, and you can also use your phone and/or table to load them up. http://asciiexpress.net has a cache of code converted to audio for the Apple II.
I’ve done something similar, except in my case, I used one audio channel as a clock, and the other for data. A webpage loaded 255 pre-rendered samples. Javascript on the page would send the samples out as audio which was interpreted by a µC as generic synchronous serial protocol. To achieve bidirectionality, the µC was connected to the same computer via USB and enumerated as a HID / keyboard device. The we page / javascript was able to transmit commands to the device via audio,and the device could respond by sending keystrokes to the we page.
…and by “we”, i mean “web”…
Using one channel as clock, and one as data, you can even use the soundcard to flash AVR microcontrollers:
V1:
http://www.elektronik-labor.de/AVR/Soundprog.html (german)
https://translate.google.com/translate?sl=de&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.elektronik-labor.de%2FAVR%2FSoundprog.html&edit-text= (english translation)
V3:
http://www.elektronik-labor.de/AVR/Soundprog6.html (german)
https://translate.google.com/translate?hl=en&sl=de&tl=en&u=http%3A%2F%2Fwww.elektronik-labor.de%2FAVR%2FSoundprog6.html (english translation)
Ahh yes, I remember Hackaday featuring a project similar to this. It’s called Audioino, and it’s a bootloader that does the same thing.
What’s the next big hack? use a mic input as a low frequency oscilloscope?
The question is how well the typical tablet is protected against short circuit/overvoltage on its earphone output when something is wired wrong.
I did this a couple of years ago to make Android powered universal remote. The whole circuit consisted of one comparator translating whatever voltage my phone was outputting to TTL, which in turn was read via AVR blinking the IR led as requested.
At 44100 samples/second I got a bit faster speeds than 9600, but I don’t remember how high I managed to get.
Unless something changed since Android 2.3 bidirectional audio isn’t possible since the task of reading the input audio stream fast enough to read the serial data would block all other tasks on the device.
That can’t be right… I’ve successfully run bidirectional DroidParty patches on a 2.3 device…
BTW you can output analog values too with decent precision by using a cheap frequency to voltage converter such as the LM331.
Did not know about the LM331’s existence. Thanks for pointing it out, but apparently it’s a voltage to frequency converter?
It can be rewired to work both as a V to F and F to V converter. Both examples are on the TI datasheet. http://www.ti.com/cn/lit/gpn/lm331
Plenty of cheap ones on Ebay, not sure if they’re legit, clones or fakes though.
And here’s what it sounds like:
http://jsfiddle.net/L0ryLark/
^^^ To anyone else… turn your volume down first :)
You can also use the full terminal webpage, which will transmit a blip for each keypress: https://espruino.github.io/EspruinoOrion/
cool – I hadn’t seen that before. Surely someone has made a javascript based chip tune demo.
It doesn’t seem to work on my iPhone, but it works just fine on Macbook. Anything I need to tweak from the code?
Are you using an up to date iOS? I think Apple were a bit late to the party with the Web Audio API. You might have more luck with one-way communications as well – there’s now a better write-up at http://www.espruino.com/Headphone – hope that helps!
Yes, I am with iOS 9.3.3. It does not work for all iPhone 5C, 5S, and 6S that I have here. Am I missing something else?
When the headphone cable is unplugged (and turn the volume down quite a bit so it doesn’t mess with the speakers), can you hear sounds coming out when you press a button? If not, you’d have to find a way to debug the webpage on the iPhone and see if it’s producing any errors? It might be better to ask on http://forum.espruino.com as this thread is getting quite long! (You might also need to invert the output polarity which you can do by setting a variable on your webpage – it might be Apple produce a negative output for a 1 or vice-versa)
Sounds like a very handy hack.
The connector in the drawing shows three connections: left, right, sleeve(common)
A non-mobile simple tablet wouldn’t have a mic contact lead in earphone connector, right?
I can understand the tablet sends sound and that sound is converted to 1 and 0 by the R-C
but how is any data flowing back from espruino to the tablet?
Does the tablet “listen” to its audio-out ?
Thanks for anyone knowledgable enough.
2 of the 3 examples just transmit – in which case you need one resistor, one capacitor, and a standard 3 pole headphone jack.
The full bidirectional terminal uses the Mic input with a 4 pole connector (circuit diagram on the forum post). I think a surprising amount of tablets do have a mic input on it – you might want to use it for Skype/etc.
Thanks for the quick explanation, will check mic on tablets, good luck with your kickstarter stretch goals, more everyday examples would help these goals. Also thanks for doubling the espruino RAM for free !
Cool. I almost didn’t read the article. I really didn’t get what was special about this from the summary. There isn’t any software at the microcontroller demodulating FSK like in most of the audio-serial setups I’ve seen. It’s all in that little RC circuit, he’s getting actual 1 and 0 voltages out of that.
Cool!
Cool but let’s keep it a secret, because ftdi will not like that.
For entry level or low-budget users, it could mean less ftdi chips in arduino and the like.
BTW is there any known solution for arduinos that lack usb-serial?
and work with avr dude/avr studio ?
I suppose my last question was answered by cyk above.
Time to experiment !
It looks cool, but this business of waiting 1 second for a capacitor to charge up is off putting. Is this just at startup?
Second, from my understanding the mic input on a PC or smartphone is AC coupled.
How reliably could you send continuous sequences of 0xFF 0xFF… characters or any sequences with a DC component?
OK in serial_to_audio.js you wait 1 second for the cap to charge, send your data, then wait another second? So if you are sending 1 byte it will take 2 seconds before you can send the next one.
How much data can you send in 1 packet? Numbers please.
Get rid of all of the circuitry above, throw in an opamp configured as a comparator and run above 9600 all day?
On Android you can (or at least used be able to, I haven’t touched it since 2.3) access raw PCM stream going straight to the audio DAC. Your packet length is only limited by how large buffer you can allocate and pass along and your baudrate is only limited by how many samples/bit you want to allocate. Theoretically running serial link at 44100 bps should be possible, worst case scenario half of that if you need to satisfy DC decoupling with Manchester code.
I should have better defined “packet”. I take packet to mean the number of signalling bits sandwiched between the first 1s delay and the 2nd 1s delay.
I don’t think my question matters, because the espruino developer will avoid questions calling him out on his 9600 baud cliam.
I seriously don’t get where they got that 1s delay from. My old HTC Wildfire started transmitting right away
I think this is pretty well answered on the forum, but if you want your audio used all the time, there’s no need for the 1s delay. You just wait 1s for the capacitor to charge, send all the data you want at 9600 baud and then wait another 1s for a smooth discharge. You could start transmitting right away, but you might end up with a few garbled bytes.
back in the day telecomms got around digital line conditions of 0xff by encoding with hdb3 or b6zs , substitution after a certain count of 1’s. A trivial conversion (for todays systems).
How do you get a UART out of that? He says in the article that there’s a USART in the microcontroller… that’s the only connection I could make.
The audio output is creating a signal that is interpreted by the Microcontroller’s UART. There’s no special software on the microcontroller – it believes that it is communicating with a totally standard UART – the JavaScript on your PC is effectively emulating one.
There is even simpler solution! check out “ArduCom” app for iPhone . its amazing…