
One day, a ridiculous idea popped into my head to combine I spent a lot of time on it, and the result was spectacular and useless, but I enjoyed it. Six months ago, another wild idea came to me. This time, it wasn't impressive at all, but much more useful. I also spent a lot of time on it. In this article, I present the beta version of my second crazy idea.
I named the project Nanonyam and even came up with a logo (took me a whole 5 minutes to draw it).

For those who think in Arduino terms, Nanonyam is a virtual Arduino shield for controlling Windows.
In other words, Nanonyam is a virtual machine that uses firmware for the AVR microcontroller as bytecode (ATMEGA2560 is recommended). Inside this virtual machine is a simulator of the AVR core, but instead of peripheral devices located at SRAM addresses from 0x0060 to 0x01FF, there is a special interface to virtual functions (including Windows API functions). It’s important to understand right away: code for Nanonyam must not reference this memory range to avoid accidentally triggering functions like file deletion or disk formatting. The rest of the SRAM memory range from 0x0200 to 0xFFFF (which is more than in a real microcontroller) is available to the user for any purpose. I should note that there is special protection against accidentally launching the firmware of a real microcontroller (or firmware from another architecture): before activating 'dangerous' functions, you must call a special clever virtual function. There are also some other protective elements.
To create programs for Nanonyam, you need to use special libraries that implement all the virtual functions currently available. You can download the Nanonyam virtual machine and its libraries . Here, . And yes, my website is very primitive and not mobile-friendly.
The Nanonyam program is free for both home and commercial use. The Nanonyam program is provided 'as is'. The source code is not provided.
Currently, the program is in the testing phase. About 200 virtual functions have been implemented, allowing for the creation of simple programs for Windows.
It is clear that creating something complex in such a virtual machine will not be possible, as there is only 256 KB of memory for the code. Data can be stored in separate files, and the buffer for the graphical part is implemented externally. All functions have been simplified and adapted for an 8-bit architecture.
What can be done in Nanonyam? I have thought of a few tasks.
Developing software blocks
Once, I needed to develop a complex menu for a 128×64 pixel graphic display. I really didn't want to constantly upload firmware to a real microcontroller to see how the pixels looked. That's how the idea for Nanonyam was born. In the image below, you can see a screenshot from a real OLED display of one item from that menu. Now I can work on it without the actual device.

Nanonyam (in its final conception) is a good tool for developing software blocks for microcontrollers, as it includes functions for working with graphics (you can simulate displays and indicators), with files (you can create logs, read test data), with keyboards (you can read up to 10 buttons simultaneously), and with COM ports (this is a separate point).
Creating quick programs
For example, you need to quickly process 100,500 text files. Each one needs to be opened, slightly modified according to some simple algorithm, saved, and closed. If you are a Python master, congratulations, you have everything you need. But if you are a hardened Arduino enthusiast (and there are quite a few), then Nanonyam will help you tackle this task. This is my second goal for Nanonyam: to add a variety of useful functions such as text processing, screenshot creation, or simulating key presses in the system (all of which already exist), as well as many other functions for solving routine tasks.
Testing hardware through the COM port
Nanonyam can act as a terminal that runs on your algorithm. You can create a small menu for managing the device and display data received from the port. You can save and read data from files for analysis. It is a convenient tool for simple debugging and calibration of hardware, as well as for creating basic virtual control panels for devices. This project can be very useful for students and young researchers.
Learning Programming
As with the entire Arduino project, the main benefit of Nanonyam lies in the simplicity of its functions, interface, and bootloader. Therefore, this project should be interesting for beginner programmers and those who are satisfied with the Arduino level. By the way, I myself have not yet studied Arduino in detail, since I have always used WinAVR or AVR Studio, starting with assembly language. Thus, the example code below will be slightly inaccurate, but fully functional.
Hello, Habr!
It's time to get acquainted with some features of Nanonyam and write a simple program. We will write in Arduino, but not in the usual way, but rather as I currently know how (I have already mentioned that I still don't fully understand this environment). First, we create a new sketch and select the Mega2560 board.

We save the sketch to a file and copy nearby . It would be proper to include library headers, but I don't know how to specify compilation of individual files in Arduino, so for now, we will just include the libraries directly (all at once):
#include <stdio.h>
#include "NanonyamnN_System_lib.c"
#include "NanonyamnN_Keyboard_lib.c"
#include "NanonyamnN_File_lib.c"
#include "NanonyamnN_Math_lib.c"
#include "NanonyamnN_Text_lib.c"
#include "NanonyamnN_Graphics_lib.c"
#include "NanonyamnN_RS232_lib.c"It would be even better to create a special module 'Nanonyam for Arduino' that can be installed directly from Arduino. Once I figure this out, I'll do it, but for now, I’m just demonstrating the essence of working with a virtual machine. We write the following code:
//Сразу после запуска рисуем текст в окне
void setup() {
sys_Nanonyam();//Подтверждаем код виртуальной машины
g_SetScreenSize(400,200);//Задаём размер дисплея 400х200 точек
sys_WindowSetText("Example");//Заголовок окна
g_ConfigExternalFont(0,60,1,0,0,0,"Arial");//Задаём шрифт Windows в ячейке шрифтов 0
g_SetExternalFont(0);//Выбираем ячейку шрифтов 0 для рисования текста
g_SetBackRGB(0,0,255);//Цвет фона синий
g_SetTextRGB(255,255,0);//Цвет текста жёлтый
g_ClearAll();//Очищаем экран (заливка цветом фона)
g_DrawTextCenterX(0,400,70,"Hello, Habr!");//Рисуем надпись
g_Update();//Выводим графический буфер на экран
}
//Просто ждём закрытия программы
void loop() {
sys_Delay(100);//Задержка и разгрузка процессора
}The sketch with this program . A detailed description of the functions . I hope there are enough comments in this code to understand the essence. Here, the function sys_Nanonyam() serves as a 'password' for the virtual machine, lifting the restrictions on virtual functions. Without this function, the program will close after 3 seconds of operation.
Click the 'Verify' button, and there should be no errors.

Now you need to obtain a binary file (firmware). Select the menu 'Sketch>>>Export Binary File (CTRL+ALT+S)«.

This will copy two HEX files into the sketch folder. We only take the file without the prefix "with_bootloader.mega".
There are several ways to specify the HEX file to the Nanonyam virtual machine, all of which are described . I suggest creating a file next to Nanonyam.exe file Nanonyam.path, where you specify the full path to our HEX file. After that, you can launch Nanonyam.exe. We get a window with our inscription.

Similarly, you can create programs in other environments, like AVR Studio or WinAVR.
For now, we'll conclude our introduction to Nanonyam. The main idea should be clear. . If there are enough people interested in using this project, I will create more examples and continue to "fill" the libraries of virtual functions. Specific ideas for project development and reports on malfunctions, bugs, and typos are welcome. Ideally, send them through the contacts . Discussions are welcome in the comments.
Thank you all for your attention and happy programming!
Source: habr.com
