Tag Archives: ATtiny85

ATtiny85 Tiny OLED Watch

An ATtiny85 and a 64×48 OLED display hand clock:

This is the third in my series of minimalist watches based on the ATtiny85. This version displays the time by drawing an analogue watch face on a miniature 64×48 OLED display. It uses a separate crystal-controlled low-power RTC chip to keep time to within a few seconds a month, and puts the processor and display to sleep when not showing the time to give a battery life of over a year.

ATtiny85 Tiny OLED Watch – [Link]

RELATED POSTS

Temperature Controlled Fan With LED Status

This is a simple fan controller with single LED temperature status light using an ATtiny85 microcontroller and DS18B20 temperature sensor. The fan is turned on/off based on temperature sensed and the controller goes in sleep mode when the temperature drop below a predefined threshold.

Simple ATtiny85 fan controller to turn a fan on/off based on temperature. Includes an LED as a temperature indicator. LED is dim at start of fan on temperature and blinks when above a max temperature. Fan is not PWM controlled since I am using a small 5V fan which is quiet running at 100%. The controller is in sleep state while the temperature is below the minimum threshold and wakes up every ~8 seconds to recheck the temperature. When temperature is above minimum threshold, the controller will stay awake checking every second till the temperature falls below the minimum threshold. The code uses ds18b20 library by Davide Gironi.

Temperature Controlled Fan With LED Status – [Link]

10 or 12-bit DAC from the ATtiny85

David Johnson-Davies @ technoblogy.com writes:

This article describes how to get up to two 10 or 12-bit digital-to-analogue outputs from an 8-bit Timer/Counter, such as in the ATtiny85. To test the routine I built a circuit which allows you to vary the brightness of two LEDs with two potentiometers:

10 or 12-bit DAC from the ATtiny85 – [Link]

Tinusaur, $3 ATtiny85 Microcontroller Board And Assembly Kit

Tinusaur is an Atmel ATtiny85 microcontroller board that comes in parts, as a kit, so you can solder it yourself and then program it. This small microcontroller board can run Arduino and its goal is to have a simple, cheap and quick-start platform for everyone interested in learning and creating things.

Tinusaur comes as an assembly kit, in parts, all in a small plastic bag, so you have to solder it yourself. In order to program this microcontroller board you will need a programmer like AVR ISP programmer, you can also use an Arduino to program the ATtiny microcontroller.

These are the components of Tinusaur standard kit:

  • PCB: Tinusaur PCB
  • MCU, Attiny85: Atmel AVR ATtiny85 microcontroller
  • Socket, DIP-8: DIP-8 socket for MCU
  • H1, Header: Header 2×4, Female
  • H2, Header: Header 2×5, Female
  • ISP, Header: Header 2×5, Male, for ISP
  • RESET, Button: Tactile push button, for RESET
  • Power, Header: Header 1×2, Male, for external power
  • Battery, Header: Header 1×2, Male, for battery power on/off
  • Battery, Jumper: Jumper, 2-pin, for battery power on/off
  • C1, Capacitor: Capacitor 100uF, Low profile 5×5 mm
  • C2, Capacitor: Capacitor 100nF, Small
  • R1, Resistor: Resistor 10K, Small, 1/8W
  • Battery holder: Battery holder for CR2032
  • Battery 3V: Battery 3V, CR2032

There is also the Tinusaur Starter – another kit that has everything included in the Tinusaur Board plus a USBasp programmer, plus few other useful things.

Tinusaur was launched 3 years ago and it is now used  in schools and universities to educate young people in both hardware and software. The team behind Tinusaur had launched an Indiegogo campaign to produce more of Tinusaur boards and bring the cost down to $3 per basic board and allow more people to be able to get them. A recent crowdfunding campaign was held by the team, it didn’t meet its goal plus it had the price multiplied by 3!

With just $3 you can get now the Lite edition of Tinusaur, the same components as the standard kit excluding the battery and its holder. You can get the Standard one for $4 and the Starter one for $6.

