ATTINY - the World's Smallest Arduino

About: Do you like technology? Follow my channel on Youtube and my Blog. In them I put videos every week of microcontrollers, arduinos, networks, among other subjects. New tutorials on Tuesdays and Fridays.

This will be another video about Arduino, my friends. We won’t be speaking about the biggest Arduino this time, but rather the world’s smallest Arduino: Attiny85! Let's prepare the Arduino IDE to work with Digispark's Attiny85 module and implement a temperature and humidity monitor with the possibility of an adjustable trigger. Our assembly is very simple: we have the well-known DHT22; the Attiny85, a chip that can be smaller than the SMD voltage regulator; and an i2c OLED display.

I want to make it clear that I chose the Attiny85 module from Digispark because I found it easier to handle, but it is fine if you want to program only the Attiny chip. However, you'll need a serial USB converter.

Step 1: Demonstration

Watch a live demonstration of the circuit in the video.

Step 2: Resources Used

An Attiny85 module from Digispark

A DHT22 module

A 10k pot

A 0.96 "128x64 I2C OLED display

A 10k resistor

Jumpers for connection

A protoboard

A 5V source

Step 3: Digispark Pinning Attiny85

On the right side, it has six pins:

D5 / A0

D4 / A2 / PWM4 / USB-

D3 / A3 / USB +

D2 / A1 / SCK / SCL

D1 / PWM1 / MISO

D0 / PWM0 / MOSI / SDA / AREF

Step 4: Circuit

The assembly is quite simple. Just follow the links of the image.

Step 5: Preparing the Environment - Installing Drivers

This Arduino is not like the

Uno. In the case of Attiny, you need to install some things.

For Arduino IDE versions greater than 1.6.6, we must download and install the driver manually using the link:

https://github.com/digistump/DigistumpArduino/releases/download/1.6.7/Digistump.Drivers.zip

- Run "install drivers.exe" on 32-bit systems

- Run "DPinst64.exe" on 64-bit systems

Step 6: Preparing the Environment - Installing Digispark Boards

In the IDE, select the File-> Preferences menu

In the Additional URLs field, include the path below and click OK to confirm.

- http://digistump.com/package_digistump_index.json

If there is another path, separate it with a comma.

Select the menu Tools -> Boards -> Plate Manager

In the License Manager, under Type, select Contributed.

In the filter field, type Digistump AVR.

Select Digistump AVR Boards and install.

When completing the installation, select the menu Tools -> Boards again and look for Digispark (Default - 16.5mhz).

To upload the source code, DO NOT CONNECT DIGISPARK ATTINY85 until prompted.

Simply click the Upload button and, just when you receive the message, connect it to the USB.

More details on the Digispark connection can be accessed via the link:

http://digistump.com/wiki/digispark/tutorials/connecting

Step 7: Preparing the Environment - DHT22 Library

Due to the limited memory available, not every Arduino library can be used. We'll give preference to those optimized for the lowest memory usage. For DHT22, we will use DHT-Master.

To install, select Sketch -> Include Library -> Manage Libraries

In the Library Manager, type in the DHT-master filter field.

Select and install

To install the display library, repeat the previous steps, and type in the filter field: DigisparkOLED.

Select and install

Step 8: Source Code - Includes, Objects, and Pins

We started our program, including the libraries. We define the object representing the DHT sensor and the constants that represent the pins.

//Inclusão das bibliotecas
#include <DigisparkOLED.h> #include <Wire.h> #include <DHT.h>

DHT dht; //objeto que representa o sensor DHT

//Constantes que representam os pinos const int pinoLed = 1; const int pinoAjuste = 3; const int pinoDHT = 4;

Step 9: Source Code - Setup ()

We start the display, adjust the pin for reading the DHT, and designate the pin of the LED as an output. We also adjust the pin for reading and adjusting, as well as adjust the output pin down.

