Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate with an Arduino over its serial interface in C++ on Linux?

I have an RFID reader connected to an Arduino board. I'd like to connect to it over its serial interface, and whenever the RFID reader omits a signal ( when it has read an (RF)ID ), I'd like to retrieve it in my C++ program.

I already have the code for simply printing the RFID to serial from the Arduino.

What I don't know, is how to read it from C++ in Linux ?

I have looked at libserial, which looks straightforward. However, how can I have the C++ program react to a signal and then read the RFID, instead of listening continously? Is this necessary?

EDIT: In most examples I have read, the (c++) program sends input, and recieves output. I just want to listen and recieve output from the Arduino.

like image 419
meastp Avatar asked Oct 03 '08 22:10

meastp


People also ask

How do I send a serial message to Arduino?

Upload the sketch and send messages using the Serial Monitor. Open the Serial Monitor by clicking the Monitor icon (see Recipe 4.1) and type a digit in the text box at the top of the Serial Monitor window. Clicking the Send button will send the character typed into the text box; you should see the blink rate change.

Can Arduino read C?

All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process.

Which protocol is used for communication between Arduino board and serial monitor?

UART stands for Universal Asynchronous Reception and Transmission and is a simple communication protocol that allows the Arduino to communicate with serial devices. The UART system communicates with digital pin 0 (RX), digital pin 1 (TX), and with another computer via the USB port.

How does Arduino communicate with serial monitor?

You can use the Arduino environment's built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin() . Serial communication on pins TX/RX uses TTL logic levels (5V or 3.3V depending on the board).


1 Answers

On unix you use the select() call to wait for an input. The select() call acts like a sleep - using no CPU until the kernel receives the hardware interrupt and triggers the select().

http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html

like image 68
Martin Beckett Avatar answered Oct 04 '22 21:10

Martin Beckett