Arduino Nano Self Programmer.

Use this section to discuss your embedded Flowcode projects.
Post Reply
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Arduino Nano Self Programmer.

Post 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

chipfryer27
Valued Contributor
Posts: 1110
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 278 times
Been thanked: 397 times

Re: Arduino Nano Self Programmer.

Post by chipfryer27 »

Very cool

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

Regards

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Arduino Nano Self Programmer.

Post 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

S_VE
Posts: 9
Joined: Tue Jan 26, 2021 6:10 am
Has thanked: 17 times
Been thanked: 1 time

Re: Arduino Nano Self Programmer.

Post by S_VE »

Hello Martin,
Quite a Creative idea. really nice one .

Could you please share the flowcode


-SV
S_V

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Arduino Nano Self Programmer.

Post 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.

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Arduino Nano Self Programmer.

Post by mnfisher »

In the movies...

The source -
sorcerer.zip
(1.28 KiB) Downloaded 154 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 160 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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Arduino Nano Self Programmer.

Post 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

Post Reply