Use of Phyton and C++ for Arduino Mega

Hi, I'm a 3rd year college student and we are making a prototype and Arduino Mega is our input and use for microprocessor. We are using phyton because Machine learning algorithms used phyton language and C++ language for our hardware (sensors, led and etc.) just wanted to ask how to put phyton and C++ program together in one for our Arduino Mega Code.

you can communicate using Python serial communications
have a look at htwhy-do-serial-commands-from-python-dont-run-arduino-when-sent-in-a-for-loop
an alternative is to use TCP/IP but you require a board which supports WiFi, e.g. ESP32
have a look at esp32-s3-softap-connect-and-receive-data-with-python

Are you asking how to transfer a Python program using Python's algorithms (meant for your PC) for Machine learning into your MEGA?

or are you asking how can the MEGA transfer some data to the PC where a Python code will await the data input and apply all the Machine learning algorithms?

You either need to translate your python to C++ and make a C++ program or translate your C++ to python and make a python program
You can program some Arduinos using micropython

BTW - The Arduino Mega won't have the compute power and memory needed for most Machine learning algorithms (if this is where you think the code will run)

The first one, we are doing some Machine learning in PC and wanted to know how to insert it in code with c++

Can you explain it to me clearly? how machine learning will work with arduino to integrate the hardwares? Thank you, we really wanted to learn, we already have codes for our sensor but we are struggling how to integrate them to machine learning algorithms.

Can I ask, is microphyton an another library to be installed?

have a look at micropython tutorial - recommend using an ESp32

Not a library but it is another software that need to be installed.
CircuitPython is another implementation of python for microprocessors
I have not used either

so this ?

just forget it - your MEGA won't have to power nor memory to run it and you can't run Python there.

we've already saw some machine learning run by arduino uno only in youtube and with a bigger memory like mega, how come its not enough? I humbly asking a clearer response, cause I didn't understand, sorry for the inconvenient we're beginners.

define then what you call "machine learning" (tensorFLow and the likes?) and share the youTube video of this running on a UNO...

here is an example on a much more capable arduino

1 Like

Another is femtopython

And was this running Python at the same time on a UNO?

I think you misunderstood what you saw.

I have used Circuit Python quite a lot. I use it on a Raspberry Pi PICO 2040.
I use a Mac and a an editor / IDE called Thonny. It the only Python you can run on a PICO that has a USB MIDI interface. And the PICO is very reasonably priced, especially when compared to the Nano BLE sense.
The PICO also has a second serial port that can also be used as a conventional MIDI 5 PIN MIDI interface.

this would be the process of ours, is it ok?

Firstly we will train an ai model where the machine can identify the object if it's a Plastic, Paper and Food waste.
Secondly after training an ai model we would like to use Arduino and combine it to a model.
Where after identifying those objects where it should belong if it's a Plastic, Paper and Food waste the answers should be passed to Arduino and the Arduino will do the rest.

Where would the object recognition run? If it’s on a Mac/PC/Smartphone then fine there is enough compute power.

Then it’s just a matter of having that application talk to the Arduino so that’ it takes action. That’s done easily over the Usb connection / Serial link.

yes, we have PC for machine learning, we really just struggling to know how to integrate the machine learning with our C++ codes for hardware. So it can function as what we wanted to

My experience is that I found best to use tasks in python to listen to the Serial port, I gave an example in this post

You’ll find tons of on line examples here in the forum as well

If you read French (or just Google translate) I have a tutorial on this topic too with code ready to use.