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
Arduino Nano Self Programmer.
-
- Valued Contributor
- Posts: 1453
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
-
- Valued Contributor
- Posts: 1528
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 353 times
- Been thanked: 549 times
Re: Arduino Nano Self Programmer.
Very cool
James Cameron should be worried by your skill even though he predicted "self awareness"
Regards
James Cameron should be worried by your skill even though he predicted "self awareness"

Regards
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Arduino Nano Self Programmer.
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.
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.
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Arduino Nano Self Programmer.
In the movies...
The source -
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.
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
The source -
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 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.
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
-
- Matrix Staff
- Posts: 1924
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 684 times
Re: Arduino Nano Self Programmer.
Excellent what a brilliant project!!!
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


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

Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel