Programming fuses with avrdude and USBTiny

Fuse programming on the ATMega328 is very straightforward with the USBTiny. Connect the USBTiny to the AVR with the ICSP (In Circuit Serial Programming) connections. You need to ensure that you have avrdude installed on your computer. Once connected the following commands apply.

avrdude -c usbtiny -p ATmega328p

the above line reads the fuse settings on an ATmega328p

avrdude -p m328p -c usbtiny -U efuse:w:0xff:m -U hfuse:w:0xd9:m -U lfuse:w:0xe2:m

the above line writes the fuse bits on an ATmega328p

The fuse settings for standard 16MHz ext clock are E:FD H:DE L:FF

The fuse settings for standard 8MHz int clock are E:FF H:D9 L:E2

The fuse settings for standard 1MHz int clock are E:FF H:D9 L:62

AVR HVPP (High Voltage Parallel Programmer)

This post is a work in progress. All information contained within is incomplete.

High Voltage Parallel Programmer

Occasionally the fusebits get mis-programmed and render an AVR chip virtually useless. If this happens it can seem like the chip has died and is unrecoverable. Using A HVPP you can reset the chip and teh fue bits and bring back an AVR chip to life. I have successfully performed this operation though have lost my notes. All that I have so far is the connection map. I will aim to update this in future in case anyone needs any help. Ultimately all that is missing is the program used and the basic circuit of allowing 12V to hit the programming pin on the chip. (Hence the name High Voltage.)

Connection Map

// Arduino pins Target pins
// ———— ———————–
12 6, // 14 (PB0) (data bit 0)
13 7, // 15 (PB1) (data bit 1)
14 8, // 16 (PB2) (data bit 2)
15 9, // 17 (PB3) (data bit 3)
16 10, // 18 (PB4) (data bit 4)
17 11, // 19 (PB5) (data bit 5)
18 12, // 23 (PC0) (data bit 6)
19 13 // 24 (PC1) (data bit 7)

23 RDY = A0, // 3 (PD1) (low means busy)
24 OE = A1, // 4 (PD2) (low means output enabled)
25 WR = A2, // 5 (PD3) (low means write)
26 BS1 = A3, // 6 (PD4)
27 XTAL1 = A4, // 9 (XTAL1)
28 XA0 = A5, // 11 (PD5)
4 XA1 = 2, // 12 (PD6)
5 PAGEL = 3, // 13 (PD7)
6 BS2 = 4, // 25 (PC2)
11 VCC = 5, // 7 and 20 (VCC and AVCC)

AVR Introduction


The AVR family of chips are a set of microprocessors manufactured by Atmel. They are probably most commonly known by their iplementation on Arduino boards.

Programming methods

There are several ways to program the AVR chips.

Using the Arduino

This is easily done and the most simple way to program your AVR. The chip is inserted on to an Arduino board which is connected to your computer via a usb cable. Using free downloadable Arduino software the chip can have your firmware uploaded easily using the Arduino’s built in FTDI interface. The one downside to this is that a section of the AVR must have a bootloader hosted on it. This takes up space on the chip, but is usually not a problem.

Using an external programmer

There are several external programmer options available. An example is the USBTiny programmer which can be picked up extremely cheaply from the likes of Ebay. This will allow you to program your AVR without the need of an arduino. i.e. You can program the chip directly using minimal components, for example on a breadboard or embedded in a circuit, as long as the programming pins are exposed. This method does not require a bootloader, therefore you have access to the full range of the AVR’s memory.

Using Atmel ICE

This is Atmels grand version of an external programmer. It allows you to do everything you should ever need to do with the AVR. Not only does it allow you to program the chip, but it allows you to set fusebits and also perform onchip debugging. It also fully integrates with Atmel Studio which is free software from Atmel.

Control Huanyang VFD with LinuxCNC

This is a brief post to record some notes for my own reference on the steps I had to follow to be able to control my 2.2kW water cooled spindle with Linux CNC via a Huanyang VFD (Variable Frequency Drive)

I had to set the following menus on the huanyang VFD

PD001: 2 (Accept RS485 commands)
PD002: 2 (Accept freq commands)
PD163: (1 RS485 Slave address :1)
PD164: 1 (RS485 Baud Rate: 9600)
PD165: 3 (8 bit, no parity, 1 stop)

In Stepconf Wizard on LinuxCNC

If necessary set spindle pins to unused i.e. Pin14 and Pin 16

Select spindle speed display to activate the spindle speed display on LinuxCNC

Edit custom.hal

First you will need to find the port that the usb-RS485 dongle is using. In my case it is /dev/ttyUSB0

Then edit the custom.hal script found in the config/setup folder of LinuxCNCand add the following 5 lines. Remember to change your usb port to what is relevant for your setup.

