Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (59 sloc) 2.42 KB

Arduino Serial Interface

With this serial interface you'll be able to send commands from a console in your PC to the arduino. You can also define your own commands for the arduino.

In this example we use a desktop console app and an arduino program to move a servo attached to the Arduino.

Send the "servo" command from our desktop app to the arduino program, and type the desired angle. The arduino board connected via USB will do the rest!

How does it work?

Just need to use the methods read and write to communicate with the device through serial port. Those functions and the whole API definition are defined in david/serial_arduino and david/serial_cpp libraries.

How do I use it?

  • You need to create two projects arduino_app and cpp_app, one will contain the code that will be uploaded to arduino and the other one the client application that will run in your PC.

    $ bii init cpp_app
    $ bii init arduino_app
  • Open the examples: C++ app code goes into your pc project and arduino code goes into the arduino's project.

    $ cd cpp_app
    $ bii open examples/serial_interface_cpp
    $ cd arduino_app
    $ bii open examples/serial_interface_arduino

C++ code

Change the Serial Port ID in the main_cpp.cpp file with the one you are using with the arduino.


.. literalinclude:: ../../_static/code/arduino/examples/serial_interface/main_cpp.cpp
   :language: cpp

Arduino code


.. literalinclude:: ../../_static/code/arduino/examples/serial_interface/main_arduino.cpp
   :language: cpp

Build and run!

Execute following commands in each project:

Arduino App

$ bii arduino:settings
$ bii configure -t arduino
$ bii build
$ bii arduino:upload

C++ App

$ bii build
$ cd bin
$ #run solver executable
Enter: servo
Enter: 180
Enter: servo
Enter: 90

Now you can start hacking your own commands!