Friday, January 15, 2016

First steps: Arduino Blinky and FreeRTOS on Windows

First of all, you should buy your Arduino. Their site sells the real deal [1], but I guess an Aliexpress copy will do the trick just as fine. With the board in hand, download and install the Arduino IDE [2].

The first project to test will be the Blink Project! So open the IDE, connect the USB cable to the board and your computer, select the correct board, processor and port under the Tools menu. Under File, select Examples -> 01.Basics -> Blink. Scroll down the source code and you'll see the setup() function, that's where you put sources you want to run one once (like setting the LED pin 13 as an output), and the loop() function, where you maddest ideas are written (this function will run in a loop, endlessly).

To compile your code and send it to the board, either click on the second button from left to right (the one with the arrow), click on Upload under the Sketch menu. If everything went well, the LED on your board will be blinking.



If you're not used to programming Arduino, I strongly recommend you read a lot on Arduino's webpage ([3] and [4]), as I don't pretend to describe what each function does and how it does what it does.

As for FreeRTOS, there are several books regarding it, but I' always try to use the free contents you find around. So first of all, check the official website [5]. One of the first things you'll see is that there is a lot to read! But don't worry, I'll try to guide you by less-reading path.

First thing: download FreeRTOS ([6] - I'm currently using version 8.2.3) and, if you don't have any version installed, the free version of Microsoft Visual Studio ([7] - I'm currently using version 2015 for Desktop). Yes, Visual Studio. FreeRTOS has a port to Windows that won't be as accurate when speaking of Real Time, but will serve its purpose of test platform and first try. Every port of the RTOS has a Demo project, which serves as a fast start, containing a complete documentation [8]. There is also a way of using Eclipse with MingW and I'll talk about it later.

On Visual Studio, open the file Win32.sln located on FreeRTOS/Demo/WIN32-MSVC and on the Solution Explorer tab (on the right), open main.c and main_blinky.c under RTOSDemo/Demo App Source. On the first, set the definition mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 1. There are two Demos: when the option is 0 (default), it runs the code from main_full.c, a more comprehensive demo project; when it's 1, it will run a simple Blink project. The simple project will run two tasks and a queue (check it on the function main_blinky() on main_blinky.c): one task (prvQueueSendTask, the Sender) will send the value 100 to the other (prvQueueReceiveTask, the Receiver) through the queue (xQueue). When the Receiver receives the value, it will print a message on the terminal. Now press the Play button (Debug -> Start Debugging) and a terminal window will appear and the Receiver will start writing its messages.


Now, for Eclipse, this is the recipe: download and install both Eclipse IDE for C/C++ [9] and MinGW's C++ compiler [10]. Start Eclipse, go on File -> Import -> General/Existing Projects. On the new window, choose FreeRTOS/Demo/WIN32-MingW as the root directory and finish. The rest is the same as for Visual Studio. To start debugging, first build the project (Project -> Build All, or CTRL + B) and then run (Run -> Debug, or F11): the execution will be shown on the lower side of the Debug perspective (tab "Console") and will stop as soon as it enter the main() function. Press Run -> Resume (F8) and check the messages from the Receiver.


No comments:

Post a Comment