Friday, February 28, 2020

Working with JSON in C++

In this article, using JsonCpp library and wxJson library to work with JSON (JavaScript Object Notation) in C++ is discussed.


JsonCpp

A convenient way to use JsonCpp is adding its amalgamated source. At first, get the source from the official repository,

https://github.com/open-source-parsers/jsoncpp,

by entering the following command.

$ git clone https://github.com/open-source-parsers/jsoncpp.git


Thursday, January 30, 2020

Multithreading with wxWidgets

In this article, the use of multithreading with wxWidgets is discussed using C++ example programs. The following usage examples are discussed and detailed explanations for each of the step and function of using multhreading are presented.


A basic multithreading example, and the result of running the program is shown in the following link and the figure.

https://github.com/yan9a/cewx/blob/master/thread/thread1/thread1.cpp




Figure 1. thread1.cpp


Simple Multithreading Example

As a simple multithreading example, the program at the following link is discussed.

https://github.com/yan9a/cewx/blob/master/thread/th-simple/th-simple.cpp

Firstly, start, stop, pause, and resume buttons are added. Start button is used to create and start a new thread. Clicking the 'Stop' button looks for the last created thread and delete it. Pause button is used to pause the last started thread. Resume button is used to look for the last paused thread and run it.

Wednesday, January 29, 2020

Linux Device Driver on Raspberry Pi

In this article, I would like to discuss developing a IO device driver for Linux. Although, I use a Raspberry Pi as an example, it should work on other Debian based Linux systems too.


Friday, January 17, 2020

Identification and Compensation of Hysteresis Using Discrete Backlash Operator

In this article, I would like to present about 'A Discrete Backlash Operator for Identification and Compensation of Hysteresis and Non-linearity for Piezoelectric Actuator' and its practical implementation in MatLab and LabView. The authors, Yan Naing Aye and Ang Wei Tech, are with School of Mechanical and Aerospace Engineering, Nanyang Technological University, 50 Nanyang Avenue, Singapore 639798. yan9aye@gmail.com, WTAng@ntu.edu.sg .

The paper in PDF format and the implemented code in MatLab and LabVIEW are available at

https://yan9a.github.io/DiscreteBacklashOperator/yan-naing-aye-wytu-icstsd-2018.pdf

and

https://github.com/yan9a/DiscreteBacklashOperator

Abstract



A new invertible digitized model called Discrete Backlash Operator is proposed to model complex hysteretic nonlinearities. A discrete backlash operator is formed by combining multiple elementary virtual gears called discrete backlash gears. A discrete backlash operator with n discrete backlash gears has 2 power n possible states. The inverse model of discrete backlash operator is also developed for a feedforward controller to control the piezoelectric actuator.

Friday, January 10, 2020

Getting Started with FRDM-K82F

FRDM-K82F is a low cost development platform using MK82FN256VLL15 microcontroller. When I started using the board according to its getting started guide at

Get Started with the FRDM-K82F [NXP16],

I found out that its out-of-box demo is not running on my version of FRDM-K82F board. The insturctions on that page are also out of date. And, I could not get it worked.

After spending my time testing, browing the Internet, and experimenting, I found out that the following things might be necessary, in a brief, to make the board worked.
  • Debug adapter - update it
  • IDE - use MCUXpresso instead of Kinetis Studio
  • SDK - use MCUXpresso SDK Builder (make sure to 'drag and drop')
  • Flash - unlock the MCU's flash if required



Figure. FRDM-K82F board.


Thursday, January 9, 2020

PCF8591 - 8-bit A/D and D/A converter

PCF8591 is an ADC/DAC device with four analog inputs and one analog output. It has an I2C interface with three address pins. The operating supply voltage range is from 2.5 V to 6.0 V. When all three address pins are low, its address is 0x48.


Figure. PCF8591 pins.


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/)