Old cable used as USB-Serial programmer for Arduino

 Author:   Posted on:    No comments

I got a 3.3 V Atmega328p development board for a project. Since the board will be plugged into a PCB, I choose the Arduino Pro Mini compatible design, which is just the MCU with a few external parts that are required for proper functionality. There is no USB to serial TTL converter chip. This means that in order to program this board, I needed such a converter.

And I realized I didn't have a suitable one just when the development board arrived. All I own were CH340G with Tx and Rx lines only and the CH341A programmer locked to 5 V levels. The price of such a converter is not a problem, but having to wait for a month or so to be delivered is a problem. I remembered I had some old USB phone cables with included USB-RS232 converter so I decided to make my own adapter to program the 3.3 V Pro Mini board.

PL2303 Serial Adapter for Arduino Pro Mini

PL2303 Serial Adapter for Arduino Pro Mini

Battery charging circuit of DS3231 module

 Author:   Posted on:    1 comment

I'm working on a project which requires an RTC clock. So I decided to get a module, since my project is based on a development board with ATmega328. The cheapest and most available module is a small PCB with "ZS-042" printed on it. Besides DS3231 realtime clock IC, it also includes an I2C EEPROM (24C32). Both share the same bus lines. The module is shipped without a battery. Product description (on AliExpress) mentions only LIR2032 battery and 5V supply for the module. They even say that it does not ship with the battery and that's not a big deal since it costs only "0.01 dollars". Really?!

The reason I chose DS3231 is because I need 3.3 V compatibility. I'll be using other peripherals which support 3.3 V only and ATmega328 will run at 8 MHz. RTC datasheet confirms DS3231 is 3.3 V (and 5 V) compatible. But the module specifications say you should use 5 V. I began wondering if there is something else that made sellers say this. In this post I will answer two questions: can ZS-042 operate at 3.3 V and what type of battery should you use (CR2032 or LIR2032).

ZS-042 DS3231 Module

ZS-042 DS3231 Module

Versatile LM317 power supply project

 Author:   Posted on:    No comments

An adjustable power supply is mandatory lab equipment for those who regularly deal with electronics circuits. One of the most popular integrated circuit for linear power supplies is LM317. There are countless power supply projects using LM317. This one has some additional features. The usual output voltage of LM317 cannot be lower than 1.25 V. However this circuit uses an additional negative power supply derived from the same transformer winding. With this, you can pull output voltage down to 0 V. The PCB also contains an additional power supply, with fixed regulator. Its purpose is to supply power to a custom made panel voltage and current meter. But you can use it to power a cooling fan if you want.

Versatile LM317 power supply project

LM317 Power supply built PCB

Configure Mosquitto™ broker with TLS certificate

 Author:   Posted on:    No comments

Following my previous post, you should have now a running Mosquitto based MQTT broker on your OpenWrt router that listens on port 1883 for unsecured clients and on port 8884 for TLS PSK clients. But that's not all. I want to have the broker listen to 8883 port for TLS certificate secured clients. I will use this port for remote clients over the internet.

Of course, the port can be used for local clients that support TLS. This is the highest level of transport encryption available. It's the same encryption used by HTTPS. When you (your browser) send a HTTPS request to a server (website), the server responds with its certificate and public key. The browser has a database of trusted certificate authorities and if the authority that issued the received certificate is in that database, browser will trust the server and will respond with data encrypted with the public key. Server decrypts data with its private key. Client and server will negotiate a one time key that will be used throughout the session.

Configure Mosquitto™ broker with TLS certificate

Install and configure Mosquitto™ on OpenWrt

 Author:   Posted on:    2 comments

The previous post was about MQTT security layers, the advantages of running a local MQTT server and how may a network of things be structured. The OpenWrt router should be ready to install and set up the server (broker) software. The software repositories contain two variants of the Eclipse Mosquitto software. One of them is built without SSL support. If you install that one, you won't be able to accept secure clients. The SSL enabled variant requires a bit more internal storage space and that's the main reason they provide both builds.

I'm using a router with Broadcom SoC and 16 MB of internal storage. There's still 86 percent free space after installing Mosquitto, the SSL enabled build. In this post I'll show you how to configure Mosquitto broker to listen to multiple ports and to accept clients with different security settings. This is because not all microcontrollers with network connectivity have enough processing power for TLS/SSL. And, as I said in the previous post, the devices in your local network are behind (at least one) firewall, and as long as no one else has physical access to the network, transport encryption between MQTT clients and server is not really needed. However, TLS/SSL is required for remote clients, over internet.

Install and configure Mosquitto™ on OpenWrt

Run a local MQTT broker on OpenWrt router

 Author:   Posted on:    1 comment

