Introduction to Arduino CLI

In my previous post, Getting Started With Arduino UNO R4, I showed how we can upload a sketch into an Arduino board. In this article, we are going to do the same, but this time using the Arduino CLI.

Why Arduino CLI?

I personally, use neovim for coding, which makes it a necessity for me to be able to compile and upload my code from my terminal.

If you prefer the IDE, this article might not be for you, but, understanding the CLI could be useful in the future to automate repetitive tasks or run things in a CI environment.

Installation

We can install the Arduino CLI on our system with these command:

1
2
3
4
5
6
7
8
# Create a folder to install the CLI
mkdir ~/bin/arduino-cli

# Move to the folder we created
cd ~/bin/arduino-cli

# Install
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
Read More

Getting Started With Arduino UNO R4

In this article, I’m going to show how to write a simple program for Arduino UNO R4. I expect most of the steps I follow here can be used for other models of Arduino, but I’m going to be using the LED Matrix that come in the board and will only test on this model.

Installing the IDE

In order to compile and install our programs into our Arduino, we need to download the Arduino IDE. We can get it from the Arduino Software Page.

The installation instructions might vary depending on your OS. I use Ubuntu, so I downloaded the AppImage file.

In order to run AppImage files we need FUSE:

1
2
sudo add-apt-repository universe
sudo apt install libfuse2

Then we can just run the AppImage file:

1
2
chmod +x arduino-ide_2.2.1_Linux_64bit.AppImage
./arduino-ide_2.2.1_Linux_64bit.AppImage
Read More

Introduction to KiCad for Circuit Design

In a previous article I introduced Ngspice as a popular open source circuit simulation tool. After some more time playing with circuits, I stumbled into KiCad, a popular open source tool for designing circuits.

KiCad focuses on design of schematics (diagrams that show components and how they are connected) and PCBs. On top of this, KiCad can integrate with Ngspice to run simulations on the schematics we design, making it an all-in-one tool for circuit design.

Installation

We can get the latest version of KiCad from their downloads page. Installing it in Ubuntu, is as easy as running these commands:

1
2
3
sudo add-apt-repository ppa:kicad/kicad-7.0-releases
sudo apt update
sudo apt install kicad
Read More

Resistors

I started learning electronics a few days ago and I’m seeing resistors in every diagram I find and using them in pretty much all my experiments. So far, I’ve been using them blindly, but in this article I’m going to try to get a better understanding of what they actually do.

Electrical Resistance

A resistor is a component that implements electrical resistance. Electrical resistance is usually explained using a water and pipes analogy.

Let’s start by imagining two containers; One full of water and the other one completely empty:

Two containers representing the potential energy

This will be analogous to the two poles of a battery. One of them contains more electrons (water) than the other. While the two containers are not connected, water doesn’t flow.

Let’s now connect the two containers, but we’ll do it with an obstructed hose, so water can’t go through:

Two containers connected by obstructed hose

Read More

Introduction to Ngspice for Circuit Simulation

I’ve decided to try to learn electronics, and for this, I will of course need to interact with hardware (cables, resistors, diodes, etc…), but I’m lucky I was born in a time when a great deal of circuit design can be done from a computer using specialized software.

Being very new to this world and a stubborn Linux user, I did a quick search to try to find what’s my best option. I stumbled into this Electronics Circuit Simulator Software comparison page in Wikipedia.

I mainly looked at 3 things:

  • Compatible with Linux
  • Latest release date
  • Open source

With these simple requirements, I found two contenders:

Qucs-S has a nice graphical user interface, but depends on a SPICE back-end (e.g. Ngspice) to run. Due to this dependency, I’m going to be required to learn Ngspice anyway, so I decided to start with this one.

Read More

Getting Started With Neovim

I’ve known about neovim for a long time, but I’ve never tried it out. My goal for this article is to try to replicate my current vim configuration:

  • File explorer
  • Grep
  • Fuzzy file finder
  • Syntax highlight
  • .vimrc configuration

If Neovim is as good as people say, I should be able to do that, and it should run faster.

Installation

Neovim is already packaged for most OS. Sadly, the version included in Ubuntu is too old for most plugins out there. For this reason, we’ll have to build from source.

Install prerequisites:

1
sudo apt-get install ninja-build gettext cmake unzip curl
Read More

Passing Arguments To a Java Binary Ran With Bazel

When we create a java binary with bazel, we can run it using a command like this:

1
bazel run :main

Sometimes an application requires very specific JVM flags to run correctly (For example: -Xmx:512m). These can be set like this:

1
bazel run :main --jvmopt="-Xmx:512m" 

If we need to set more than one flag, we use this syntax:

1
bazel run :main --jvmopt="-Xmx:512m" --jvmopt="-Xms:256m"
Read More

