Serial Toolbox Plugin

 
#1

@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. Smile Smile

#2

All the serial commands for the ezb can be found in...

EZ_Builder.EZBManager.EZB[0].Uart

#3

@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. Smile

#4

@DJ

Also curious as to how the serial plugin handles the arduino side of things...Rick.

#5

Only to give a little bit of context.
Rick sent me an email requesting some help to integrate an Arduino with EZ-Builder.

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.

#6

Hardware used:
=============

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)

#7

Arduino Code:

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.

#8

Test Arduino Code:
===============
Open the Arduino Serial Console:

User-inserted image

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:


SerialCommand cmd_read_analog_("READ_ANALOG", cmd_read_analog);
SerialCommand cmd_set_led_("SET_LED", cmd_set_led);
SerialCommand cmd_start_push_("START_PUSH", cmd_start_push);
SerialCommand cmd_stop_push_("STOP_PUSH", cmd_stop_push);



accepts the following commands: READ_ANALOG, SET_LED, START_PUSH, STOP_PUSH

some examples:

Code:


//reads analog port 0
READ_ANALOG 0

//read analog port 1
READ_ANALOG 1

//read analog port 2
READ_ANALOG 2

//set red led (ON) RGB Led (Common Cathod/255-Off, 0-ON)
SET_LED 0 red

//set red and green led (OFF)
SET_LED 255 red green

//set red and blue led (HALF bright)
SET_LED 128 red blue

//request ping push messages every 1000 ms
START_PUSH 0 1000

//request analog push messages every 3000 ms
START_PUSH 1 3000

//stop ping push messages
STOP_PUSH 0

//stop analog push messages
STOP_PUSH 1



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:

User-inserted image

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.

#9

EZBuilder Side
============

To be continued...

#10

reserved 5