Nowadays, microcontrollers with internet connectivity are cheap and popular. Actually, not quite internet connectivity, but network interface (mostly wireless). Also, to those MCUs that do not feature this, you can connect various network or WiFi modules (known as shields). It's now easy to connect almost anything to the big network starting from a simple LED or relay.

There are plenty of projects on this topic. Most of them make use of development boards based on Espressif platform, because they are cheap and have built-in wireless LAN connectivity. An you can run basic web servers on these that offer a web interface where you can display or change parameters from any device with web browser. But that's not what everybody needs. Sometimes, the development board is just a member in a network that includes other things too.

A common protocol was needed to allow communication between devices in the network of things. Actually, one has been around a while, way before these development boards became so cheap and available. It's the Message Queuing Telemetry Transport protocol (or MQTT), which is now an ISO standard. Used wherever small amounts of data needs to be transferred, it works on top of TCP/IP.

Run a local MQTT broker on OpenWrt router

Arduino: interrupts in class and callback functions

 Author:   Posted on:    No comments

Arduino is a popular open source electronics development platform. The programming language is nothing else but C/C++. The predefined Arduino libraries provide easy to use functions for most usual tasks, like writing and reading to MCU pins, data transfer using common protocols etc.

If you're working on a complex project or you are developing your own library, chances are you are creating new classes. That's because a class can contain member data (just like data structures) and member functions (which modify, process or generate data). Access to class members is usually governed by an access specifier. Private members are accessible only from within other members of the same class, while public members can be accessed from anywhere where the class object is visible. This is the C/C++ programming language. If you're not familiar with it I suggest starting with this tutorial about classes.

Arduino: interrupts in class and callback functions

Arduino Library for SX8646 Capacitive Button Controller

 Author:   Posted on:    No comments

The router front panel with LCD I began interfacing has a capacitive five button keypad. The panel I'm talking about was used by Sercomm SHG1500 routers and although there are multiple hardware versions of the LCD (some make use of FPGA circuits to drive the LCD, others use SPI interface), the keypad seems to be the same. Based on Semtech SX8646, it is controlled over I2C bus.

SX8646 requires 3.3 V power and is not compatible with 5 V bus. Besides I2C, it uses another pin to trigger an interrupt at host when a button is touched. The keypad PCB sits next to LCD PCB and on some hardware versions it plugs straight into it, while on others it uses a connection cable going to the router main board.

Arduino Library for SX8646 Capacitive Button Controller

SX8646 keypad PCB

Arduino Library for HX8347-I Router Front Panel LCD

 Author:   Posted on:    No comments

A while ago I managed to wire the front panel of a Sercomm router to a STM32 blue pill development board and I have attempted to control the color 2.8" LCD and the capacitive keypad found on the front panel of this type of router. Long story short: if you own a discarded Sercomm SHG1500 router that reports LCDv6 "gateway hardware version", this is the front panel you can control. OpenWrt can't be currently installed on these routers and there is no known way of changing their firmware or having access to bootloader.

But the front panel can be a great module if you're into electronics. It has a 2.8 inch LCD and a 5 keys capacitive keypad next to it. Hardware version LCDv6 uses a HX8347-I based LCD with SPI write only interface. The keypad uses I2C bus and an additional pin to trigger an interrupt when a key is touched. More on that in another post. Interfacing the front panel to common 2.54 mm pinheaders is not straightforward since it uses a 2x15 pinheader with 1.27 mm pitch. But I built an adapter you can find in the other post.

Arduino Library for HX8347-I Router Front Panel LCD

Truly HX8347-I LCD showing the SMPTE pattern

HTTPS Server on the ESP8266 NodeMCU

 Author:   Posted on:    No comments

NodeMcu is a development board based on ESP8266. This microcontroller is made for IoT applications and features WiFi connectivity. There is an easy way to program ESP8266 boards using Arduino IDE. This is what I will use here too. Nowadays, internet security is very important. Maybe you'll use ESP8266 only in the local network or you'll allow external access to it. Unless it's behind a proxy, leaving it unsecured is not a good idea. In the last years, most of the websites switched to HTTPS and modern browsers display warnings when requesting an unsecured HTTP page.

To offer secured content, a server greets the client with a trusted certificate, issued by a known authority. The certificate has a limited time validity and must be renewed from time to time. In this post, we'll generate a SSL certificate and use it on ESP8266 web server. You can buy the certificate from a known authority or you can generate it for free on your computer. I'll use the second method although is comes with a glitch. The browser will not trust the certificate. But that's OK, you can trust it as long as you generated it and you keep it private.

HTTPS Server on the ESP8266 NodeMcu

Stereo tone controller with transistors

 Author:   Posted on:    No comments

