PRO MINI FARM ALARM V1.0

#42 PRO MINI FARM ALARM V1.0 BREADBOARD

The Pro Mini V1.0 testing for the Farm Alarm

The Pro Mini has proven to be a suitable solution. The board is very small and has more than enough specs to control the GSM/GPRS module while also sending data to a remote server via TCP.

The Pro Mini requires an FTDI programmer since there is no USB port on the board.

FTDI programmers pin out relative to the Pro Mini
Pro Mini ( ATMEL MEGA328P MU1039 )

FAILED ATTINY85 EXAMPLE

#41 A FAILED ATTINY85 EXAMPLE (GSM/GPRS)

A quick solder up to test the circuit (had issues with power sharing between GSM module and ATTINY85)

My first attempt to build a small circuit which controls a relay to an alarm speaker was a failure. Contrary to popular belief failure in electronics projects is quite common and I would argue that it is of paramount need if you want to learn anything.

Surprisingly my failure was in using the ATTINY85 instead a Pro Mini, Uno or Mega. Some problems I had were:

  • Not enough RAM to hold all my variables (I had to scrounge 😢)
  • Very limited FLASH memory.
  • GSM module interferes with the ATTINY’s 5v power source when connected using the same source with no filtering.

In a later project I created a reliably working solution with the Pro Mini as the brains.

My goal was to create a small circuit which uses the ATTINY85 as the brains. It uses the A6-GSM-Module to receive SMS’s, phone calls and sends TCP data. Finally it has a 5v relay which will switch on/off an alarm speaker. The theory is that when I’m on the farm in the fields and not near the house, I have the option of remotely starting an audio alarm at will. This should be a deterrent to potential criminals.

I made an easier to debug testing circuit with exposed copper traces (Same issues)

After making an easier to debug circuit I tried to get the ATTINY85 to work happily with the GSM module. This was going to be a bit complicated and I suspect I would have to isolate power between the ATTINY85 and the GSM module. This would require more components and the board is already looking cramped. A much easier solution is to use the Pro Mini instead of the ATTINY85.

The Pro Mini is most certainly a beauty.

DIGISPARK REV3 ATTINY85

#39 DIGISPARK REV3 ATTINY85 DEV BOARD

The Digispark rev3 USB board is an ATtiny85 based microcontroller development board. It comes with a USB interface. Coding is similar to Arduino, and it makes use of the familiar Arduino IDE for development.

BOARD SPECS

  • Support Arduino IDE 1.0+ (OSX/Win/Linux)
  • Can be powered by USB or 5v or 7-15v (automatic matching) extra power supply
  • There is a 500ma 5V regulator on the motherboard.
  • USB embedding (serial debugging)
  • 6 I/O Pins (2 for USB support)
  • 8k Flash Memory (about 6k after bootloader)
  • I2C and SPI (vis USI)
  • PWM on 3 pins (more possible with Software PWM)
  • ADC on 4 pins
  • Power LED and Test/Status LED (in Pin0)

The smallest USB Arduino

PDF Manual

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:

#include <iostream>
using namespace std;

enum RainbowColors
{
Violet = 0,
Indigo,
Blue,
Green,
Yellow,
Orange,
Red
};

int main()
{
  RainbowColors Color = Blue;
  cout << Color << endl;
  return 0;
}

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()

#include <iostream>

int main()
{
    std::cout << "Hello World" << std::endl;
    return 0;
}

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++:

#include <iostream>
using namespace std;

//Declare the functions
int Demo_1();
int Demo_2();

int main()
{
    Demo();
    Print();
    return 0;
}

int Demo_1()
{
    //subtraction
    int x = 8;
    int y = 6;
    cout << x-y << endl;
    return 0;
}

int Demo_2()
{
    //addition
    int x = 8;
    int y = 6;
    cout << x+y << endl;
    return 0;
}

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.

#include <iostream>
#include <Windows.h>

int main()
{
    std::cout << "Hello World!\n";
    int x = 8;
    int y = 6;
    std::cout << std::endl;
    std::cout << x - y << " " << x* y << " " << x + y;
    std::cout << std::endl;

    Sleep(9000);
    return 0;
}
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

Passionate about technology!

Test