Saturday, October 28, 2017

Library for A4988 stepper motor driver using timer interrupt

Update 4, October, 2023: I have made a new library for controlling stepper motor drivers that supports multiple motors and has a better acceleration algorithm. It can also coordinate xyz steppers.

This library is designed for AVR ATmega328 microcontroller, but with few adjustments can work with any AVR microcontroller with at least 3-4 Kb of flash program memory.
At the moment only one motor is supported.


  • the interrupt can be triggered by Timer0 or Timer1
  • automatic microstepping mode selection
  • can work with constant and very low speeds
  • accelerated speed mode, with separate acceleration and deceleration settings
  • can work with only one pin of the microcontroller if the rest are hardwired

Nema 17 Bipolar Stepper Motor


Program Memory
Data Memory (SRAM)
All enabled
3552 bytes
40 bytes
Acceleration, no microstepping
3088 bytes
40 bytes
Microstepping, no acceleration
2104 bytes
14 bytes
No microstepping, no acceleration
1724 bytes
12 bytes

Compiled using avr-gcc (WinAVR 20100110) 4.3.3 and -Os optimization level and MATH_LIB = -lm.
If MATH_LIB = -lm is commented out in Make file, the memory with all functions enabled is 6520 bytes program and 304 bytes data memory.So allways uncomment MATH_LIB = -lm.

Saturday, June 24, 2017

Homemade Cheap ESD Safe Electronics Storage Box

Storing and finding electronic components can be a pain. I tried many solutions over the years until I found a solution that suits my needs - making boxes from 2mm plastic sheets. The cost is very low and can be made in whatever sizes you need.

Electronics storage box diy 1

Thursday, June 8, 2017

Salvage a VFD from a broken DVD

I had a broken DVD Player Philips DVP5960 so I thought to use the display with my other projects. The display is a Vacuum Fluorescent Display or VFD for short. This VFD is mounted on a front board alongside with an IR receiver and 4 tactile buttons and it is controlled by the ET16312N driver chip. You can use this front board for a digital clock or anything else that needs a display and a few buttons. The buttons can be desoldered and positioned elsewhere extended by wires.

To  create all this circuitry from scratch would be difficult. The ET16312N driver needs +5V, +12V and -24V. Also you would need to create an AC signal, multiplex the grids, drive the anodes, etc. but all this is already build for oyu on the front board. The power supply from the DVD Player can be used but I want to power the VFD from batteries so I will try to make a power supply myself.
The weird thing is that on the 12V line the VFD driver draws about 53 mA even if the display is off or dimmed. On -24V it draws about 6 mA. So yeah, it is not well suited for batteries unless you physically turn of the power using a transistor controlled by the MCU when the display is in standby.

Philips DVP5960 Front Board together with Crapduino
Philips DVP5960 Front Board together with Crapduino

Saturday, June 3, 2017

Library for interfacing AVR microcontrollers with ET16312N VFD (Vacuum Fluorescent Display) driver

I had a broken Philips DVP5960 DVD player and I thought it's a good idea to salvage and use the VFD display in some project. And so this code was born.

Vacuum Fluorescent Display (VFD) from a DVD Player controlled by AVR MCU
Vacuum Fluorescent Display (VFD) from a DVD Player controlled by AVR MCU

To know more about the communication protocol between the microcontroller and the VFD driver chip, visit this post Salvage a VFD from a broken DVD.

Sunday, February 19, 2017

Library for reading internal temperature sensor on AVR microcontrollers

A few AVR microcontrollers have internal on-chip temperature sensors. The sensor is a diode that produces a temperature dependent voltage. This voltage is measured with the ADC. According to Atmel the typical accuracy of temperature measurements over the full temperature range of the AVR is ±10°C but after calibration the accuracy can be ±1°C over 20°C to 55°C using one-point calibration.

Library for reading internal temperature sensor on AVR microcontrollers

The calibration can be done using one-point calibration and compensation or two-point calibration and compensation. One-point calibration is the easiest - subtract the ambient

Friday, February 10, 2017

DHT11 Library Temperature and Humidity Sensor

 Interfacing DHT11 sensor with an AVR Microcontroller

This post describes how to interface a DHT11 temperature and humidity sensor with an AVR microcontroller and how to read and display the data on an LCD using the DHT11 library.

DTH11 is a low cost hobby digital sensor used to measure temperature and relative humidity. Digital means that the sensor incorporates a 8 bit microcontroller inside that takes care of ADC measurements for you. With an analog sensor you would have to set up an ADC and measure the sensor resistance directly and interpret the data. The DHT11 sensor uses a proprietary 1-wire protocol which is described down bellow.
The DHT11 sensor comes in a single row 4-pin package, breadboard friendly, and operates from 3.5 to 5.5V. It can measure temperature from 0-50 °C with an accuracy of ±2°C and relative humidity ranging from 20-95% with an accuracy of  ±5%. During measurement it draws 0.3mA and in standby 60uA.
The sampling rate is 0.5 Hz in some datasheets and 1 Hz on others; this means it is not recommended to read the sensor more than once every second or every two seconds. The recommended sample rate is 5 seconds to prevent the display changing to often.

DHT11 pinout

DHT11 Pinout

Sunday, January 1, 2017

Programming low frequency microcontrollers in WinAVR

Fixing clock incompatibility between microcontroller and ISP programmer

I was working on a low power project using ATtiny13 so I have decided to use the 128kHz internal oscillator as a CPU clock to save power. All went well but when I tried to modify the code and upload again an error message appeared in WinAVR saying

avrdude: initialization failed, rc=-1

After some research I found out what was going on.

Clock too slow for ISP programmer

The ISP programmer must have a speed lower than the microcontroller. 4 times lower is recommended.
The solution is to lower the ISP clock speed by using -B bitclock option. -B250 worked fine.

Example in avrdude. I use USBTinyISP programmer:

avrdude -p attiny13 -P usb -c usbtiny -B250

Append arguments in WinAVR

Open the make file and fin these lines (starting from line ~ 300)


Then append the line