Microcontroller (AVR) programming from smartphone

Hi Friends!

Briefly: considering ways of uploading code to microcontroller (particularly some Atmel's AtMega - same as used for Arduino) from the smartphone.

In details:

Programming MCUs (e.g. uploading firmware into their ROM) usually happens via some proprietary interface (using SPI in case of AVR), or UART, or JTAG. This generally involves dedicated software on the side of computer and some hardware (USB to UART or dedicated "serial programmer").

Suppose we want to be able to write simple code using mobile phone - situation I met with my class of 15+ students with no dedicated lab having 15+ computers.

I tried creating a small system containing two parts: First - html web-page with a textarea to write assembly code, built-in AVRA assembly compiler (just compiled to javascript) - and some JS code which can "beep" the bits of the hex-file containing firmware (via audio). Second - bootloader for target MCU which uses ADC pin to "listen" to those beeps via direct wire connected to 3.5 mm audio jack plugged into smartphone - and "burn" incoming data into flash memory.

This works (if you are curious to try, it could be found in my github page by same username) - however there is a sudden issue: almost half of students use mobile phones without 3.5mm jack - as nowadays it is the era of wireless headphones already, I missed the fact!

So now I'm looking for further, alternative approaches. For example:

- attaching microphone to ADC pin instead of wired connector; code should be beeped out via built-in speaker of the smartphone (it would be a bit noisy class, of course) - I actually tried, but was not yet able to come up with signal recognition algorithm of good enough quality.

- blinking data with display and catching it with photo-transistor attached to ADC or digital pin, haven't tried for it seems like bitrate would be very low (even though we generally need to upload firmware of few dozens bytes).

Thus I'm open to any ideas / hints / articles on improving either of these two approaches - or perhaps something completely different which I may have missed.

Reply to
RodionGork
Loading thread data ...

If your smartphone has USB, just plug a AVR programmer in.

FX "arvdude", (which is FOSS)

do they still make smartphones with 3.5mm jacks?

Have you considered using USB? (hmm maybe not, do iphones have USB a USB host on their Lightning connector? only 4 pins... maybe not, but phones with USB-C or (or micro etc) should ba able to connect to a USBASP or similar by using the right plug adaptor.

Or bluetooth perhaps, prototyping modules with BTLE enabled processors on them are only a few bucks - write some code, add a connector and a power supply.

Reply to
Jasen Betts

<snip>

Maybe play a suitable (uncompressed?) video with bits encoded as frames? Don't ask me how, just a thought.

Reply to
Clive Arthur

MJPEG?

Reply to
Clive Arthur

Keep your audio interface but plug it into a Bluetooth audio receiver (or cannibilze an old Bluetooth headphone and connect your audio interface to where the earpiece was). Then students can connect audio via Bluetooth.

Reply to
piglet

With, for example, an MJPEG file playing, you could have say a grid of

3x4 or more squares, each with a different file encoded. Select your file simply by placing your phototransistor in the appropriate square.

Also, using an RGB phototransistor (if there is such a thing, if not three phototransistors with filters) could triple the data rate.

Reply to
Clive Arthur

How about canibalising a cheap bluetooth earbud or pairing the phone by Bluetooth for audio with some other cheap and nasty peripheral. Plenty of not quite supported any more "smart" speakers knocking around.

Reply to
Martin Brown

Beings Bluetooth uses a packet-based protocol you need an MCU to receive packets, no?

It's easy to use a HC-05 Bluetooth Module:

formatting link

It's harder to DIY:

formatting link

Danke,

Reply to
Don

Hi Friends! First of all thanks for all those replies. These are my first steps in usenet and I hardly expected such quick and multiple-sided discussion. Seems like some suggestions complement each other so I'll answer in the order of encountering them in replies.

Thanks for your kind words. Actually it already can be used but probably I need to add more documentation/video, particularly about hardware setup. "Coding / beeping" page is here (you may click "compile" and then "burn" just for fun):

formatting link
Setup may look as easy as here:

formatting link

Yep (some of them already took it home and did some coding in "unsupervised" mode), moreover it would be fine to have interface which is easily and cheaply reproducible.

OTC "module"?

I'm not sure what is OTC module. AVR microcontrollers were picked as those with probably simplest assembly language, particularly these are bare ATMega8L chips in DIP-28. Initially kids plugged them into breadboard, added battery, couple buttons and LED - and audio-connector of course - and voila (see image linked above). That was not very stable so we invested 2-3 lessons in building hand-made PCBs.

Thanks, I glanced over but need to dive more into details. It also reminded me of approach used with ZX spectrum, need to check how exactly it worked...

Well, this would be an improvement though more wiring is needed and audio port with mic input. Shall search for more info how 4-contact jack is implemented on various smartphones... Though if uploading could be made more stable even with one-way link, I'll stick to it for simplicity...

Surprising idea! never came to my mind, though I think there is no API to directly control SD card pins and with 8-bit MCU bootloader it is probably not possible to accomodate for complicated code handling SD card IO... And yep, these are perhaps more rare than audio jacks

Unless I'm mistaken it works only with phones which have USB "on the go" variety, e.g. can work as USB-host?

We actually did use this previously (HC-05 or something alike), just with somewhat different firmware (also created by me) allowing an interactive BASIC on Arduino or STM32. Here is a lousy video:

formatting link
However setting 15+ cheap bluetooth devices with shaky power supply - they were not working fine and it was sometimes painful experience. I admit I haven't thought of them for uploading though it will make straightorward flow. Perhaps shall switch to it if "audio" channel couldn't be improved after all, thanks :)

Here I'm a bit out of sync with technology - does all modern smartphones include NFC? And I think receiver needs a chip like 531 or 522 and some stuff around so it feels bit too complicated for school level...

Very curious idea I completely missed, also not sure about throughput but need to go and check first. Also it suggests using camera itself as a feedback... very interesting!

Ha-ha! that is also something I completely missed. I can easily program "running barcode" in an HTML page with javascript/canvas... Not sure if it will work better than blinking display, but it looks much more comprehensive to user... and seems more versatile (even up to printing barcode on a paper) - will think more about this, thanks!

Don't ask me how, just a thought.

That may be working, right. Not necessarily video, it is possible to programmatically blink an area of screen etc...

Interesting, never thought of this approach - shall investigate it further, thanks.

hardware in the student lab that loads the target machines

funny, but you described exactly approach we used year ago - they uploaded code to my server, then rushed to the single laptop at the center which had USB programmer attached - and here entered pin-code by which small script fetched the compiled HEX-file from the server and uploaded it. It was just not very convenient when there are many people and few (or single) computer. But it was the most stable setup probably, that's true.

I agree. But coding without anything is even worse. These are "facultative" classes of electronics happening once per week and we can't pretend on supplying ourselves with suitable auditorium with desktop computers or fetching dozen-or-two spare laptops :)

Reply to
RodionGork

...

There are converters from USB/Lighting to 3.5mm audio jack available for both iPhone and Android phones. That will allow you to use your existing solution.

For example:

formatting link
formatting link
kw

Reply to
KevinJ93
<snip>

The batteries shown in your video look like two 1.5 VDC used in the USA. If so they provide, at best, 3 VDC. You may need more oomph.

I power my Blue Pills and Black Pills with USB 5 VDC and let the built in LDO regulator drop it down to 3.3 VDC.

Danke,

Reply to
Don

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.