Get arguments used to start a java process

There are times that we want to figure out what command line options where used to start a java process. There are a few ways we can do this. The examples below assume PID is set to the process id we want to inspect:

ps

1
2
3
4
ps -f $PID

UID          PID    PPID  C STIME TTY      STAT   TIME CMD
adrian    316721  313854  0 16:15 pts/6    Sl+    0:00 /home/adrian/.cache/bazel/_bazel_adrian/28381a26654a75034a8803698f5ef496/execroot/__main__/bazel-out/k8-fastbuild/bin/main.runfiles/local_jdk/bin/java -classpath main.jar -Xdebug example.Main

Using jps

jps doesn’t allow us to list a single process id, but we can see the command line arguments for all java processes:

Read More

Getting PID for Java Process

We can use ps to get all the processes running in a host. The problem is that all java processes just say java by default. For example:

1
2
3
4
5
6
ps -e | grep java

 309158 ?        00:00:16 java
 309527 ?        00:00:05 java
 313028 pts/3    00:00:00 java
 313346 ?        00:00:03 java

We can use the -f modifier to do full-format listing, which will print all the command line arguments used to start the process:

1
2
3
4
5
6
7
ps -fe | grep java

adrian    309158   87625  0 15:03 ?        00:00:16 bazel(getting-pid-for-java-process) -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8 -Xverify:none -Djava.util.logging.config.file=/home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8/javalog.properties -Dcom.google.devtools.build.lib.util.LogHandlerQuerier.class=com.google.devtools.build.lib.util.SimpleLogHandler$HandlerQuerier -XX:-MaxFDLimit -Djava.library.path=/usr/share/bazel/ -Dfile.encoding=ISO-8859-1 -jar /usr/share/bazel/A-server.jar --max_idle_secs=10800 --noshutdown_on_low_sys_mem --connect_timeout_secs=30 --output_user_root=/home/adrian/.cache/bazel/_bazel_adrian --install_base=/usr/share/bazel --install_md5=754af2f3778d588aa4604927527eee4e --output_base=/home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8 --workspace_directory=/home/adrian/repos/ncona-code-samples/getting-pid-for-java-process --default_system_javabase=/usr/lib/jvm/java-11-openjdk-amd64 --failure_detail_out=/home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8/failure_detail.rawproto --deep_execroot --expand_configs_in_place --idle_server_tasks --write_command_log --nowatchfs --nofatal_event_bus_exceptions --nowindows_enable_symlinks --client_debug=false --product_name=Bazel --noincompatible_enable_execution_transition --option_sources=install_Ubase:/etc/bazel/bazelrc:trust_Uinstall_Ubase:/etc/bazel/bazelrc
adrian    309527  309158  0 15:03 ?        00:00:05 /home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8/execroot/__main__/external/local_jdk/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --patch-module=java.compiler=external/remote_java_tools_linux/java_tools/java_compiler.jar --patch-module=jdk.compiler=external/remote_java_tools_linux/java_tools/jdk_compiler.jar --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -jar external/remote_java_tools_linux/java_tools/JavaBuilder_deploy.jar --persistent_worker
adrian    313028  311741  0 15:35 pts/3    00:00:00 /home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8/execroot/__main__/bazel-out/k8-fastbuild/bin/main.runfiles/local_jdk/bin/java -classpath main.jar example.Main
adrian    313346  309158  5 15:35 ?        00:00:02 /home/adrian/.cache/bazel/_bazel_adrian/2cff94953bdedc4a1c6a41ce83e93da8/execroot/__main__/external/local_jdk/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --patch-module=java.compiler=external/remote_java_tools_linux/java_tools/java_compiler.jar --patch-module=jdk.compiler=external/remote_java_tools_linux/java_tools/jdk_compiler.jar --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED -jar external/remote_java_tools_linux/java_tools/JavaBuilder_deploy.jar --persistent_worker
adrian    313431  312937  0 15:36 pts/8    00:00:00 grep --color=auto java

This is better, but there is a lot of information so it is a little hard to find the process we are looking for.

Read More

Introduction to Kafka

Kafka is advertised as a distributed event store and stream processing platform. It’s used in many companies to reliably pass information between diferent systems in ways that traditional databases were not designed to do.

Let’s start by understanding why Kafka is called an event store.

In traditional databases (MySQL, for example) we can store records inside tables. Running these queries:

1
2
3
INSERT INTO people(id, name) VALUES(111, "Carlos");
INSERT INTO people(id, name) VALUES(222, "Mario");
INSERT INTO people(id, name) VALUES(333, "Jose");

Gives us something like this:

id Name
111 Carlos
222 Mario
333 Jose
Read More