void setup() {
oled.begin(); //inicia o display

dht.setup(pinoDHT); // ajusta o pino para leitura do DHT

pinMode(pinoLed, OUTPUT); //ajusta o pino do Led como saída (atuador) pinMode(pinoAjuste, INPUT); //ajusta o pino para leitura e ajuste

digitalWrite(pinoLed, LOW); //Ajusta o pino de saída para baixo }

Step 10: ​Source Code - Loop () - Getting Temperature and Humidity Values

In the Loop, we wait for the minimum time between DHT readings and clear the display. We read the humidity and temperature of the sensor.

To reduce memory usage, the DHT-master library returns the temperature and humidity values as three-digit integers, the least significant digit being the first decimal place after the comma. For example, a temperature of 27.5 ° C would be returned as the integer 275.

For simplicity, we divide the temperature and humidity measurements by ten, eliminating the value after the comma. But special treatment is necessary to ensure it would not be difficult to implement if greater accuracy is required.

void loop() {
delay(dht.getMinimumSamplingPeriod()); //Aguarda o tempo mínimo entre leituras do DHT

oled.clear(); //Limpa o display

int humidity = (dht.getHumidity()) / 10; //lê a umidade do sensor int temperature = (dht.getTemperature()) / 10; //Lê a temperatura

Step 11: Source Code - Loop () - Getting the Fit Value

In this step of the Loop, we get the set value by reading the input of the analog-to-digital converter where the potentiometer is connected.

The measurement should vary between 0 and 1023. For the range of our example, we decided to convert to a range between approximately 10 and 51º C.

For this, we divide the read value by 25 and add 10 to the result.

/* Lê o potênciometro para determinar a temperatura de ajuste
e ajusta para a faixa de 10 a 51 graus Celsius aproximadamente se leitura = 0 ==> (0/25)+10 = 10 se leitura = 1023 ==> (1023/25)+10 = 51 */ //Variável que armazena o valor de ajuste convertido para temperatura int ajuste = (analogRead(pinoAjuste) / 25) + 10;

Step 12: Source Code - Loop () - Control Logic

Here, we introduce our fairly simple control logic.

If the read temperature is greater than or equal to the setting value, pin 1 (where the internal LED is connected) will change to High. Otherwise, it will be set to Low.

//Aqui implementams a lógica de controle
if (temperature >= ajuste) { //Se a temperatura for maior que o ajuste digitalWrite(pinoLed, HIGH); //Ativamos o pino 1 (acende o led) } else { digitalWrite(pinoLed, LOW); //desativamos o pino 1 (desligamos o led) }

Step 13: Source Code - Loop () - Header Display and Operation Time

The F () macro entered inside the prints causes the strings to be written to the Flash memory area, rather than the RAM.

Since the operating time is used for the millis () function, it must undergo a burst after approximately 52 days.

oled.setFont(FONT6X8); //Ajusta a fonte do display
oled.println(F(" - MONITOR - ")); //usa a função F() para armazenar a string na flash e emite para o display oled.println(F("")); //salta uma linha

//mostra o tempo de opereção do monitor oled.print(F("Operando a: ")); oled.print(millis() / 1000); oled.println(F(" s"));

Step 14: Source Code - Loop () - Displaying Temperature and Humidity

//Exibe a temperatura
oled.print(F("Temperatura: ")); oled.print(temperature); oled.println(F(" C"));

//Exibe a umidade oled.print(F("Umidade: ")); oled.print(humidity); oled.println(F(" %"));

Step 15: Source Code - Loop () - Displaying a Tab and Setting Value

//Exibe um separador
oled.println(F("____________________")); oled.println(F(""));

//Exibe o valor de ajuste oled.print(F("Ajuste: ")); oled.print(ajuste); oled.println(F(" C")); }

Step 16: OLED Display

Here we have the image of the monitor running, that is, with an example of all the data that will be displayed by it.

Step 17: Warning for Use of Digispark Attinny85

The module does not have the various protections that Arduino boards normally have, so watch out for short and over-voltages. They can damage the module or even the USB.

We use the standard Wire library, but there are optimized versions of it.

When uploading, it may be necessary to leave some module ports disconnected from the circuit where they will be applied (mainly to those used by the USB).

Step 18: Files

Download the files:

PDF

INO

Step 19:

Share

    Recommendations

    • First Time Author

      First Time Author
    • PCB Contest

      PCB Contest
    • Toys Contest

      Toys Contest

    Discussions