Skip to content

Example using an ATTiny85 to display the RPM output from a 3 pin DC fan on an OLED screen over i2c

Notifications You must be signed in to change notification settings

korziee/attiny85-fan-rpm-oled-display

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Displaying fan RPM on an OLED using an ATtiny85

IMG_7049

Demo Video

IMG_7045.mov

Schematic

schematic-v0.1

Requirements

  1. ATtiny85 development board (the one with USB + 5V regulator), like this.
  2. Arduino 2 IDE (think this comes pre-installed with the boards manager, you could use the original IDE but you'll need to add ATTinyCore to the boards manager, like this)
  3. 3 pin DC Fan
    1. I've used an old PL80S12M. It activates down to 5v so I could test in circuit without an external supply.
  4. 128x64 i2c OLED
    1. I've used this one

Note on the Code

Most of the code is self-documenting, however interrupts on the ATtiny85 are not like other AVR boards and you cannot use attachInterrupt directly like you would with an Arduino Uno - you instead need to setup the registers explicitly. The three registers we care about are: PCMSK, GIMSK and MCUCR. Once you've set the registers, you need to enable interrupts globally by calling the sei function.

PCMSK - Pin Change Mask Register

The PCMSK register configures which pins (PB-0 through to PB-5) will trigger an interrupt.

GIMSK - General Interrupt Mask Register

We only care about the 5th bit in this register, which is the PCIE (Pin Change Interrupt Enable) pin. In the PCMSK register we configured which pins triggered an interrupt, and by setting PCIE to be 1, we enabled that behaviour.

MCUCR - MCU Control Register

Bits 7:2 control assorted properties of the MCU, bits 1 and 0 however serve as the interrupt sense control for the ATtiny85. This controls the condition you want the interrupt to be triggered (rising, falling, low, any) on.

Bit 1 (ISC01) Bit 0 (ISC00) Description
0 0 The low level of INT0 generates an interrupt request.
0 1 Any logical change on INT0 generates an interrupt request.
1 0 The falling edge of INT0 generates an interrupt request.
1 1 The rising edge of INT0 generates an interrupt request.

Note on Interrupt Pins

The ATtiny85 development boards have a handful of components attached to some of the GPIO pins to enable sub programming and to provide a regulated 5V supply, this means that not all pins are suitable to be used an interrupt. I could not get pin 4 to operate in a stable manner as it is part of the USB circuitry. Pin 5 is not connected to anything, but I was unable to get an interrupt to trigger on this pin, unsure why - think it has something to do with that pin being used as the reset. Pins 0 and 2 are ideal candidates for interrupt triggers, but these are used for i2c (SDA and SCL respectively), so I could not use them. I had moderate success with pin 3 even though it's connected to a USB data line. I think this is because unlike pin 4, pin 3 in the development board is tied to 5V. So it is mostly stable, but occasionally some data on the USB line causes it to freak out a bit and the RPM measurement is incorrect - maybe if this was connected to a USB power supply (no data) then it would not be an issue. Because pin 3 is used in the usb circuitry, IT NEEDS TO BE UNPLUGGED BEFORE programming, otherwise it'll just hang.

References

About

Example using an ATTiny85 to display the RPM output from a 3 pin DC fan on an OLED screen over i2c

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages