rbonari
USA
Asked
— Edited
@PTP
I have read over the tutorial on making plugins and it was very good and helpful. I am looking to do a plugin using the serial port on the ezb to communicate with an arduino type board to communicate back and forth with various sensors, lcd's, etc.
I was wonering if I could get your source code for the serial toolbox plugin to learn from regarding serial port communications with ezb, etc. I am also taking a course on c# but there is nothing like actual examples of code when it comes to communicating with hardware serial ports. Most all courses don't go into this type of coding. Thanks much....Rick.
All the serial commands for the ezb can be found in...
EZ_Builder.EZBManager.EZB[0].Uart
@DJ
Thanks much, that helps but there is nothing like having a completed and working example to look over and learn from. The serial toolbox covers alot more than what was included in your awesome tutorial on plugins...Rick.
@DJ
Also curious as to how the serial plugin handles the arduino side of things...Rick.
Only to give a little bit of context. Rick sent me an email requesting some help to integrate an Arduino with ARC.
I will start by saying that: Arduino is not EZ you can easily open the IDE, copy paste some code, compile, flash and run.
But if you need to dig in you will need to know C/C++ language, how the libraries work, board specific details, code optimization, troubleshooting without breakpoints, limited memory, limited resources, interrupts, timers etc, etc.
Hardware used:
Arduino:
Power = USB/Cable Pins 0 - RX - Grey wire 1 - TX - Purple wire 3 - Red wire 5 - Green wire 9 - Blue wire GND - Black wire 5V - Orange wire
RGB Led (Common Cathode)
Red Led - Red wire Green Led - Green wire Blue Led - Blue wire 5v - Orange wire
EZB
Power = 7.5v Power supply Uart 0 - RX - Purple wire Uart 0 - TX - Grey wire Uart 0 - GND - Black wire (Common Ground)
Arduino Code:
https://github.com/ppedro74/Arduino-SerialCommands
Please download the and install the arduino library.
i opened a ticket to publish the library via Arduino IDE tool, later you will be able to search and install automatically via Arduino IDE.
Compile and flash!
Note: When flashing an Arduino with a single Serial Port (Atmega328, Atmega168) disconnect the RX/TX cables (EZB side) to avoid interferences.
Test Arduino Code:
Open the Arduino Serial Console:
Blue Note: When sending serial commands the existent code expects the CR & LF to end a line
Red Note: 57600 bps is intentional ! All micro-controllers have different clocks, when working with serial communications both sides (RX / TX) agree on a specific BaudRate / Clock, unfortunately 115200 bps @ atmega328 is not 115200. So let's use 57600.
more here: https://arduino.stackexchange.com/questions/296/how-high-of-a-baud-rate-can-i-go-without-errors
The arduino code (relevant part)
accepts the following commands: READ_ANALOG, SET_LED, START_PUSH, STOP_PUSH
some examples:
The above commands are examples how:
After submitting the above commands:
Note: After the START_PUSH the arduino code starts pushing messages to the console. This can be modified to instruct the Arduino to perform some action or monitor a sensor and report the values back with a specific frequency or a specific trigger, all depends the code logic.
ARC Side
To be continued...
reserved 5
nice! ptp, have you thought of making this a user tutorial? rather than a forum post... Look here: https://synthiam.com/Tutorials/UserTutorials/
Thanks for putting this together. One area I was struggling with when talking to the UART was sending multiple commands at once and waiting for answers to come back. I have to do it one command at a time. Send request, wait for aknowledgment, and then act. Example I am reading the position of a dozen servos and then mirror the servos with a second set to mirror the position of the first set of Servos. Unfortunately this means I have to send individual get location requests, wait for acknowledgement, process data checking for CR LF and then send to new Servo. Then repeat for next one.
What would be better if I could send a command to arduino to say keep checking servo locations if nothing changes don’t talk to me but if one changes send me a messsage.
I haven’t had a chance to get around to this yet but would be nice if we had a way to reduce chatter between two devices.
Nink, if you're creating the application protocol yourself - meaning you get to define the commands and what to expect in response...
So if that is the case, do not terminate. And you generally see some "command packets" have a silly checksum. That's silly in this day of age... specifically with TCP already embedding sanity checks. And to communicate over UART, well... it's pretty difficult in this day of age to have a single byte go unnoticed. Back in the day... and i mean like 20-30 years ago when cpu's were slow and interrupts were rare... that's when sometimes a byte could go unnoticed.
Anyway - the next thing is the command and termination. So yeah, don't terminate. Create a list of commands and their expected response size. That way you can cut the transmission speed and processing significantly.
Take for instance if your command is 1 byte, and your termination is 2 bytes (crlf). That's 3 bytes per transmission. And if your response is 1 byte, but terminated with 2 bytes (crlf) then that's 3 bytes for transmission. That's a total of 6 bytes to do one little thing. If you didn't terminate, and had an expected list of commands and their length, then you'd cut that transmission size by 300%! So if you were to transmit 100 commands, with a CRLF you'd actually be transmitting 300 Bytes vs 100 Bytes. HUUGGE difference with volume! (three times as much...)
Now, we've only reviewed the datasize. We haven't touched on the processing aspect. Part of the discussion is "oh now i have to parse the data blah blah blah". Why do you have to parse data? Never parse data. Parsing data when you should know what to expect is unnecessary. If you're in control of the data, don't design it to be parsed. CPU processing time is a luxury, not a right
Have you taken a look at the ez-b communication protocol datasheet? That will give you an idea of how to implement an application protocol of your own.
Here, take a look at this: https://synthiam.com/Tutorials/Lesson/18?courseId=4
While you add to that, let me expand on what an efficient application protocol should look like...
What i recommend is, if you only need to set and receive servo positions, is to use the 7th bit to determine SEND or RECEIVE. That gives you 127 servos you can send or receive to.
So to SEND a command, have it like this...
COMMAND, POSITION (0-127), (0-255) i.e. Move servo 0 to position 50:
And to get data back... do something like this...
@DJ, Thanks I agree with you a Tutorial will be more easy to follow and update. I'll finish this thread, and use the user feedback to create a tutorial.
@Nink I'll provide examples how the plugin can help for different scenarios sync and async data responses.
...
This a text protocol, is not optimal neither bullet proof but it's EZ to debug and test and improve but there some limitations: message size and text only.
So if you want to send sound bytes or bitmap bytes you need to develop a custom protocol similar to the EZ-Robot.
...
I've a custom robot, and I'm using multiple mini controllers to solve different problems (time sensitive) and HID (Human Input Devices) related e.g.
I like the concept of building blocks, so each problem is solved with a micro-controller, but in the end they need to communicate with a master controller EZB or a Host.
Each device sends and receives data sync and async, so I2C does not fit, so I'm using serial (tx,rx).
If each device requires a serial port, soon or later you will run out os UART ports.
So each device has two or more serial devices, and they relay/route the messages using their serial ports, so you can have a Host with a single port communicating with N inline serial devices or you can have a network with multiple nodes (redundant paths or alternative more/less hops)
I couldn't find anything simple (Library) to use so this is another mini project i'm working on.
Okay - now last part of the lesson
Once you have a good working EZ-Script that sends and receives your servo commands, turn those into EZ-Script functions as a plugin. The neat thing about ARC is you can extend the capabilities, including ez-script. So you can create a plugin that registers the commands...
You can do this by following this part of the plugin tutorial: https://synthiam.com/Tutorials/UserTutorials/146/22
ptp, add an address byte at the beginning of each command - that way all other controllers ignore the command if it's not addressed to them.
something like..
[ADDRESS], [COMMAND], [DATA]
Thx @DJ and @PTP If you have a look at my code I am trying to interface with Meccanoid bios but the commands are structured and responses come back and I don't really know the size of the packet (could be 4 or 5 bytes. I wrote my own error check and put a wait in after 4 bytes but I really need to redo the meccanoid bios to make this work effectively. I also need to create a unique ID on each packet and then queue them but .....
Goal was to build 1 JD from meccanoid servos and 1 from EZB servos and mirror the second one off the first one (Move left arm on first JD and Left arm on second JD moves) I have 2 read and 2 write servo's working now but it's messy.
I think you'll need to start by telling us what a "meccanoid bios" is. Is there a data sheet?
Meccanoid BIOS was the original firmware released by Meccano for Meccanoid. It was supposed to be open source but the version they released was not easy to interface with. Some smart folks wrote some code to interface with it (I see there is even a tutorial on EZ-Robot) to control servo's (but they don't read current servo position from it) . It ran on a Arduino.
Meccontrol wrote a better version of the meccanoid BIOS you could interface with, but it was really written to interface with his own app, although he did publish a command interface I mentioned at top of code. Anyway I think I have derailed the thread. I will need to read up on creating plugins.