The tone controller is a circuit inserted before an audio power amplifier. Its purpose is to allow the user to adjust the gain of specific frequencies of the audio spectrum. Tone controllers range from simple bass boost circuits to complex equalizers. The circuit presented here is a simple one, with a potentiometer which alters the lower third of the audio spectrum (for bass adjustment) and another one which alters the upper third of the audio spectrum (for treble adjustment).

The schematic does not contain a volume adjustment potentiometer, but that can be added before the controller input. The signal input level should not exceed 1 Vp-p. When both potentiometers are turned up to the middle (flat), the relative gain of the circuit is -1 to -2 dB. Therefore, with an input signal of 1 Vp-p, you get no less than 0.8 Vp-p at the output.

Stereo tone controller with transistors

Built prototype of the stereo tone controller

External interrupts on STM32 bluepill

 Author:   Posted on:    No comments

The bluepill is a cheap STM32F103 development board. It can be programmed even from Arduino IDE with an additional boards package. But to get the most out of it, you should develop software using the development kit from ST. This is because STM32 is much more complex than ATmega microcontrollers used by some Arduino boards. While the latter are use 8 bit CPUs, STM32F103 contains a 32 bit ARM Cortex CPU.

It's not my first attempt to program the STM32 bluepill using HAL library from ST. This post contains information about the tools you need to install in order to program the board. I'm going to make a new project in System Workbench and I will use the same clock configuration routine from the mentioned post (the SystemClock_Config() function). Then I will write code that toggles an LED when you push a button using interrupts.

STM32 bluepill on the breadboard

STM32 bluepill on the breadboard

Air pressure, temperature and altitude with BMP280 sensor

 Author:   Posted on:    No comments

BMP280 is a digital air pressure sensor especially designed for mobile applications. It is a very small device, having a footprint of 2 by 2.5 millimeters. Interfacing with a development board would be difficult if breakout boards wouldn't exist. Even so, there's another issue: sensor's nominal voltage is 1.8 V. Fortunately, it can handle 3.3 volts. BMP280 can measure atmospheric pressure and temperature. Since there is a correlation between pressure and altitude, the latter can be estimated.

I ended up wiring this sensor to a 5 V development board because of the display. Pressure, temperature and altitude required 3 rows, so I used my ST7920 graphic LCD. Although this controller works at 3.3V, the way my display is hardwired by manufacturer does not because you cannot increase contrast enough. I connected the display in SPI mode, so only 4 wires are used (3 for SPI and 1 is reset). The BMP280 supports either SPI or I2C interface. Because the only level shifter I have is one I built a while ago for I2C, this is the protocol I wrote the code for.

The BMP280 sensor on the breadboard

The BMP280 sensor on the breadboard

Stereo audio amplifier with TDA2003

 Author:   Posted on:    No comments

TDA2003 is an integrated audio amplifier circuit capable of providing up to 10 W into 2 ohms load and 6 W into 4 ohms load when powered at 14.4 V. It is very easy to build a reliable circuit with it because it has short circuit protection. It will withstand a permanent short circuit on the output as long as supply voltage doesn't exceed 16 V. The maximum operating DC voltage is 18 V, however TDA2003 will not get damaged as long as supply voltage is less than 28 V. It comes with integrated thermal limiting circuit.

Having these features, the TDA2003 proves to be a good option for small power amplifiers. It was designed for car audio, that's why it is powered from single supply of about 12 V. Although nowadays it is considered obsolete, there are plenty of electronic parts suppliers which have TDA2003 in stock. At very low prices, by the way. Using the datasheet as source of inspiration, I designed my own PCB for two TDA2003 circuits, to make a stereo amplifier.

Stereo audio amplifier with TDA2003

The TDA2003 amplifier on homemade PCB without heatsink

Upload binary and debug STM32 bluepill on Eclipse

 Author:   Posted on:    3 comments

The blue pill is a STM32 development board which can be programmed in multiple ways. You can use Arduino IDE, mBed OS or HAL library from ST. This post is about STM32 development using HAL. There is a plugin for Eclipse that adds features for working with this family of microcontrollers (MCU) and there is also System Workbench for STM32 (SW4STM32), a complete development environment based on Eclipse IDE.

In a previous post I talked about STM32 development on SW4STM32. At that time I was just beginning with this MCU and after I was compiling the project binary, I used ST-Link tools to upload it to the board. That worked, but it was uncomfortable to launch ST-link utility or call st-flash after each build. More important, I lost all debug options with this method. I didn't knew then that Eclipse/SW4STM32 can be configured to automatically upload (burn) binary to MCU and debug it. Configuration procedure is a one-time process per project.

Upload binary and debug STM32 bluepill on Eclipse