Reputation: 13
I just recently started working with Arduino
. I just have a quick question, I tried searching for an answer but have failed for days. Basically what I wanna ask is if there is a way to read a whole line from the Serial Port. Like the line highlighted in the picture below.
What I'm trying to do is using a Bluesmirf Silver Rn-42
to search the area for a bluetooth device and trigger a signal if a matching address is found. I just cant figure out how to read messages that are already on the Serial port.
Upvotes: 1
Views: 3745
Reputation: 174
If you want to read something that's already in the serial port from the Arduino end, then you need to rethink your code. Anything you produce within your code to print to the serial monitor will already be in your program ready to access if you make it available in the right way. The exemplar string you provided, is simply an array of characters that you can store in an element within an array, making it accessible whenever you need it.
Hints:
However, if you want to read from the COM
port that the Arduino is connected to in Windows, then you'll need to work with Libusb libraries found here: http://www.libusb.org/
for C. Any other language will be library or import dependent.
Upvotes: 0
Reputation: 372
Use .readString()
Example code:
String myString;
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available())
{
myString = Serial.readString();
//do stuff with the string
}
}
Upvotes: 2