Hi, I have an Adeept arm and I am trying to set up a user interface where the user can control the movements of the are by entering certain text strings into an input field. For example, typing and entering "Servo1 To 90" could correspond to the Arduino command "servo1.write(90)".
I want to have a list of pre-defined commands and put the program in a while loop so the user can enter multiple commands causing multiple movements in sequence. (If the user enters a string that is not any valid command on the list, nothing should happen.)
Is there a way to either:
1: Create a text input field in the Arduino IDE?
Or
2: Integrate Arduino code into a Jupyter notebook Python file (which allows text input fields)?
And do I need to upload a new program from the Arduino IDE to the board each time I want the arm to carry out a novel movement? Or can I upload a single program that will allow the board to continue to take inputs from the keyboard on the attached computer?
are you using a PC to transmit commands to the Arduino to move the arm?
if so implement a simple protocol as suggested by @paulpaulson
you could then build a GUI on the PC where a selection of buttons/textfields/sliders etc could be used to input commads which are then transmitted to the Arduino using the protocol
the GUI could be implemented using Java, C#, Python, etc
@horace I am using a Mac, and I was not looking to create an entire Graphical User Interface unless I need to (and I don't really know how to do that). I was thinking of something more like a single text input field that shows up in the same Arduino IDE window as the code - analogous to how you can have an input field in a Jupyter notebook file under the cell that is running code (so you can, for example, set the value of a string by typing into the input field without changing the code in the actual cell).
Do you happen to know if this functionality exists in the Arduino IDE, and what the syntax is for it if so?
If you are familiar with Python/Jupyter Notebooks, I can post examples of the kind of thing I am talking about, if that would help.
You can input stuff through the serial monitor window.
No syntax, you just make it up as you go along. If you input a command you can read it as a string and then when you read it in you can check which one of your predefined strings it matches and then issue the commands to do this.
Each new command you want to interpenetrate has to have its own bit of code to implement it. There is no point in typing in code that the Arduino doesn't understand.
I to am on a Mac, and you can implement a graphic interface using a programming language called "Processing", it is C like in syntax but is actually Java under the hood. If you know C then you will be able to understand it. It is free and comes with Mac, Windows and Linux versions.
I recently wrote an example code for driving servos, from an Arduino via a GUI in Processing, if you would like me to dig it out?
This is the screen dump of the GUI from processing.
You set the required angel by dragging the arc on the angle knob, then by clicking one of more of the blue boxes you send that angle to the servo S0 to S15 as given by the label on the blue box.
Of course there is some Arduino code on the other end that interpenetrates the angle set by the knob and applies it to the servo number given by what box you clicked.
I don't use Macs or Python but it may be a good idea to post some examples as other forum users may have ideas
Here is what the analogous thing would look like in Jupyter Notebooks. In the white box at the bottom a user can type strings that correspond to moving a selected servo to a specified angle.
If the typed string is a valid pre-defined command, the result should either be that a line of Arduino code get uploaded to the board so that the arm carries out that movement. If the typed string is not a valid command, the result should be an error message displayed on the screen.
I to am on a Mac, and you can implement a graphic interface using a programming language called "Processing", it is C like in syntax but is actually Java under the hood. If you know C then you will be able to understand it. It is free and comes with Mac, Windows and Linux versions.
I recently wrote an example code for driving servos, from an Arduino via a GUI in Processing, if you would like me to dig it out?
Thanks, yes it would be helpful if you could dig out some example code/sketches, as I am not really that familiar with C syntax.
You set the required angel by dragging the arc on the angle knob, then by clicking one of more of the blue boxes you send that angle to the servo S0 to S15 as given by the label on the blue box.
Of course there is some Arduino code on the other end that interpenetrates the angle set by the knob and applies it to the servo number given by what box you clicked.
Do you know if this also supports interfaces where the user must enter a string in an input field? Or is it only for click-and-drag type interfaces?
Please do not post code as images. It is singularly useless, no one is going to be bothered to type it in. Best post it as code then we can all see it and try it if we want.
This is a zipped up file of both the code in the Processing side and on the Arduino side. Processing Messages.zip (48.2 KB)
The whole package is a "not quite completed" proposal for a tutorial so contains a text file with a lot of explanation about what is going on with the code.
It is designed to run in Processing 4, which you must load onto your Mac first. Processing 4 will also work on windose and Linux.
It can with some changes.
This code will allow you to send messages to the Arduino, so if you want you can type messages into Processing and have them sent to the Arduino. This will need a bit of change to the code at both ends. At the Processing end use the Keyboard function to gather your message into a string and then send it, by calling a modified version of the send message function that handles strings, when the keyboard input function detects a return character.
Also of course you need to modify the Arduino end to cope with what you receive.
Note do not open any serial monitor windows on the Arduino as this will make the whole thing not work. Arduino feedback is provided in Prosessing's console window underneath the code window.
Please do not post code as images. It is singularly useless, no one is going to be bothered to type it in. Best post it as code then we can all see it and try it if we want.
I shared the screenshot to give an idea of what the text input field would look like and how it would work. Except that for the real application I am going for, I would want the arm to execute the Arduino Command movement when valid strings are typed rather than simply display the code for the command on the screen. But if anyone has Jupyter Notebooks and wants to try the code, here it is:
EXIT = False
Numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
Servos = ["Servo1", "Servo2", "Servo3"]
while(EXIT == False):
Print_String = ""
print("")
Input = input("Input a Servo Number, single space, and 2-digit Target Degree; or input 'EXIT' to exit:")
print("")
if(Input == "EXIT"):
EXIT = True
print("Program Exited")
else:
if(len(Input) == 9):
if((Input[0:6] in Servos) and (Input[6] == " ") and (Input[7] in Numbers) and (Input[8] in Numbers)):
Print_String += "Arduino Command: "
Print_String += Input[0:6]
Print_String += ".write("
Print_String += Input[7:]
Print_String += ")"
else:
Print_String += "'"
Print_String += Input
Print_String += "' is not a valid command"
else:
Print_String += "'"
Print_String += Input
Print_String += "' is not a valid command"
print(Print_String)
This is a zipped up file of both the code in the Processing side and on the Arduino side.