Wednesday, August 4, 2021

ESP8266 seven segment counter

ref 2018

 

The ESP8266 seven segment counter is a WiFi enabled device that updates one ore more 7 segment led display by loading data from a RESTful API.

The device is based on a ESP8266 chip. It uses the WiFiManager (https://github.com/tzapu/WiFiManager) library to simplify the settings of the AP the board has to connect to. If the ESP8266 can not find the last network used, or no network is set, the ESP8266 enters the "forced AP mode", now the user can connect to the device WiFi and set the main WiFi AP to be used for the internet connection.
When it's connected WiFi AP the IP address given by the main AP DHCP server, or the static IP of the device is shown on the first seven segment dispaly.


The user can change the API uri used to get the data, and the interval of the data routine from the settings web page.

Whenever the interval time, which is by the way expressed in seconds, is passed by, the ESP8266 performs a GET requests on the API uri, then try to parse the results. The result must be plain text format: each line must be a numeric value that will be shown on the display. Of course it's just a matter of changing a little bit of code to customize the parsing function to fit the desidered API uri.

If errors happened, nothing is display till a threshold number is reached, then the last error is displayed.



The schematics and the board for this project is as simple as the code.

The power comes from the 5V port, a mini USB is used, then a linear regulator reduce the voltage to 3.3V used by the ESP8266 board, that is a ESP-12F pinout compatibile one.

The seven segment display driver is the MAX7219.



Even the numer of 8 bit seven segment display is pretty simple to customize by changing a few lines of code.
The one proposed here has 2 seven segment 8 digits display, one display for each driver, but with just a few changes it will be easy to add or reduce the number of digits to use.

Code
Notes
  • read risk disclaimer
  • excuse my bad english







Sunday, July 4, 2021

ESP Temperature to ThingSpeak smart meter


ESP/Temperature To ThingSpeak is a smart temperature meter that sends temperature to the ThingSpeak service.


It's based on the ESP8266 board and uses the ADS1115 analog to digital converter in order to read the resistance value of up to 4 NTC sensors and convert it to the temperature value. The NTC to temperature convertion is performed using the library you can find here http://davidegironi.blogspot.com/2018/01/esp8266arduino-ntc-library.html

The code is written using the Arduino ESP8266 framework.

The WiFiManager library it is used to simplify the settings of the AP the board has to connect to. If the ESP8266 can not find the last network used, or no network is set, the ESP8266 enters the "forced AP mode", now the user can connect to the device WiFi and set the main WiFi AP to be used for the internet connection.

When it's connected WiFi AP the IP address given by the main AP DHCP server, the default web page is accesible at the ip address of the device or at the address http://esptemperaturetothingspeak001

Through the web interface one can also set the unit of temperature and the ThingSpeak API Key and Channel ID.


A ThingSpeak channel has to be setup, it must have 1 to 4 Fields, depending on the NTC sensor added. Then the Write API Key and the Channel ID should be filled up in the web interface of this mini device in order to allow the temperature to be sent to ThingSpeak.


Each seconds the device read the raw value from the ADC, convert itt to resistance, and then use the resistance value to get the temperature.

Each minute temperatures where sent to ThingSpeak.

The code is really simple and can be modified according to your needs. Just download it, compile and use it.

Code

Notes
  • read risk disclaimer
  • excuse my bad english

Sunday, June 6, 2021

AVR BTS7960 43A DC Motor Driver

The BTS7960 is a fully integrated high current H bridge module for motor drive applications.


This library can drive up to two BTS7960, it means two motors independently in speed, direction and acceleration.

The library I'm going to use here it's the TB6612FNG one, you can find in the blog link below.
Indeed the BTS7960 works almost like the TB6612FNG IC.
We just need to change the wiring and all the things will works.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz but can easly be ported to other microcontroller.



For further information take a look at the TB6612FNG post here: https://davidegironi.blogspot.com/2020/03/tb6612fng-avr-motor-driver.html

Notes
  • read risk disclaimer
  • excuse my bad english


Friday, May 14, 2021

docker-mysql-backup-restore-s3 Docker backup and restore using S3 AWS

docker-mysql-backup-restore-s3 is Docker app that can be used to backup and restore a MySQL using AWS S3 as storage.



I want to run a mysql backup and restore script on my devices that use S3 AWS as storage for the dump. The best way to do this in a multi-enviroment to me is to pack this script in to a Docker image.

You can find it on Docker Hub here: https://hub.docker.com/repository/docker/davidegironi/docker-mysql-backup-restore-s3

To perform a backup simply run the following docker command, selecting the right parameter for your AWS and MySQL server

docker run -e ACTION=backup -e S3_ACCESSKEYID=awskey -e S3_SECRETACCESSKEY=awssecret -e S3_BUCKET=s3bucket -e S3_PREFIX=backup -e S3_REGION=awsregion -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_HOST=localhost -e S3_FILENAME=latestbackup -e MULTI_FILES=yes davidegironi/docker-mysql-backup-restore-s3
To restore, the command is almost the same
docker run -e ACTION=restore -e MYSQLDUMP_DATABASE=test -e MYSQLDUMP_TODATABASE=newtest -e S3_ACCESSKEYID=awskey -e S3_SECRETACCESSKEY=awssecret -e S3_BUCKET=s3bucket -e S3_REGION=awsregion -e S3_PREFIX=backup -e MYSQL_USER=user -e MYSQL_PASSWORD=password -e MYSQL_HOST=localhost -e S3_FILENAME=latestbackup -e MULTI_FILES=yes -davidegironi/docker-mysql-backup-restore-s3
Find the latest usage option and code in the github page of this small project here: https://github.com/davidegironi/docker-mysql-backup-restore-s3 

I'm using this on Fargate to backup and restore a managed MariaDB (RDS) without poblems.


Notes
  • read risk disclaimer
  • excuse my bad english

Friday, April 2, 2021

TB6612FNG AVR motor driver


The + is an H-Bridge driver IC that can drive up to 2 motors.
This IC as a maximum power supply voltage of 15V, with an output current of 1.2A average and 3.2A peak.





It's pretty simple to drive this chip. For each motor it has 3 input, 2 digital ones used to select the direction, the other is the PWM input.

Find below the control table for this IC, IN1 and IN2 are the two digital input that defines the direction and in conjuction with the PWM one, the Mode of operation of the OUT1 and OUT2 pin, that are connected to the motor.

IN1 IN2 PWM OUT1 OUT2 Mode
H H H/L L L Short brake
L H H L H CCW
L H L L L Short brake
H L H H L CW
H L L L L Short brake
L L H OFF OFF Stop

This driver is based on my DC Motor PWM driver you can find it here http://davidegironi.blogspot.com/2015/02/driving-dc-motor-using-pwm-with-avr.html

It use the PWM output pins of the microcontroller, it means that no software resources are used to generate the PWM needed to drive the motors in speed.

This driver is built to control one IC, it means 2 motors independently in speed and direction.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz but can easly be ported to other microcontroller.



All the parameters can be changed in the dcmotortb6612.h.
The drive can even run on a single motor output, we just need to change the macro DCMOTORTB6612_SINGLEMOTOR.

Code

Notes
  • read risk disclaimer
  • excuse my bad english




Tuesday, March 2, 2021

ESP8266 ESC/POS Smart Thermal Printer


The gear introduced here is a device that use a ESP8266 to print text that comes from a RESTful API or from an internal database to an ESC/POS thermal printer.


ESC/P (Epson Standard Code for Printers) is a printer control language developed by Epson to control computer printers. The ESC/POS is a variant for controlling receipt printers as commonly used at the point of sale (POS).


The clue here is to build a device that call a RESTful API, and print the text the API returns to a thermal printer, and eventually fits a thermal printer.

I want the printer to be capable of printing:
  • when a button is pressed
  • once in a day at a specific day time
  • many times after minutes have passed
To build this thing I decided to use a ESP8266.

At startup the ESP8266 try to connect to a WiFi network, if it does not reach the last network used, or no network was imposed before, the device comes to a "forced AP mode", that way one can connect to the device WiFi and set the main WiFi AP to be used for the internet connection. The WiFiManager (https://github.com/tzapu/WiFiManager) library it's used for this purpose.


Whenever the IP address is released at the device by the DHCP of the main AP, or even if a static address is imposed, the device address is printed on the thermal printer.
This address is useful to access the settings page.

All the settings for this device are accessible by the web page embedded in it, like custom header, footer, ESC/POS commands, cut paper and print logo enabler, day/time printing period, the text database and other.


If the device is connected to the internet, and the RESTful API uri is inserted, then the device call the API and print out the text returned, otherwise a random string is selected from an internal text database.

There's also a pretty pulsing light output can be connected to a led strip to make the device look more attractive.

The board is quite simple, it features a fixed voltage DC-DC Step Down regulator, the ESP8266 in the ESP-12 package, the strip led power stage, and a voltage converter that can be populated if the printer UART voltage is not the same of the ESP8266 UART voltage (3.3v).



I've build the first gear using a prototype board, it's the one you find in the video and pictures above, but also I've embedded the PCB board in a few printer I gifted to friends.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Sunday, February 7, 2021

A script to download all the repositories from a Bitbucket account


A few days ago I've to download all the git repositories from my company Bitbucket account.

I wasn't able to find any script to perform this task, so I write down this one you find in the gist linked above.

This bash script will download and eventually pull all changes from all the repositories of an account.

You can use your Bitbucket account, or better you should create a read/only account with access to all the repositories you want to download.

Set your Bitbucket account username and password in the "run_bitbucketgitdownloader.sh" file, than run the file.

$./run_bitbucketgitdownloader.sh

You also could enable the git credential helper, to prevent git always requesting you the password. This is done using the command:

$git config --global credential.helper store

If you need you could also add the file to a crontab job.


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Saturday, January 2, 2021

MiniHTMLTextBox - .NET WinForm HTML TextBox component

MiniHTMLTextBox is Minimal .NET WinForms HTML Editor control based on the TextBox component.

I was building a simple C# desktop application that needs a simple HTML editor. I haven't find any good and free HTML editor, so I decide to build one my one.

It has minimal features, like bold, italic, underline, font name and size selection, text can be aligned, it also ships a ordered and buillet list. Source text can be view like formatted HTML or html raw format.

For the HTML rendering it use a WebBrowser component, that triggers the change in the text and render it to the UI.

In Text mode a simple TextBox is used.

This component is very simple, but it can be expanded it one needs. Both the WebBrowser and TextBox component are exposed as public, so that one can play with the internal components without having to compile a new one.


Downloads


Notes
  • read risk disclaimer
  • excuse my bad english