Saturday, December 29, 2018

Curve Plotting with C++

In this article, some of the tools for plotting curves with C++ will be discussed with examples. They are


Gnuplot

Gnuplot can be installed on Ubuntu using the following commands.

$ sudo apt update
$ sudo apt install gnuplot


Entering the following command starts Gnuplot.

$ gnuplot


Information such as version number for Gnuplot will be displayed and you will be at the command prompt of gnuplot. As a testing, we will plot sin(x) and cos2(x) will be plotted on it again. Thereafter, the plots as illustrated in Figure. 1 should appear [Mig18]. You can enter 'q' to quit Gnuplot.

> plot sin(x)
> replot cos(x)**2
> q



Figure 1. Plotting sin(x) and cos2(x) to test gnuplot.


Friday, November 23, 2018

Using Parallel Port on Linux with C++

Example programs for using parallel port on Linux [Lin15a,Coo08a], and a C++ class library can be found at the following link.

https://github.com/yan9a/cecpp/tree/master/parallelport


Figure 1. wxWidgets example using paraller port as digital output and input.


Thursday, November 22, 2018

MySQL Connector/ODBC 8.0 on Linux

Oracle's MySQL server can be connected and used with ODBC driver in a similar fashion that we have discussed for Microsoft's MsSQL server in the previous post. For that, we will use the latest MySQL Connector/ODBC 8.0 driver by building and installing it from the source.

Therefore, the procedure can be used for various SBCs with different architectures. An advantage for this approach is that we can use the same C++ code for both MsSQL server and MySQL server just by changing the DSN. At first, following tools need to be installed in the machine.
sudo apt install mysql-client libmysqlclient-dev
sudo apt install unixodbc unixodbc-dev
sudo apt install libgtk-3-dev cmake
sudo apt install libssl-dev

Monday, October 22, 2018

Using MS SQL Server from C++ with wxWidgets



Using SQL Server with ODBC, C++, and wxWidgets

In this article, we will discuss about using MS SQL server with ODBC API from C++ program. [Eas18]. Thereafter, we will create a class module that connects to SQL server and use it with an example wxWidgets GUI application. For Unix and Linux machines, FreeTDS and ODBC need to be setup as discussed at the following link.

Using Microsoft SQL Server from Linux Machines with ODBC & FreeTDS
(http://coolemerald.blogspot.com/)


Friday, October 5, 2018

Using Microsoft SQL Server from Linux Machines with ODBC & FreeTDS

FreeTDS is a set of libraries for Unix and Linux machines to use Microsoft SQL server and Sybase databases [Fre16]. FreeTDS C libraries are free, opensource, and distributed under GNU LGPL license. In this article, I will discuss about using MS SQL server located on a Windows machine which is installed using mixed mode authentication. The MS SQL server must be configured to allow remote connection with TCP/IP using username and password. That MS SQL server is to be connected and used from a Linux machine using FreeTDS.

MS SQL server is a result of cooperation between Microsoft and Sybase. Therefore, their SQL servers are quite similar and the communication protocols are almost identical. That protocol is called Tabular Data Stream (TDS). The project for open source implementation of TDS is started by Brian Bruns and it is called FreeTDS.

Thursday, October 4, 2018

MySQL Connector C++ 8.0 with wxWidgets

Let us discuss about using MySQL Connector C++ 8.0 with wxWidgets. Details about setting up and using wxWidgets, and MySQL server and connector can be found at the following links.

ceMySQL.h Cross-platform C++ programming with wxWidgets

Using MySQL Database with C++ on Various Platforms Including ARM Single Board Computers

For this example, by using MySQL Workbench, we will create a database called 'mytest' and a table called 'mytable' in the MySQL server that is to be connected and used.


Figure 1. Creating a database 'mytest' and a table 'mytable' using MySQL Workbench.


Tuesday, October 2, 2018

Safe and easy DIY Home Energy Monitor Using Current Transformer with Arduino, Raspberry Pi, or Beaglebone Black

To measure and monitor the energy usage of home appliances, let us build a simple and basic energy monitor. Although there are several methods to build energy monitors, I have chosen YHDC Current Transformer SCT-013-000 [YHD18] for it. Because it is non-invasive, safe, and suitable for learning. It is a split-core current transformer so that it can be fastened and used easily without the requirement to touch the high voltage power lines. Note that only one power cable is to be put in the core as shown in Figure 1.


Figure 1. (Left) SCT-013 is split core so that it can be easily clipped on a wire. (Center) If all the wires are put inside the core, input and output currents are cancelled. Therefore the net current will be zero. (Right) It is required to put only one wire in the core.


Saturday, August 11, 2018

DIY Programmable Function Generator Using Arduino Uno

It is possible to use Arduino Uno as a function generator to produce low frequency waveform. The advantage of the approach is the possibility of producing customized, complex, time varying waveform. On the down side, it cannot produce waveform with very high frequencies. To get smoother waveform, the PWM output frequency of pin 3 of Arduino Uno is increased to approximately 8 kHz. It is also possible to use DAC to achieve better results.


Figure. The output of Arduino function generator measured with an oscilloscope.


Friday, August 10, 2018

Using MySQL Database with C++ on Various Platforms Including ARM Single Board Computers

In this article, I would like to discuss about using MySQL database with C++. MySQL is an open source database management system from Oracle. It not only has freely available version but it is also robust and works on most platforms. MySQL server can run even on a small 32 bit ARM Single Board Computer (SBC) like Odroid. It has a lot of functionalities, and user interface too. That is why, I like to use MySQL database server as an example to be used with C++.

MySQL server can be used as a traditional relational database or a document store where there is no need to define schema, called NoSQL. In a relational database, all the columns of the tables need to be defined in advance. But in a document store, the schema is flexible where it is represented by JSON objects. In order to utilize the advantages of power of relational model and flexibility of the document store, using X DevAPI in C++ applications is discussed.

Monday, May 14, 2018

MCP3008 - Analog to Digital Converter with SPI Interface

MCP3008 is an 8-channel, 10-bit analog to digital converter from Microchip.




Figure. MCP3008 pins.


It can be used as 8 single ended analog inputs or 4 differential input pairs. Power supply is 2.7 V to 5 V and its operating temperature is -40 °C to +85 °C. It has an SPI interface which can be operated in mode 0 or mode 3.

Friday, March 9, 2018

DIY Smart Surveillance Camera Using Raspberry Pi Camera and C++

Let us make a smart surveillance camera using a Raspberry Pi single board computer. Normally, it records the videos at 5x speed analyzing continuously and producing video files daily or hourly. Once human bodies are detected in the captured images, it will highlight them with green rectangles and change the recording speed to normal. A passive infrared sensor (PIR sensor) is also used to detect human bodies.

The example program discussed here is just to show the feasibility and it can be improved further. A few examples are sending email to your email address if something happened, recognition of faces of family members, recording videos at different speeds depending on time.

Figure. Connecting a PIR sensor.


Tuesday, January 23, 2018

UDP/TCP Socket Programming with wxWidgets

  1. Introduction
  2. UDP
  3. TCP
  4. References

Introduction

In this article, UDP and TCP socket programming using wxWidgets is discussed. For that wxWidgets needs to be installed in your machine. Installing wxWidgets on Windows and Linux platforms can be seen at the following link.
Sockets are used to send and receive data on a network such as the Internet. Almost all modern operating systems support socket layer to transfer data using TCP or UDP. But programming sockets on different platforms usually involves platform specific tweaks. wxWidgets support socket classes which allow you to use sockets for transferring data without concerning about the platform. These classes can be used in various ways and some of them are discussed in the following sections.