where is main.py ?

Dear All,

I try to insert my python code inside the main.c of the firmware but i dont find the main.py.
I mean main.py always wait an usb connexion in place of my uart com and led blinking.

First, I tried to modify the array (fresh_main_py) used to create file on the sdcard, but i dont use sdcard, so it is never used…

static const char fresh_main_py[] =
"#main.py -- put your code here!\n"
"import pyb, time\n"
"led=pyb.LED(2)\n"
"uart=pyb.UART(3,19200)\n"
"while(True):\n"
"   uart.write(b'A')\n"
"   led.on()\n"
"   time.sleep(150)\n"
"   led.off()\n"
;

I used the python code tested before through the ide.

Secondly, i tried to use exec_boot_script(“path/script.py”, false, true) but it does nothing because the path is wrong like boot, selftest but opposite to main.py ?
I suppose it is used for sd card file but how it works with main.py without sdcard…

Thirdly, I dont find any main.py in src directory ?

I am lost, what is your point to do this simply ?
pyexec_str function uses a vstr_t than i dont know…

Thanks,

Hi, main.py is inside the main.c file as a text string. It’s only created on bootup if the camera doesn’t have an SD card.

Um, if you want to bake your code into the camera’s firmware and need an SD card you can also just execute methods to open up a new file and write the text string of your main.py to any disk once the disk is loaded. See some of the machine vision library code for how to do this.

Dear Kwagyeman,

Thanks for your answer, it is was my first idea to do this but the program never went there because of a wrong if :

if ( res == FR_OK) { // FR_NO_FILESYSTEM { // Chris Modif
	// Create a fresh fs
	make_flash_fs(); // here is created main.py
	....
}
else ...

Is it a bug or is it normal ?

I hope it could help.
Thanks,

? I can’t tell… The code we have on github works. So, if you are modifying you should know what you are doing.

Thanks, i am just beginning with openmv.
Therefore i cant say i am sure of what i do, but i will verify this in future and keep you informed.