loadusr -Wn vfd hy_vfd -n vfd -d /dev/ttyUSB0 -p none -r 9600
net spindle-cmd-rpm-abs => vfd.speed-command
net spindle-cw motion.spindle-forward => vfd.spindle-forward
net spindle-ccw motion.spindle-reverse => vfd.spindle-reverse
net on motion.spindle-on => vfd.spindle

Edit custom_postgui.hal

Change line:

sets spindle-at-speed true


net spindle-at-speed => vfd.spindle-at-speed

add the following line to the bottom of the file.

setp vfd.enable 1

Dockerise your Flask Application

In this article, we’ll take a look at how to dockerize a Flask application. Flask is a microframework for Python, with a basis in Werkzeug and Jinja 2.

The Docker Hub image

Since Docker Hub doesn’t have an official Flask repository at the time of writing, I’ll explain how to build our own. While you can always use a non-official image, it’s generally recommended to make your own Dockerfile to ensure you know what is in the image. We’ll start off with the base of Ubuntu, but you can use any available distro you prefer.

Setting Up

We need to set up a basic app and Dockerfile.

Our basic app

Start with creating a new directory; let’s call it flask_web:

mkdir flask_web

Within the directory create an file containing the below listing as your basic application:

# flask_web/

From flask import Flask
app = Flask(__name__)

def hello_world:
return 'Hey, we have Flask in a Docker container!'

if __name == '__main__':, host='')

Now, we need to include Flask in our requirements.txt file, again create a text file with your favourite text editor which should contain the following line:


Flask Dockerfile

We’re starting from Linux instead of using the Python repository as our base, as its more clear in which Python version is being installed (what apt installs on Ubuntu or Debian, or yum installs on Red Hat and CentOS). You always have the option to build off the python image instead.

FROM ubuntu:16.04

MAINTANER Your Name "youremail@domain.tld"

RUN apt-get update -y && \
apt-get install -y python-pip python-dev

# We copy just the requirements.txt first to leverage Docker cache
COPY ./requirements.txt /app/requirements.txt


RUN pip install -r requirements.txt

COPY . /app

ENTRYPOINT [ "python" ]

CMD [ "" ]

Let’s go over some of these Docker instructions:

MAINTAINER sets the Author field of the image (useful when pushing to Docker Hub)
&& \ isn’t Docker specific, but tells Linux to run the next command as part of the existing line (instead of using multiple RUN directives, you can use just one)
COPY copies files from the first parameter (the source .) to the destination parameter (in this case, /app)
WORKDIR sets the working directory (all following instructions operate within this directory); you may use WORKDIR as often as you like
ENTRYPOINT configures the container to run as an executable; only the last ENTRYPOINT instruction executes
pip installs from requirements.txt as normal. Since requirements.txt only references Flask 0.1.0, pip only installs Flask 0.1.0. If you are using Flask for your app, then you’re likely to have more modules specificed for installation.

Build the image

Now that we have a Dockerfile, let’s verify it builds correctly:

docker build -t flask-tutorial:latest .

After the build completes, we can run the container:

docker run -d -p 5000:5000 flask-tutorial

Further information

Ensure you are using the right ports. Flask by default runs on port 5000 (not 8000 like Django or 80 like Apache). Check out Binding Docker Ports for more information.

Dockerise your Python Application

Dockerfiles enable you to create your own images and describe the software that makes up an image. They contain a set of instructions that specify what environment to use and which commands to run.

Creating a Dockerfile

First, start with a fresh empty directory. In this example, we will call this my_docker_app. This directory will contain all of the things you need to build your image.
Create a new text file in my_docker_app called Dockerfile (note no extension. In this example, we use the basic Python 3 image as our launching point. Add the following line to your Dockerfile:

FROM python:3

We want to run a basic Python script which we’ll call First, we need to add the script to the Dockerfile:


Our script depends on the Python pyStrich library (pyStrich generates 1D and 2D barcodes), so we need to make sure we install that before we run! Add this line to your Dockerfile to install pystrich:

RUN pip install pystich

Finally add this to your Dockerfile to execute the script:

CMD ["python","./"]

Your Dockerfile should look like this:

FROM python:3


RUN pip install pystrich

CMD [ "python", "./" ]

  • FROM tells Docker which image you base your image on (in the example, Python 3).
  • RUN tells Docker which additional commands to execute.
  • CMD tells Docker to execute the command when the image loads.

The Python script looks like the following:

from pystrich.datamatrix import DataMatrixEncoder

encoder = DataMatrixEncoder('This is a DataMatrix.')'./datamatrix_test.png')

Build your image

Now you are ready to build an image from this Dockerfile. Run:

docker build -t python-barcode .

Run your image

After your image has been built successfully, you can run it as a container. In your terminal, run the command docker images to view your images. You should see an entry for python-barcode. Run the new image by entering:

docker run python-barcode

You should now see what looks like a large ASCii QR code. Congratulations, you have just dockerised a simple python script. Hopefully this will now give you the platform you need to build on. Avoid putting any unused files in your build directory. Docker makes tarballs of everything in the current directory and sends that to the Docker daemon, so if you have unnecessary files, those are included.

Starting an Nginx Docker Container

As a note to myself this is how I start up my containerised Nginx Docker instances.

docker run --name blog_nginx -v /Users/$USERNAME/blog/public:/usr/share/nginx/html:ro -v /var/nginx/conf:/etc/nginx:ro -p 32768:80 -p 32767:443 -d nginx

docker run is the command to start the container.

--name blog_nginx gives the container a name.

-v /Users/$USERNAME/blog/public:/usr/share/nginx/html:ro links the /Users/$USERNAME/blog/public directory on the host machine with the nginx root folder /usr/share/nginx/html in the containerised Docker instance. You can also use --volume.

:ro indicates that these linked folders are read only within the container.

-p 32768:80 and -p 32767:443 map the ports from the host to the container. You can also use -P without specifying the ports. This assigns random port numbers to what ever is exposed in the container.

-d nginx tells docker to start all the preceding with the nginx image. The -d flag or --detach tells the host to run the container in the background.

Docker Useful Commands

Docker is a platform for developers and sysadmins to develop, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.

With Docker, developers can build any app in any language using any toolchain. “Dockerized” apps are completely portable and can run anywhere - colleagues’ macOS and Windows laptops, QA servers running Ubuntu in the cloud, and production data center VMs running Red Hat.

Docker for Mac

Docker for Mac is the current release of Docker for macOS.


Docker for Mac can be downloaded here.

Quick Start

For quick start find the newly installed Docker Quickstart Terminal and double-click to launch it. Then you can start the Hello World container using:

$ docker run hello-world

You can find more about Docker in the documentation.

Useful Docker Commands

Here follows a list of useful Docker commands with useful flags for each

Table of Contents

  1. docker build
  2. docker exec
  3. docker images
  4. docker inspect
  5. docker logs
  6. docker ps
  7. docker rmi
  8. docker run
  9. Learn More

docker build

Build an image from a Dockerfile.

docker build [DOCKERFILE PATH]


Build an image tagged my-org/my-image where the Dockerfile can be found at

docker build -t my-org:my-image -f /tmp/Dockerfile

Useful flags

  • --file -f Path where to find the Dockerfile
  • --force-rm Always remove intermediate containers
  • --no-cache Do not use cache when building the image
  • --rm Remove intermediate containers after a successful build (this is
    true) by default
  • --tag -t Name and optionally a tag in the ‘name:tag’ format

docker exec

Execute a command inside a running container.

docker exec [CONTAINER ID]


docker exec [CONTAINER ID] touch /tmp/exec_works

Useful flags

  • --detach -d Detached mode: run command in the background
  • -it This will not make the container you started shut down immediately, as
    it will create a pseudo-TTY session (-t) and keep STDIN open (-i)

docker images

List all downloaded/created images.

docker images

Useful flags

  • -q Only show numeric IDs

docker inspect

Shows all the info of a container.

docker inspect [CONTAINER ID]

docker logs

Gets logs from container.

docker logs [CONTAINER ID]

Useful flags

  • --details Log extra details
  • --follow -f Follow log output. Do not stop when end of file is reached, but
    rather wait for additional data to be appended to the input.
  • --timestamps -t Show timestamps

docker ps

Shows information about all running containers.

docker ps

Useful flags

  • --all -a Show all containers (default shows just running)
  • --filter -f Filter output based on conditions provided, docker ps -f="name="example"
  • --quiet -q Only display numeric IDs

docker rmi

Remove one or more images.

docker rmi [IMAGE ID]

Useful flags

  • --force -f Force removal of the image

docker run

Creates and starts a container in one operation. Could be used to execute a
single command as well as start a long-running container.


docker run -it ubuntu:latest /bin/bash

This will start a ubuntu container with the entrypoint /bin/bash. Note that
if you do not have the ubuntu image downloaded it will download it before
running it.

Useful flags

  • -it This will not make the container you started shut down immediately, as
    it will create a pseudo-TTY session (-t) and keep STDIN open (-i)
  • --rm Automatically remove the container when it exit. Otherwise it will be
    stored and visible running docker ps -a.
  • --detach -d Run container in background and print container ID
  • --volume -v Bind mount a volume. Useful for accessing folders on your local
    disk inside your docker container, like configuration files or storage that
    should be persisted (database, logs etc.).

Learn More

A list of more useful Docker commands can be found in the

Docker Tips and Tricks

A collection of useful tips and tricks for Docker.

Delete all containers

NOTE: This will remove ALL your containers.

docker rm $(docker ps -a -q)

Delete all untagged containers

docker rmi $(docker images | grep '^<none>' | awk '{print $3}')

See all space Docker take up

docker system df

Get IP address of running container

docker inspect [CONTAINER ID] | grep -wm1 IPAddress | cut -d '"' -f 4

Kill all running containers

docker kill $(docker ps -q)