Page 1 of 1

Arduino Nano Self Programmer.

Posted: Sun Aug 22, 2021 9:52 pm
by mnfisher
Uploaded a short video - the Programmer's Apprentice.

https://youtu.be/DRXwuKgs0p8 (should appear at approx 10:30pm at current upload speed - now live - rather less delays than the latest Bond!)

In it an Arduino Nano actually writes a program and reprograms itself (to a 1s blinkie)

I went a bit overboard on the titles - and due to some broadband issues the body of the video isn't quite as 'polished' - Nano's Adventure #2?

So it's either:
An allegory on the dangers of self-modifying code.
A reflection on how easy Flowcode is to use (a Nano can do it!)
A four minute precis of 'Machines Like Me' - computer gains awareness. Doesn't like it - reprograms itself.

The Nano 'genuinely' writes the program - plugging it into USB port 'opens' Flowcode - starts a new project and adds the relevant icons (and text) - it could be useful for demo situations...

Martin

Re: Arduino Nano Self Programmer.

Posted: Sun Aug 22, 2021 10:34 pm
by chipfryer27
Very cool

James Cameron should be worried by your skill even though he predicted "self awareness" :)

Regards

Re: Arduino Nano Self Programmer.

Posted: Sun Aug 22, 2021 10:47 pm
by mnfisher
Thanks -

I think he sleeps like a baby (still)...

My first go with canva - which is very cool but needs a good broadband connection :-(

Martin

Re: Arduino Nano Self Programmer.

Posted: Mon Aug 23, 2021 9:49 pm
by S_VE
Hello Martin,
Quite a Creative idea. really nice one .

Could you please share the flowcode


-SV

Re: Arduino Nano Self Programmer.

Posted: Tue Aug 24, 2021 8:59 am
by mnfisher
Surely - though it's very simple.
The nano just writes command strings to uart and waits for the pc to respond before sending the next..
A command has the form
Xstring, string, string....

Where X is a command (for example S (start flowcode) or C - add a calculation block (first string is comment and then others are the 'body'))

Some python receives the strings and passes them to flowcode. It also 'pauses' before requesting the next command - I didn't get all the timing right - there is too long after compilation for example.
I added keyboard shortcuts to fc to allow keys to add macros for example alt-c adds a calculation block..

Like a magic trick - knowing how it's done reduces the illusion..

Will post the code this evening...

Martin.

Re: Arduino Nano Self Programmer.

Posted: Tue Aug 24, 2021 9:44 pm
by mnfisher
In the movies...

The source -
sorcerer.zip
(1.28 KiB) Downloaded 164 times
Note - I used Python 3 (I recommend getting Anaconda - which includes a lot of libraries - but I had to add pywinauto (use pip install pywinauto))
Using v3 meant some issues with strings (byte from serial and unicode) I use decode to convert...
It just 'fires' keystrokes and mouse clicks to FC (mouseclicks are based on a 1920 x 1080 screen) - and waits a while...
It can be made faster by reducing the delay in send_keys (I wanted a 'typing' effect - but it turned out a bit small to see :-( ) I'd wanted to have a 'zoom' on the part of the screen - but didn't manage it. Also a lot of the time.sleep commands could be 'reduced' - this may be dependent on the speed of your PC.
I only automated the commands I needed.
Nano was on COM9 - this is hardcoded - I'd make it a command line parameter if I were to play more. When the Nano chooses the programming port - the cursor is just moved down one line (it doesn't read what's there - and it would have been better to send 'COM9' as keypresses (which does work) - the port I wanted 'moved from the bottom of the list originally to the top when I filmed it..
The location of the flowcode executable is also hardcoded.
In the 'Key' commands %Key -> Alt+Key pressed and ~ -> return.
auto_nano.fcfx
(12.13 KiB) Downloaded 170 times
The command strings are set in the array definition (main.cmds) - this is new to v9. I'd probably incorporate a text file if I wanted to send more text...

As mentioned above - it's necessary to 'add' keyboard shortcuts to FC for adding the macros (Customize Quick Access Toolbar -> More commands -> Keyboard shortcuts (customize)

Have fun - and any questions welcome..

Martin

Re: Arduino Nano Self Programmer.

Posted: Wed Aug 25, 2021 5:20 pm
by BenR
Excellent what a brilliant project!!! :o :)

Many thanks for sharing Martin that looks very powerful and could be put to all kinds of uses. :) ;)

I keep wanting to create a set of fuzzy logic components similar to the DSP components and then we could start playing with things like neural networks and getting the MCUs to really start thinking, it's on the list and hopefully I'll get around to it soon :D