This Tinusaur is open source, both the hardware and the software, and you can check out the source files right here https://bitbucket.org/tinusaur. 3 days are left to end this crowdfunding campaign, so if you are interested in getting your own Tinusaur with that amazing price you should hurry up! More details can be found at the official product page, getting started page and tutorials.

Tiny LED Time Watch

tinytimewatch

David Johnson-Davies designed a minimalist ATtiny85-based watch using 12 LEDs, arranged like a clock face, to show the time in analogue-style. He writes:

To show the time you press the button on the watch face, and the time is then displayed for four seconds. It lights one LED to show the hour, and flashes another LED to show the minutes to the nearest five minutes, like the hour and minute hands on a clock. If only one LED lights up you know that both hands are pointing to the same hour mark.

Tiny LED Time Watch – [Link]

RELATED POSTS

DIY Spectrum Analyser

Alan X has been working on a spectrum analyser project that can show the spectrum visually! He started working with ATTiny85 and kept on updating the project over time.

1952321477553334016

Alan X used Goertzel’s algorithm with a Hamming window, this algorithm can be used to detect a frequency from sampled data. Here is the preliminary code for a spectrum analyzer:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Uses Daniil Guitelson's BGI library
#include "graphics.h" // -lBGI -lgdi32


#define SampleFreq 125000


int main(void)
{
  int N=250;
  double data[N];
  double samples[N];
  double freq;
  double s;
  double s_prev;
  double s_prev2;
  double coeff;
  double magn;
  int i;


  int gd=CUSTOM, gm=CUSTOM_MODE(700,700);
  initgraph(&gd, &gm, "");
  setcolor(WHITE);


  int X1,Y1,X2,Y2;
  double scale,xmin,ymin,xmax,ymax;


  // Find the maximum and minimum data range
  xmin=0;
  ymin=0;
  xmax=50000;
  ymax=N;
  scale=1.1*(xmax-xmin>ymax-ymin?xmax-xmin:ymax-ymin);


  // Generate samples
  for (i=0;i<N;i++) {
    samples[i]=(50*sin(2*M_PI*i*3300/SampleFreq)+50*sin(2*M_PI*i*5700/SampleFreq)+50*sin(2*M_PI*i*25700/SampleFreq)+100);
    // Window the data
    // data[i]=samples[i]; // Straight Goertzel - not great
    // data[i]=samples[i]*(0.5-0.25*cos(2*M_PI*i/N)); // Hanning Window
    data[i]=samples[i]*(0.54-0.46*cos(2*M_PI*i/N)); // Hamming Window
    // data[i]=samples[i]*(0.426551-0.496561*cos(2*M_PI*i/N)+0.076848*cos(4*M_PI*i/N)); // Exact Blackman Window
  }


  // Scan frequencies
  for (freq=100;freq<=50000;freq+=100) {
    coeff=2*cos(2*M_PI*freq/SampleFreq);
    s_prev=0.0;
    s_prev2=0.0;
    for (i=0;i<N;i++) {
      // Goertzel
      s=data[i]+coeff*s_prev-s_prev2;
      s_prev2=s_prev;
      s_prev=s;


    }


    // Get magnitude
    magn=2*sqrt(s_prev2*s_prev2+s_prev*s_prev-coeff*s_prev*s_prev2)/N;
    printf("Freq: %6f Mag: %6.4f\n",freq,magn);


    // Plot data
    X1=(int)((freq-(xmin+xmax)/2)*700/scale+350);
    Y1=(int)((0+(ymin+ymax)/2)*700/scale+650);
    X2=(int)((freq-(xmin+xmax)/2)*700/scale+350);
    Y2=(int)((-magn*700/2+(ymin+ymax)/2)*700/scale+650);
    line(X1,Y1,X2,Y2);


  }
  getchar();
  closegraph();


  return 0;
}

Daniil Guitelson’s BGI library was also used for the graphics.

Output

Here is the output showing the DC, 3300 Hz, 5700 Hz and 25700 Hz signals:

8398261477186172386

 

The next step is to port the code to a suitable Arduino board and to show the results physically. Thus, he used a MicroView OLED display and here it is listening to a 3v 1kHz square wave:

68801477279127568

 

#include <MicroView.h>

// Audio Spectrum Analyser
#define SampleInput A0   // Name the sample input pin
#define BandWidth  500   // BandWidth
#define MaxFreq   4000   // Max analysis frequency
#define Trigger     10   // Trigger to synchronise the sampler 2vpp at 1kHz = 32

// Define various ADC prescaler
const unsigned char PS_16=(1<<ADPS2);
const unsigned char PS_32=(1<<ADPS2)|(1<<ADPS0);
const unsigned char PS_64=(1<<ADPS2)|(1<<ADPS1);
const unsigned char PS_128=(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

// Setup the serial port and pin 2
void setup() {
// Setup the ADC
pinMode(SampleInput,INPUT);
ADCSRA&=~PS_128; // Remove bits set by Arduino library
// Set prescaler
// ADCSRA|=PS_64; // 64 prescaler (250 kHz assuming a 16MHz clock)
// ADCSRA|=PS_32; // 32 prescaler (500 kHz assuming a 16MHz clock)
ADCSRA|=PS_16; // 16 prescaler (1 MHz assuming a 16MHz clock)

uView.begin();// Start MicroView
uView.clear(PAGE); // Clear page
uView.println("Spectrum  Analyser"); // Project
uView.println("0-20 kHz"); // Range
uView.println();
uView.println("agp.cooper@gmail.com"); // Author
uView.display(); // Display
uView.clear(PAGE); // Clear page
delay(2000);// Wait
}

void loop() {
static byte *samples; // Sample array pointer
static byte *window; // Window array pointer
static int N=0; // Number of samples for BandWidth
static long sampleFreq; // Sample frequency
long freq; // Frequency of interest
float s; // Goertzel variables
float s_prev;
float s_prev2;
float coeff;
float magn;
int i;

if (N==0) {
// Check sample frequency and set number of samples
samples=(byte *)malloc(100);
unsigned long ts=micros();
for (i=0;i<100;i++) samples[i]=(byte)(analogRead(SampleInput)>>2);
unsigned long tf=micros();
free(samples);
sampleFreq=100000000/(tf-ts);
N=2*sampleFreq/BandWidth+1;

uView.setCursor(0,0); // Set cursor to beginning
uView.print("SI: A"); // Sample input pin
uView.println(SampleInput-14);
uView.print("SF: "); // Sample frequency
uView.println(sampleFreq);
uView.print("MF: "); // Max frequency
uView.println(MaxFreq);
uView.print("BW: ");// andWidth
uView.println(MaxFreq);
uView.print("SN: ");// Number of samples
uView.println(N);
uView.display(); // Display
uView.clear(PAGE);// Clear page
delay(2000);

// Create arrays
samples=(byte *)malloc(N);
window=(byte *)malloc(N);

// Modified Hamming Window
for (i=0;i<N;i++) window[i]=(byte)((0.54-0.46*cos(2*M_PI*i/(N-1)))*255);

// Generate test samples
for (i=0;i<N;i++) {
samples[i]=(byte)(30*(sin(2*M_PI*i*5000/sampleFreq)+sin(2*M_PI*i*2500/sampleFreq)+sin(2*M_PI*i*7500/sampleFreq)+sin(2*M_PI*i*10000/sampleFreq))+127);
}
}

if (true) {
// Sychronise the start of sampling with data slicer
int a0,a1;
a0=1023;
for (i=0;i<N;i+=2) {
a1=analogRead(SampleInput);
a0=(a0*13+a1*3)/16;
if (a1>a0+3) break;
}
for (i=0;i<N;i++) samples[i]=(byte)(analogRead(SampleInput)>>2);
}

// Scan frequencies
for (freq=0;freq<=MaxFreq;freq+=(MaxFreq/40)) {
// Goertzel (https://en.wikipedia.org/wiki/Goertzel_algorithm)
coeff=2*cos(2*M_PI*freq/sampleFreq);
s_prev=0;
s_prev2=0;
for (i=0;i<N;i++) {
s=0.0000768935*window[i]*samples[i]+s_prev*coeff-s_prev2;
s_prev2=s_prev;
s_prev=s;
}
// Get magnitude
magn=2*sqrt(s_prev2*s_prev2+s_prev*s_prev-coeff*s_prev*s_prev2)/N;
// Display on MicroView
uView.line(freq*40/MaxFreq,47,freq*40/MaxFreq,10-(int)(20*log10(magn+0.0001)));
}
// Frequency graduations
uView.setCursor(47,0);
uView.print(MaxFreq/1000);
uView.print("k");
uView.line(0,0,0,5);
uView.line(10,0,10,2);
uView.line(20,0,20,5);
uView.line(30,0,30,2);
uView.line(40,0,40,5);
// Voltage graduations
uView.line(0,40,40,40);
uView.setCursor(47,38);
uView.print("-30");
uView.line(0,20,40,20);
uView.setCursor(47,18);
uView.print("-10");
uView.line(0,10,40,10);
uView.setCursor(47,8);
uView.print("  0");
//Display
uView.display();
uView.clear(PAGE);
}

He then updated the project to work with Nokia LCD, here it is showing the 0-3v 1 kHz square wave signal:

3095781477395166324

Amazing ideas and projects can be inspired by this project. You can download these files to start your own spectrum analyser!

The full project and detailed information are available at the project page on Hackaday. You can follow it to keep updates with the latest versions.

Recover Bricked ATtiny Using Arduino as high voltage programmer

source: oscarliang.com

Hi! Today I’ll explain you how to recover your bricked ATtiny microcontroller using your Arduino board. ATtinys are very popular due to their small form factor yet very powerful. While working with them you may accidentally brick the ATtiny. As arduino is extremely popular and really easy to use, I guess you have one or more lying on your work table. You don’t need to purchase a HVP (High Voltage Programmer), or search for an old PC with parallel port to recover ATtiny. Just build a small circuit, plug it into Arduino board, upload a sketch and you are good to go. So let’s start… (more…)

RELATED POSTS

ATtiny85 Light Sensor – I2C slave device

attiny-light-sensor-with-i2c-1024x650

Paweł Spychalski build a photoresistor based daylight meter sensor connected via I2C bus using ATtiny85:

I love AVR ATtinyx5 series microcontrollers. They are cheap, easy to use, they can be programmed just like Arduinos and comparing to their size they offer great features. For example, they can be used as remote analog to digital converters connected to master device using I2C bus.

ATtiny85 Light Sensor – I2C slave device – [Link]

Neopixel Night Light using ATtiny85

F3I7FQEIQJGB80A.MEDIUM

joshua.brooks @ instructables.com describes how he build a night light using an Adafruit NeoPixel, ATtiny85 microcontroller, TSSP4038 IR receiver and some other easy available components.

I’m giving some workshops in electronics in a few weeks, centered around an inexpensive, but useful real-world project. When trying to come up with a thing to make, I wanted it to involve a microcontroller, NeoPixel LEDs (because, they’re awesome), be remotely controllable, and allow for different build options. It also had to be fully simulatable in Autodesk Circuits. This is the project that evolved.

Neopixel Night Light using ATtiny85 – [Link]

Wireless digital scale

F9IVS3JIO7EMPYQ.MEDIUM

This is a wireless digital scale using ATTiny85 microcontroller and HM-10 Bluetooth low energy transmitter/receiver:

This scale is wireless. It may be useful where you can’t operate a normal scale, due to the weather outside, or if you don’t want to scare birds or other creatures away. With this scale you can weigh them. In this instructable, I used a 0 to 1 Kg load cell since I wanted to weigh hummingbirds and orioles that visited our nectar feeder.

Wireless digital scale – [Link]