-1

I was making a project with Arduino Uno , It's working is like this it connects to a key pad and a 7segment display ,and when you press a run button connected to Arduino it should run the code written.

I don't want code for display and keypad but for executing a string like we can do in python- exec("print (8)")

Please help me and ask any information you need to solve it

2
  • There's a technical answer to your question. But a more practical answer can probably be given if you explain why you would want to do this on an UNO.
    – timemage
    Commented Dec 31, 2020 at 14:18
  • you could try forth ... it's not python, but it is interpreted ... arduino-forth.com .... you could write some forth words to emulate some of the python commands
    – jsotola
    Commented Dec 31, 2020 at 17:00

2 Answers 2

4

Unless you want to implement some form of scripting engine, you can't.

Arduino code is compiled code, not interpreted code. There is no way of converting text into runnable code, since that is done by your computer at compile time, not by the Arduino at run-time.

The only thing you could possibly do is write some form of scripting engine which reads text and interprets it in some meaningful way to perform operations. That is not a trivial task, so you have to ask yourself: is this really what you want to do? Are you going about tackling your problem in the right way?

1
  • Things like reflection in higher level languages that would make this an “easier” task aren’t available in C++ Commented Jan 1, 2021 at 4:33
1

As stated in Majenko's answer, you would need an interpreter running on the Arduino. Python is too large to run on an Uno, although it can run on some more powerful microcontrollers.

A Web search for Arduino interpreters yields quite a few promising options. I have not tested any of them:

The Forth language is quite popular when you need an interpreter with minimal footprint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.