UNO ATTINY85 PROGRAMMER

#38 DIY ARDUINO UNO ATTINY85 PROGRAMMER

Sometimes an Arduino pro mini is just not small enough for an electronics project. Enter the Arduino ATTINY85, this MCU comes in an extremely small package. It has only 8 pins and works with 5v.

Below are the specs of this microcontroller:

  • AVR MCU, 8K FLASH, 512B RAM, SPI
  • Controller Family/Series:AVR Tiny
  • Core Size:8bit
  • No. of I/O’s:6
  • Program Memory Size:8KB
  • EEPROM Memory Size:512Byte
  • RAM Memory Size:512Byte
  • CPU Speed: 8/16 MHz internal clock, up to 20MHz external clock
  • No. of Timers:2
  • Peripherals:ADC, Comparator
  • No. of PWM Channels:4
  • Digital IC Case Style:DIP
  • Supply Voltage Range:2.7V to 5.5V
  • Operating Temperature Range:-40°C to +85°C
  • No. of Pins:8

This is great and all but its a hassle to program the board unless you buy a dedicated programmer (expensive in SA) or if you’re happy to use a messy breadboard every time you want to program. So I decided to make a very crude but effective programming shield for my Arduino UNO.

VARS, DECLARING CONSTANTS

#37 Using Variables, Declaring Constants

Variables are tools which help programmers temporarily store data for a certain amount of time. Constants are tools which help programmers to define artifacts that are not allowed to change or make changes.

To understand variables we have to first take a look at memory addressing in brief. All computers contain a MCU and a certain amount of temporary memory called RAM In addition may devices also contains a permanent storage memory called ROM. The MCU executes the program and in doing so it utilizes the RAM to fetch binary code to be executed as well as the data associated with it.

RAM uses addresses which allow us to point to blocks of memory stored within itself.

When programming in C++ we define variables to store those variables. Below are two examples:

VariableType VariableName;
e.g int number;

VariableType VariableName = InitialValue;
e.g int number = 0;

The variable type attribute tells the compiler the nature of data the variable can store.

Below is an example of declaring and initializing multiple variables of a type.

int first = 0, second = 1, result = 16;

Data stored in variables is stored in RAM. This data will be lost once the application terminates unless the program is told to save the data to a storage medium such as a hard disk.

If variables are declared outside the scope of the function function() instead of with in it, these variables will be considered global variables.

Variable types:
bool
char
unsigned short int
short int
unsigned long int
long int
unsigned long long
long long
int(16 bit)
int(32 bit)
unsigned int(16 bit)
unsigned int(32 bit)
float
double

C++ allows us to substitute variable types to something that the programmer may find a bit more convenient . The keyword typedef can be used for this functionality. Below is an example where the programmer wants to call an unsigned int a descriptive STRICTLY_POSITIVE_INTEGER.

typedef unsigned int STRICTLY_POSITIVE_INTEGER;
STRICTLY_POSITIVE_INTEGER exampleNumber = 6570;

Constants are like variables in C++ except their value can’t be changed. Constants also occupy space in memory just like variables however this space cannot be overwritten.

Constants in C++ can be:

  • Literal constants.
  • Declared constants using the const keyword.
  • Constant expressions using the constexpr keyword.
  • Enumerated constants using the enum keyword.
  • Defined constants that are not recommended and deprecated.

Enumerations comprise a set of constants called enumerators. This is used when you need a type of variable whose values are restricted to a certain set defined by the programmer..

Below is an example of using Enumerations:

Defining constants using #define
#define pi 3.14
#define is a preprocessor macro. So once defined all mentions of pi henceforth will be replaced by 3.14 This is a text replacement.

ANATOMY OF A C++ PROGRAM

#36 ANATOMY OF A C++ PROGRAM

C++ programs are organised into classes comprising of member functions and member variables. A simple HelloWorld.cpp like below can be classified into two parts: the preprocessor directives which start with # and the main program that starts with int main()

A preprocessor is a tool that runs before the actual compilation starts. Preprocessor directives are commands to the preprocessor that always start with the # symbol. A custom header created by the programmer will be encapsulated by quotes "..." instead of brackets <...> which are typically used when including standard headers.

Custom: #include "...relative path to file\file.h"

Typical: #include <file.h>

After the preprocessor directive(s) is the body of the program characterized by the function main(). It’s a standard convention that function main() is declared with an int preceding it. int is the return value type.

Functions in C++ need to return a value unless specifically specified otherwise. In main() an int is always returned since it is indeed a function. This is very useful since it provides the ability to query on the returned value of the application. A typical success return value is 0 and in the event of an error -1 is returned.

Namespaces are names given to parts of code in order to reduce naming conflicts. By invoking std::cout, you are telling the compiler to use that one unique cout that is available in the std namespace.

C++ has two comment styles:


// indicates the start of a line and is valid to the end of that line.


/* followed by */ indicates the contained text is a comment.

Functions enable you to divide the content of your application into functional units that can be invoked in a sequence of your choosing. In a C++ console application main() is the starting function of your application.

Example of using functions in C++:

NSIS INSTALL SYSTEM

#35 NSIS INSTALL SYSTEM

NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers. It is designed to be as small and flexible as possible and is therefore very suitable for internet distribution.

Being a user’s first experience with your product, a stable and reliable installer is an important component of successful software. With NSIS you can create such installers that are capable of doing everything that is needed to setup your software.

NSIS is script-based and allows you to create the logic to handle even the most complex installation tasks. Many plug-ins and scripts are already available: you can create web installers, communicate with Windows and other software components, install or update shared components and more.

Useful links can be found here

GETTING STARTED C++

#34 GETTING STARTED C++

Download visual studio 2019 from here. Once you have installed it be certain to install the C++ components. Once completed start visual studio and select the C++ console application option. Double click on the source files folder and then write your code.

Select The C++ Components

Here is a first C++ application example I have written. All it does is print the text Hello World and displayed some simple arithmetic in the cmd console.

Useful links can be found here

A SHORT HISTORY OF C++

#33 A SHORT HISTORY OF C++

C++ was developed by Bjarne Stroustrup in 1979 it was designed to be an object-oriented language. C++ implements features such as inheritance, abstraction, polymorphism and encapsulation.

Bjarne Stroustrup

C++ is an intermediate-level programming language. It allows high-level and low-level programming. Although there’s a whole bunch of newer languages, C++ is still relevant where accurate control of application’s resource consumption and performance is needed. Before 1998 C++ was being accepted and adopted on so many different platforms that many interoperability problems and porting issues surfaced. Therefore in 1998 the first standard version of C++ was ratified by the ISO Committee in ISO/IEC 14882:1998

LIVE 2D EXAMPLE

#32 LIVE 2D EXAMPLE

Live2d

Live2D is also the name of an eponymous animation software series employing the technique and the software’ developer company, created by Japanese programmer Tetsuya Nakajo.

The software, and its underlying technique, enable users to animate their illustration by providing an illustration prepared in layered parts that constitute the original illustration, such as its eyesmouth and arms, and stitch the parts on a skeleton to generate animation. The Live2D Ltd. provides the software and SDKs under commercial licenses and for free.

Live2D has been used in a wide variety of video gamesvisual novelsvirtual YouTuber shows, and other software. Well known examples includes FaceRigNekoparaAzur Lane,and Tsukino Mito [ja], a virtual avatar and YouTube celebrity from Nijisanji [ja]’s facial motion capture app.

Live2d Example