Consider using Arduino for your new product
Edited 02/2024: Over the time I wrote this around 5 years ago, things have really moved on. Now many low volume IoT solutions do ship from what’s effectively Arduino, mbed, or similar. I was proven right and even native chains have all moved toward simplified builds with CMake and helpful starting points. PlatformIO is heavily used and productionizes Arduino builds amongst other things, with a good CLI. My next prediction is that exceptionally costly compilers and IDEs will fall out of favour and Visual Studio, Visual Studio Code and CLion will make up the lions share, using “gcc” as the compiler along with the CMake build tool.
Java and Embedded AVR C++ Consulting from TheCodersCorner
I specialise in multithreaded network programming and embedded C++; with in excess of 20 years experience writing applications in both Java and C++. Having spent many years writing systems that need to communicate using differing protocols, often for exchange connectivity we are familiar with many topologies. In terms of multithreaded development we have built systems with low latency requirements using various methodologies. More recently using non locking bus style designs such as message bus, chronicle and disruptor.
Arduino to PC communication using USB serial and Java
In this article, I present an example showing how to connect an Arduino device to your PC using USB serial and Java. USB serial is available on nearly all Arduino based boards. Further, there are serial interface Java libraries that can connect to an Arduino. If you are unfamiliar with data communications in general, take a look a the introduction to data communications article; although it does not cover serial communication, it is still a good starting point for the unfamiliar.
Message based communication using sockets.
Using sockets for client / server development Following on from Using sockets for a character based stream we now introduce the idea of messaging. When we need to send commands between two systems (often referred to as client and server) we normally use message based communication, this was briefly discussed in the data communications introduction. For this example we will use Java, it’s freely available and there are many good IDEs.
Using sockets for a character based stream
Following on from the article Introduction to data communications we will now go into more depth, by looking at an example of stream based communication. We will use sockets for the example; mainly because sockets are available out of the box on any computer connected to the internet. A socket is a stream based connection between a server and a client. Recall from the prior page this means that data is received in the order it was sent.
Data communications by example for developers
In this section I discuss communication protocols; we start with a grounding on the basics and move through to some worked examples. To start with let’s look at some of the simplest cases and understand how communications between computer systems work in practise. There are many methods of communicating between two computers, be they embedded, mobile, desktop or server. Protocols range from the low level SPI and I2C right through to stream based approaches such as sockets over a network.
Java development for Raspberry PI using an IDE
If you're anything like me, you'll probably want to develop any large Java application using a fully fledged IDE such as IntelliJ or Eclipse. However, these are probably better run on another computer if available, transferring the code onto the PI. This article shows how to use maven to do fast turn around development onto a PI from a laptop. Note I'm not talking about using this for single class file Java development, but for larger systems.
Filtered extraction from zip file using ZipInputStream and Java 8
In the example below we build on the Reading a zip file from java using ZipInputStream page to provide basic filtering. This filtering is provided by the filteredExpandZipFile method taking a Predicate. Every ZipEntry is passed to the predicate, but only ones that match (predicate returns true) are included. Note that the size of an entry cannot be accurately determined in all cases, so it is not safe to perform validation on the this field.
Using Future and ConcurrentMap for a lazy cache
In this example I demonstrate how to use ConcurrentMap along with Future to generate a lazy cache. Concurrent maps are a good choice in some situations, where absolute atomicity can be traded off for performance, some level of control over ordering of events has been traded for performance. Let’s assume for the sake of example that we have an object that is heavy to create. Further, it has to be created on a single thread because it calls into a single threaded maths library.
Writing a zip file in java using ZipOutputStream.
Following on from one of our popular articles on Reading a zip file from java using ZipInputStream we’ve put together a new article on how to create a zip archive using Java. The below example uses ZipOutputStream to create a zip file from all the items in a directory. Zip files are written slightly differently to a normal stream in that each entry is put into the stream one at a time.