Arduino Serial Extractor
The most time consuming, effort consuming duty i have whenever I want to
start a simple arduino project that relies on serial commands sent from
the pc|bluetooth, is how to extract these commands from the serial on
the Arduino side, how to get the actual numbers. Take for example you
want to interface a servo motor, you will only send the angle in the
serial, but when you have two servos, you will send two angles and
process the message to extract the angles from serial ( on arduino
side), but what if you have a robotic arm you have to specify that
extraction for the message sent via custom code you made on your pc,
that thing is getting messed up !! how you gonna tell the joint number 3
to rotate that angle and joint number 4 to rotate another angle !!!
Simple Serial Extractor [here]
This would be the best solution for me !! to have underlying library
that will take care of processing the message and give me the values
that i need nothing more nothing less !!
Usage
- Download the code or clone it to your project directory
- Include the SerialExtractor header file in your project main code
- Specify the splitter, msg end indicator, callback on receive function
- Run in main loop
Example:
The following code will accept data in the form:
30,20,-50#
Where numbers are random ( for example sake) and the delimeter between them is the "," comma
The output is sent to the callback function as array of integers
[30,20,-50]
so accessing the array will lead you to use them...
#include "SerialExtractor.h"
SerialExtractor ser;
void callBack(int a[], int sz)
{
for (int i=0; i<sz; i++)
{
Serial.println(a[i]);
}
}
void setup() {
// put your setup code here, to run once:
ser.SetCallBack(callBack);
ser.SetDelimeter(",");
ser.SetEndIndicator('#');
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
ser.Run();
}
Comments
Post a Comment