where is main.py ?

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

where is main.py ?

Postby chrisPyres66 » Thu Jul 19, 2018 9:27 am

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

Code: Select all

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,
User avatar
kwagyeman
Posts: 2316
Joined: Sun May 24, 2015 2:10 pm

Re: where is main.py ?

Postby kwagyeman » Fri Jul 20, 2018 12:54 am

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.
Nyamekye,
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: where is main.py ?

Postby chrisPyres66 » Fri Jul 20, 2018 2:49 am

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 :

Code: Select all

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,
User avatar
kwagyeman
Posts: 2316
Joined: Sun May 24, 2015 2:10 pm

Re: where is main.py ?

Postby kwagyeman » Fri Jul 20, 2018 10:57 am

? I can't tell... The code we have on github works. So, if you are modifying you should know what you are doing.
Nyamekye,
User avatar
chrisPyres66
Posts: 28
Joined: Mon Jul 16, 2018 9:22 am
Location: France

Re: where is main.py ?

Postby chrisPyres66 » Mon Jul 23, 2018 7:37 am

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.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests