
rbonari
@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.
EZ_Builder.EZBManager.EZB[0].Uart
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.
Also curious as to how the serial plugin handles the arduino side of things...Rick.
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.
=============
1) Arduino UNO
2) EZB V4
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)
1) Libraries
To make the process less complicated, i created an Arduino library called SerialCommands you can grab from here:
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.
2) Example project:
https://github.com/ppedro74/ArduinoPlayground/blob/master/TestSerialCommands/TestSerialCommands.ino
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.
===============
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)
Code:
accepts the following commands: READ_ANALOG, SET_LED, START_PUSH, STOP_PUSH
some examples:
Code:
The above commands are examples how:
1) Set actions (SET_LED) (Note: multiple parameters example)
2) Read Values (READ_ANALOG)
3) Monitoring values / Pushing results (START_PUSH / STOP_PUSH)
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.
============
To be continued...
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.
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: http://www.ez-robot.com/Tutorials/Lesson/18?courseId=4
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:
Code:
And to get data back... do something like this...
Code:
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.
1) multiple push button keypad
2) multiple leds
3) oled 128x64
4) other sensor devices.
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.
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...
Code:
You can do this by following this part of the plugin tutorial: http://www.ez-robot.com/Tutorials/UserTutorials/146/22
something like..
[ADDRESS], [COMMAND], [DATA]
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.
Code:
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.
Code: