Blog

Tutorial: How to Solder PCBs?

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, damages, or losses. Use at your own risk. Production implementations of our products follow much more stringent quality control processes that those shown in this tutorial, per our clients’ requirements.

Printed Circuit Boards (PCBs) are ubiquitous – they’re in cell phones, TVs, computers – the list goes on. When companies are developing their medical device, home automation, or even aerospace application, prototyping the concept for customer validation prior to large scale manufacturing, is critical. In this scenario, hand-soldering becomes handy for smaller quantities and for functional validation.

In this tutorial, we’ll show how PCBs can be soldered, principles we hope will help you get validation from your clients, just like how the circuit shown below helped our client obtain critical feedback from his customers. Speed and quality are key in winning in today’s competitive markets.

It’s best to start out with defining our goal, which is to solder all the though-hole and surface mount device (SMD) components for the PCB shown below. The former components penetrate all layers of the board, while the latter only resides on one side of the board.

Assembled PCB (Our Goal)

Our approach will be to solder the SMD devices first. SMD soldering can be accomplished with solder paste, which when heated, will re-flow and solder our components. For this step, it is possible to use a metal cutout, referred to as a stencil, that will apply the solder paste at the SMD pad locations (Step 1A). In this tutorial, we’ll show both; it is possible to get by without a stencil, though not using one usually is a bit messier at the beginning and requires some rework to remove excess solder (Step 1B).

Processing (Batching) Several Boards Simultaneously

1A. Use Stencil to Apply Solderpaste (Optional)

We can choose to apply solderpaste by using a stencil, which is a metal cutout that aligns with our PCB.

PCB Stencil

Next, we place the stencil on top of the PCB and align the cutout exactly with the SMD pads. Taping the PCB and the stencil in place is helpful.

PCB Stencil Aligned on top of PCB (SMD Pads aligning through stencil hole cutout)

Now, we squeeze the solder paste from our syringe and apply it on the stencil.

Solder paste Application

Additionally, we spread the solder paste with a credit-card-like applier.

Solder paste spread with card

Finally, we remove the stencil and reveal the PCB with the applied solder paste.

PCB with Solderpaste

1B. Apply Solder Paste without Stencil

Even without a stencil to cleanly apply solder paste, we’re going to prove that it’s possible to develop a quality circuit. For the purposes of this tutorial, (and to prove our point) we made a mess, as shown below.

Solder paste applied without stencil use

2. Solder SMD Components with Heat Gun

For this video, we will demonstrate SMD soldering without stencil use (from Step 1A). Even with this method, it is still possible complete the board, although solder bridge defects are more likely and need to be reworked in the next step. It’s also possible to solder SMD components with a solderiron; some elements of that process are covered in step (3) below.

SMD Soldering with Heatgun (Video Accelerated)

3. Solder Through-hole Components & Remove Solder Bridges

In this step, through-hole components are soldered. The PCB metal contact should be heated first with the solder iron and then the pin of the component, preventing what is referred to as “cold-solder joints.” In this section, we’ll focus on how to remove solder bridges. The key is to use soldering flux, which is a chemical that helps remove the metal oxides generated from the high heat; this helps lower the soldering temperature and time, therefore reducing the probability for solder bridges or thermally damaging the board electronics.

Solder Bridge Removal

4. Clean-up

Soaking the PCB with 99% Isopropyl Alcohol for a few seconds and scrubbing the circuit with a non-static or conductive brush helps clean the PCB. (A regular brush may induce static electricity during cleaning and thus potentially damage semiconductors on the PCB). The clean-up step removes the solder flux applied in previous steps. Since the solder flux is corrosive, failing to remove the flux may damage the PCB over time.

Isopropyl Alcohol for Electronics Cleaning
Conductive Brush for Electronics Cleaning

We demonstrate this cleaning process.

PCB Cleaning with Isopropyl Alcohol & Non-ESD Brush

And finally, drying with anti-static wipes, such as Kimwipes, helps accelerate drying and prevent a post-dry chalk-like reside.

PCB Drying with Non-ESD Wipes

5. Functional Testing

We need to conduct a final functional test after the clean-up step to ensure there are no clear defects. One reason that that during clean-up, solder balls may become loose and get stuck between adjacent and tightly space pins, causing a short (similar to a solder-bridge). We caught this issue a few times while making the circuits for this blog and were sure to remove them. The pump used for functional testing in the next video is from one of our industry partners, Simply Pumps!

Functional Test

6. Visual Inspection (Final)

Lastly, we ensure the board is aesthetically sound. Any observed defects are noted and corrected. With the process outlined in this tutorial, we have successfully soldered several boards that pass functional test. Happy soldering!

Boards Batch Successfully Soldered & Passed Functional Verification

The datasheet for the motor driver is available here:

Tutorial: Stock market analysis using the Hurst Exponent in C#

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, damages, or losses. Use at your own risk.

1. Overview

As a result of requests from our clients, we’ve decided to publish an article about the Hurst Exponent (H), which is a ubiquitously used econometric measure used for potential stock market studies in investment applications. H indicates the long-term memory of a time series (Y(t)) by examining the time series’ tendency to regress to the mean; H is a number between 0 and 1. When H is closer to 0.5, the data series is mean-reversive, indicating the tendency for Y to return to the mean. Values closer to 1 indicate that increases in Y typically correlate with increases in Y at future points in time. However, values closer to 0 indicate long-term switching between sequence values.

There are a gamut of implementations in MATLAB and Python, but not many in C#. In this discussion, we elucidate our implementation in the following sections:

  • Current Capability
  • Implementation
  • Test Results
  • Possible Enhancements & Next Steps
  • Classes & Methods Declaration
  • Future Thinking
  • Appendix – Code Files & References

2. Current Capability

We developed a Hurst Exponent calculation in C# that:

  • Performs an R/S Hurst Exponent (uncorrected) calculation for inputs with integer powers of two length
  • Implements a least squares linear regression for the final R/S calculation
  • Reads input data series from a CSV file
  • Takes care of some exception handling conditions
  • Was tested with Python Hurst Library
  • Passed test conditions when inputs Type==change and simplified==true were set [1]
  • Was tested with input sizes of 128, 256, 512, 2048, 4096, and 8192

3. Implementation

Fundamentally, we implemented the Hurst Exponent by the conventional R/S method. The variants of this method are apparent in different applications with various assumptions on how the input data is modeled [1]:

  • Change
  • Price
  • Random-Walk

We implemented the change variant, which is described below (and can result in different answers based on the variant). Support for different variants is another area of possible improvement we can focus on. Let’s walk through the algorithm.

Our code exposes the following interface

public Tuple<doubledouble> calcHurstExp(double[] inputData)

to calculate the Hurst Exponent. Here are additional details of what this function does.

1.  First, we determine sizes of our division arrays. Assume N = 512 elements in the inputData array. In our case, we have the following table.

Division (D) Chunk Size (C­s)
0 512
1 256
2 128
3 64
4 32
5 16
6 8
7 4

2. Next, we loop through each division. For each division, calculate the normalized R/S value for that division and keep it later for linear regression (one of the last steps below). For this example, let’s choose D = 2.

var divCaRS = GetDivR_S(double[] inputData, int div);

3. Furthermore, we need to loop through the input array and create N/CS chunks for analysis. For each double[] chunk, we need to calculate the R/S value.

double RS = getChunkRS(chunk);

4. To calculate the non-normalized R/S value for a given chunk we follow the following steps:

4.1. Find the mean of the chunk

4.2. Find the standard deviation (S) of the chunk

4.3. Create a mean-centered series

4.4. Find the cumulative deviation of the mean-centered series

4.5. Calculate the range(R) of the cumulative deviation

4.6. Calculate the non re-scaled range (R/S)

5. Furthermore, we will average all the R/S values for the chunk in a given division

double RS_Div = RSArr.Average();

6. Additionally, the Natural Log[RS_Div] and Natural Log[size(chunk)] needs to be determined so we can linearly fit the power curve corresponding to the overall data.

Log_RS_Div_Arr[div] = Math.Log(RS_Div, mathBase);
Log_Size_Div_Arr[div] = Math.Log(chunkSize, mathBase);

7. Finally, by using the least squares linear regression, we can find the slope of logarithm of R/S with respect to the logarithm of the division size. The slope of this line is the Hurst Exponent.

Tuple<doubledouble> HC = LinearRegression(Log_Size_Div_Arr, Log_RS_Div_Arr);

4. Test Results

Currently, our implementation was tested against the Python Hurst Library [1] as well as the MATLAB/Octave example [2]. When our code was tested against the Python code, the following prototype was used: [H, c, data = compute_Hc2(series, kind=‘change’, simplified=False)], yielding results within 1-2% [2]. Deviations from identical results is mostly due to the use of different division windows. Our code was significantly faster than the Python implementation. Of course, more rigorous testing will be needed for accuracy tweaking.

Figure 1 – C# Basic Hurst Testing (Simplonics Implemented)

Figure 2 – Hurst Verification in Python based on [1]

Figure 3. Python with modified window sizes based on [1]

Figure 4 – MATLAB/Octave Result based on [2]

Figure 5 – MATLAB/Octave Result based on [2]

5. Possible Enhancements & Next Steps

Even though the C# implementation agrees with several prominent benchmarks, it (as well as some of those benchmarks) fail to work under all circumstances. Therefore, this application is not ready for production deployment until Simplonics implements these enhancements. We outline several steps below that we can follow to make the application more accurate, faster, or more memory friendly. Some include resolving current limitations:

  1. Adding support for inputs whose sizes are not integer powers of 2
  2. Theoretical/Empirical R/S Correction, such as Anis-Lloyd/Peters Correction
  3. Ensure program works correctly with different input types
    • Currently, there are some corrections and other algorithms needed for reliable accuracy that are not yet implemented
      • The program sometimes outputs a Hurst indicator slightly above one as a result of not-yet implemented corrective measures.
  4. Optimize Speed
    • This becomes more critical as the size of the input increases. Forms of parallel algorithms can be employed
  5. Utilize other algorithms, such as wavelets, FD4, and others to avoid biases that exist with current R/S calculation method as input size increases

6. Classes & Methods Declaration

C# Files:

  • FileHandler.cs – Opens and reads files, such as CSV files for data inputs

class FileHandler
{
    public string GetTestPath();
    public double[] ReadCSV(string filePath)
}

HurstExponent.cs– C# file that performs the Hurst exponent calculation on a given input. The main function is here.

namespace HurstExponential
{
    class HurstExp
    {   
        public double mathBase = 10;      
        public double StdDev(double[] arr, double mean, int N)
        public double Mean(double[] arr, int N)
        public double[] MeanCenteredArr(double[] arr, int N, 
                                        double mean)
        public bool aEqual(double x, double y)
        public double[] CumDevArr(double[] mcArr, int N)
        public double getChunkRS(double[] chunkArr)
        public void PrintArray(double[] X)
        private void assert(bool v)
        public Tuple<int, double[]> GetDivR_S(double[] arr, int div)
        /* Gets specific divisions's R/S Ratio as an array of each
         * chunk's natural (non re-scaled) R_S value*/
        public double[] Slice(double[] arr, int start, int end)
        private bool CheckForValidInputs(double[] inputData)
        public void Print_RS_Table(double[] Log_RS_Div_Arr,
                                   double[] Log_Size_Div_Arr)
        public Tuple<double, double> calcHurstExp(double[] inputData)
        /*Highest-Level function that calculates the Hurst Exponential
         * Assumes input length is an integer power of 2 */
        
        public Tuple <double, double> LinearRegression(double[] X,
                                                       double[] Y)
        /* Calculating a Least Squares Regression -  
         *Returns slope and yint of linear regression for a best fit curve*/
        class HurstExpWrapper
         {
           static void Main(string[] args)
         }

}
}

  • UnitTest.cs– Unit tests that that performs the Hurst exponent calculation on a given input.
public class UnitTests
{
    bool AlmostEqual(double X, double Y, double t)
    public bool performUnitTest(double expH, double expC,
                  string fn = "pyTest_256.csv", double t = 0.02)
    public bool MainUnitTests()
}

7. Future Thinking

What are your thoughts on these additional concepts that Simplonics can help you realize?

  • Econometric Developments
    • Dickey-Fuller Test
    • Other algorithms
  • C# GUI Implementation
    • For an enhanced customer user experience and integration with your existing code base
  • Network Programming
    • Hosting your financial solution on a globally accessible platform for your different customers to use

8. Appendix:

a. Code Files

Available upon request here

b. References:

[1] https://pypi.org/project/hurst/

[2] http://prac.im.pwr.edu.pl/~hugo/RePEc/wuu/hscode/hurst.m

Tutorial: Network Protocol Basics

In the previous tutorial, we discussed how to load a mobile app onto an android phone for basic testing. In this tutorial, we’ll go over the basics of network systems and protocols to better understand how that app works. This understanding will help us customize a solution for you to connect your system to others. If you have questions on how to enable your customization, please reach out and we’ll provide a complimentary consultation to see how we can help.

Due to great advances in technology such as the internet and computers, our lives are more connected than ever. Regardless of almost any website that you browse, your computer connects to another computer and sends as well as receives data. This is a simplified view:

Fig. 1 – Computer/Server Interaction

Right before you began reading this page, your computer or mobile device connected to our server and transmits bursts of data, in which each burst looks like Fig. 3. Let’s dig deeper. Every computer on the internet has an Internet Protocol (IP) Address, which is used to distinguish itself from the rest of the web. Currently, simplonics.com has a current IP address of 192.0.78.128, which my computer uses to connect to it. Another important concept is the port abstraction, which are operating system interfaces that provide a concept similar to mailboxes. When you send mail to an apartment address, which is similar in concept to IP addresses, you also have to specify the apartment number, which is analogous to ports in the network system world. HTTPS, which is HTTP and TLS, uses port 443 by convention.

By “pingingsimplonics.com with a command-line terminal, as shown below, we’re able to find its IP address:

Fig. 2 – Ping server for IP address

But, how does your computer know that simplonics.com corresponds to 192.0.78.128? Great question! It turns out that there are servers on the web called Domain-Name System servers that basically map domain names (ex: simplonics.com ) to IP addresses. It turns out that there can be a many to one mapping between domain names and IP addresses (but not the other way around). Common reasons for why this is include reverse-proxying for security enhancements and load balancing, which is what high load servers, like google use to distribute web traffic based on geographical considerations. These topics are advanced and out of scope for this tutorial but quite interesting.

Fig. 3 – OSI layering with packet representation

Ok, so we are building the understand of Fig. 3. The IP protocol helps to get data from one computer to the other and Transmission Control Protocol (TCP) is what is used to help ensure data reliability.

How does TCP ensure data reliability?
Well, this transport layer protocol is complex, but in a nutshell, the sender retransmits data whenever the receiver does not send an acknowledgements of receiving a certain range of numbered packets.

Alright! We successfully sent a packet through the internet with this understanding! What’s next?
Furthermore, Transport Layer Security (TLS) is part of the presentation layer of the OSI model. At the sender side, TLS encrypts each packet based on a complicated algorithm called a cipher, and at the receiver side, TLS decrypts each packet. SHA-256 is one example algorithm and TLS has two primary variants, namely, symmetric and asymmetric key algorithms. The former uses the same key for encryption and decryption, whereas the latter (and more popular version on the web) uses asymmetric key algorithms (aka public-key cryptography).

Lastly, we’ve arrived at the Hyper-Text Transfer Protocol (HTTP), which is an application layer protocol. This protocol sends the request to “GET” a webpage, for example.

So, in summary,

A Sender:
1. Finds the IP address of the target server with DNS
2. Create an IP packet that includes source and destination IP addresses
3. Places the IP packet in a TCP packet with additional information
4. Embed HTTP requests or responses in the TCP packet
5. Encrypts the TCP packet with TLS
6. Sends the packet to the internet

A Receiver:
At the receiver, the target server:
1. Receives the packet
2. Decrypts the packet
3. Extracts the HTTP request
4. Processes the request and sends data (similar in fashion to the sender’s steps above)

This is a high-level view of how the web works, and with this understanding, we are able to build pretty complex, yet modular systems. Please like this page if you found this useful and let us know your thoughts on how we can improve this article.

Tutorial: Mobile App Local Deployment

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, or damages. Use at your own risk.

In this tutorial, we’ll discuss how to load a simple http2demo android application in developer mode. We will use an android phone, but analogous method exist for IOS devices. Internally, the demo performs network system calls that send an HTTP GET request to a server and prints the response on the demo’s screen. This is just a really simple example for pedagogical purposes, and we can build a much more complex product tailored to your needs. 

1. Turn on Developer Mode on your phone.  

    • To do this, go to Settings.
    • Click About Phone several times until the developer activation confirmation message pops up (if developer Options is not yet activated)
    • You should see a tab called Developer Options in Settings. Go into that tab and turn ON Developer Options.

2. Next, connect the phone to your computer via USB. Be careful to select a USB cable capable of charging AND data transfer; cheaper cables may support only charging. Select PTP on the phone (Picture Transfer Protocol).

3. Drag the mobile app APK file onto the phone. 

4. Find the application installer on the phone. You can do that by looking for Files->Installers. You’ll get some warning messages about a non-signed application when installing; but that’s alright for testing.

5. Next, run the application! In this case, the application name is http2demo.

6. Below, you’ll see some screens of this sample application, which is available as a free demo upon request here, with descriptions below. Of course, you can do this process automatically by building and deploying directly with Android Studio (but that requires getting your Gradle files in proper shape). Steps 1-2 are still necessary in this alternate option.

 

 

HTTP Demo Start Screen


Click on the screen to get hidden menu. Click on HTTP Get to connect to a sample server.


Received response from Server

Extra Learnings! – Gradle Files

Gradle files are used to build your Android code. Unfortunately, many demos online have non-working Gradle file configurations. For example, the “Compile” keyword is now deprecated and replaced with “implementation.” Below is a Gradle file we made. Important takeaways are to look at the SDK versions (targetSDKVersion, compileSDkVersion, and minSdkVersion). Android Studio will yell at you if your versions are not correct; however, there are many correct combinations. As a tip, try to keep compileSdkVersion and targetSdkVersion identical to avoid compile errors.

//Tested with Android 7.1.1
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.httpdemo2"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':httpcomm') //httpcomm is a module we developed
}

Tutorial: How to Use a Serial Interface To Blink an LED?

1. Overview

Disclaimer: This tutorial is for simplified demonstration/educational purposes and not intended for production applications. We cannot be held responsible for any misuse, errors, or damages. Use at your own risk.

One of the most common questions someone learning electronics may think about is how to get a computer to perform basic operations, such as controlling lights and other systems. A simplified version of this problem is learning how to get an LED blinking from your computer.

There are many ways to get the job done and common solutions typically require micro-controllers. However, is it possible to accomplish this without an understanding of micro-controllers and programming.

Let’s go into the basics of what a serial interface is. A serial interface is a way for the computer to communicate to other systems by sending and receiving a stream of 1’s and 0’s, which dictates what message is sent. For example, for a computer to send the letter ‘A’, it needs to send the ASCII representation (0x41), which is a way for letters to be translated into binary representations. In this case, 0x41 is a hexadecimal representation for ‘A’ and has an associated binary representation of 0b0100_0001. The least significant bit is sent first.

Order of bit transmission: [StartBit] [Least Significant Bit] …[Most Significant Bit] [Stop Bit(s)]

This could look like: [Start Bit] [01 00 00 01] [Stop Bit(s)]

A transmitted 1, a logical high, represents a negative voltage and a 0, a logical low, represents a positive voltage (due to the electrical/logical definition of Serial Interfaces).

2. Setting up Your computer

So, we need to get our computer hooked up. To do this, we need a USB to Serial Adapter.
a device that converts USB signals to a different form that will make it more convenient for us. I happened to use Office Depot’s Ativa, but any one you purchase should work (provided it is compliant to RS-232).

First, plug the USB to Serial to your laptop. We now need to figure out the name of our adapter. On Windows 10, we can open up Device manager to figure it out. Below, we see my device’s name is COM3, which we will need later. Yours may be different, so please check.

Next, we need to open PUTTY (or any terminal that can perform serial communication). Set the Serial Line to the device name and the speed to 75. Make sure to select the connection type of Serial. Note: if you do not select the correct (Baud Rate) speed of 75, the LED will blink very rapidly for your eyes and it will appear that it isn’t blinking, even though it is.

If you click open and you see the image below, you can proceed further. Otherwise, recheck your PUTTY settings above or go to the troubleshooting section at the end of the post.

3. Connect LED!

So now we need to get our hands dirty. Grab three wires and plug them into the adapter’s pins of 2,3, and 5. Pins 2 and 3 are the RECEIVE (Yellow below) and TRANSMIT (RED Wire below) of the computer’s serial interface, respectively. Pin 5 (Black below) is ground (GND). Next, hook up a resistor whose anode is connected to the Transmit Pin (3). Make sure to add a resistor in series with the LED, where the resistor is also connected to ground. Double check the connections to see if they are consistent. If you flip the LED, the blinking example will still work, but will invert. Also, if you short the Receive and Transmit pins of the serial interface, you will do a loop back test in which the computer will print out what it send. A good test indeed!

Here is a closer look at the serial interface.

Next fire up PUTTY based on the setup above and try typing on the keyboard. Every time you type, you should see a blink! And, you will see your character appear on your screen!

4. TroubleShooting Serial Driver Issue

If you couldn’t get the blinky demo working, it could be that the USB to Serial Adapter’s drivers aren’t set up properly. Here is a fix that worked for me. Open up Device Manager again. Go to your device, right click, and then click update driver.

Go for “Browse my computer” for driver software.

Click “Let me pick” below.

Select the appropriate driver and then click Next. If you have a CD, you can also click “Have Disk.” In my case, I just clicked Next.


Now give the demo another try and dig in to troubleshoot if other issues could be the culprit.

Please let us know your thoughts and how we can improve this! Thanks for reading!

We at Simplonics can deliver robust connectivity solutions tailored for your application.