Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Sunday, April 26, 2015

STM32F4 Discovery Tutorial 6 - USART Polling Mode

In this tutorial, I will share how to use STM32F4 USART in polling mode. STM32F4 Discovery board has 6 U(S)ART channels (USART1, USART2, USART3, UART4, UART5, and USART6). USART can be used for communication with PC or another device that use USART communication such as bluetooth module, GSM module and so much more. USART 1 and USART6 are connected to APB2 bus and able to communicate at speeds of up to 10.5 Mbit/s. USART2, USART3, UART4, UART5 are connected to APB1 bus and able to communicate at speeds of up to 5.25 Mbit/s.

To interface STM32F4 to your PC with USART, you can use either DB9 port or use USB port (Using USB to RS232 converter or USB to TTL converter). If you use DB9 port, then you must add additional electronic components like MAX232 IC to adjust voltage level.


Saturday, April 18, 2015

STM32F4 Discovery Tutorial 5 - Make Delay Using System Timer (SysTick)

In this tutorial, I’ll explain about system timer (SysTick). SysTick timer can be used to make delay function. STM32F4 has a 24-bit system timer, that counts down from RELOAD value to zero (16,777,215 to 0). The SysTick clock source is 168 MHz so 168,000,000 ticks per second. The time required to make one tick is 1 ÷ 168,000,000 ≈ 5.952 ns.

To use SysTick timer we have to call SysTick_Config function which responsible to initializes the system tick timer and its interrupt and start the system tick timer. The timer is in free running mode to generate periodical interrupts. Parameter input of SysTick_Config function is number of ticks between two interrupts (time between two interrupts). You can see SysTick_Config function in core_cm4.h.


Wednesday, April 15, 2015

C# and PostgreSQL Using Npgsql Tutorial 3 - SELECT Command

In this tutorial, I will share to you about SQL SELECT command. For me there is two technique that commonly used for read the result of SELECT command. The first technique is use NpgsqlDataReader and the second is use NpgsqlDataAdapter. This is the example code when using NpgsqlDataReader:
// Select all records form tb_music using NpgsqlDataReader.
public List<Music> selectAllRecordsUsingList()
{
    List<Music> music = new List<Music>();

    openConnection();

    try
    {
        // Create select command.
        NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM " + 
            "tb_music ORDER BY id ASC", connection);

        // Prepare the command.
        command.Prepare();

        // Execute SQL command.
        NpgsqlDataReader dr = command.ExecuteReader();

        // Fill results to music list.
        while (dr.Read())
        {
            music.Add(new Music(dr.GetInt32(0), dr.GetString(1), 
                dr.GetString(2)));
        }
    }
    catch (NpgsqlException ex)
    {
        showError(ex);
    }

    closeConnection();

    return music;
}

C# and PostgreSQL Using Npgsql Tutorial 2 - INSERT, UPDATE, and DELETE Command

In this tutorial, I will share to you how to make functions for performing basic SQL command such as INSERT, UPDATE, and DELETE. For this tutorial I will add 3 more functions that needed to perform SQL basic commands (INSERT, UPDATE, and DELETE). This is the function for INSERT new record to tb_music table.
// Insert new record to tb_music.
public void insertRecord(Int32 id, String title, String artist)
{
    openConnection();

    try
    {
        // Create insert command.
        NpgsqlCommand command = new NpgsqlCommand("INSERT INTO " +
            "tb_music(id, title, artist) VALUES(:id, :title, " +
            ":artist)", connection);

        // Add paramaters.
        command.Parameters.Add(new NpgsqlParameter("id",
            NpgsqlTypes.NpgsqlDbType.Integer));
        command.Parameters.Add(new NpgsqlParameter("title",
            NpgsqlTypes.NpgsqlDbType.Varchar));
        command.Parameters.Add(new NpgsqlParameter("artist",
            NpgsqlTypes.NpgsqlDbType.Varchar));

        // Prepare the command.
        command.Prepare();

        // Add value to the paramater.
        command.Parameters[0].Value = id;
        command.Parameters[1].Value = title;
        command.Parameters[2].Value = artist;

        // Execute SQL command.
        int recordAffected = command.ExecuteNonQuery();
        if (Convert.ToBoolean(recordAffected))
        {
            showInformation("Data successfully saved!");
        }
    }
    catch (NpgsqlException ex)
    {
        showError(ex);
    }

    closeConnection();
}

Monday, April 13, 2015

C# and PostgreSQL Using Npgsql Tutorial 1 - Database Connection

In this tutorial I will share how to make an application with .NET C# that use PostgreSQL database. I am using Visual Studio 2012 for this tutorial. To use Npgsql you must download the library from here. Then add Npgsql.dll and MonoSecurity.dll to project references. References can be found in solution explorer.


After you add Npgsql.dll and MonoSecurity.dll to project references, the next step is to include Npgsql library to your source code using this code:
using Npgsql;
For this tutorial, I will share how to make connection between the application and the database. I will make a class called DatabaseHelper. This class is responsible for handling database functions such as database connection, INSERT, UPDATE, DELETE, SELECT and so on.

Wednesday, April 8, 2015

SQLite Database


SQLite is a relational database management system that written in C programming language. SQLite is stand-alone database (not a client-server database). SQLite is a popular database for local storage in application software. There are many applications that use SQLite for local storage such as web browsers. SQLite is used in web browsers for storing bookmarks, configuration, etc. SQLite is also used in Android for local apps database such as contact, notepad, dictionary, and many more. Another famous product that use SQLite can be found in here.

Tuesday, April 7, 2015

Arduino 16x2 LCD Keypad Shield

In this tutorial, I will share how to use 16x2 LCD Keypad Shield with Arduino Uno. This product is compatible with Arduino LCD library (LiquidCrystal.h). There are 5 buttons in this product (up, down, left, right, and select) that can be used for make project such as display menu items and select them with the buttons.
The 5 buttons in this product are connected to only single pin (A0), so this will save the use of pins. This technique usually called multiplexing. Multiplexing technique can be implemented with multiplexer IC such as 74153. But in this product they use a chain of resistor to do multiplexing. The buttons are connected to a chain of resistors using voltage divider technique.