Transferring the project from Arduino Uno to Attiny85

Hi! I am from Polish and sorry for my English. :wink:
I wrote a program that works fine on Arduino Uno. I want to move this project to Digispark Attiny85 but it doesn't work properly. Can you tell me why? Is any command not supported by Attiny85?
Thank you for your help

// 3950 THERMISTOR EXAMPLE.
// Written by Miguel Angel Califa Urquiza
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Arduino thermistor library: https://github.com/miguel5612/Arduino-ThermistorLibrary

#include <thermistor.h>

thermistor therm1(1, 0); // P2 - Analog Pin which is connected to the 3950 temperature sensor, and 0 represents TEMP_SENSOR_0 (see configuration.h for more information).

byte tempThermistor = 0; // Temperatura odczytana z termistora (byte - przechowuje liczby od 0 do 255, zajmuje 1 bajt pami臋ci)
byte potentiometrTempValue = 0; // ustawiona temperatura w艂膮czenia wentylatora
byte potentiometrDeltaTempValue = 0; // ustawiona r贸偶nica temperatur
byte tempMaxFan = 0; // suma temperatury za艂膮czenia i delty temperatury (temperatura przy kt贸rej jest 100% mocy)
bool fanOn = false; // okre艣la czy wentylator jest w艂膮czony
unsigned long zapamietanyCzasPomiaruTemp = 0;


#define tempMin 10 // Zakres min ustawiania temperatur potencjometrem (nie mniej ni偶 2)
#define tempMax 60 // Zakres max ustawiania temperatur potencjometrem
#define deltaTempMin 10 // Zakres min ustawiania temperatur potencjometrem (nie mo偶e by膰 r贸wna 0)
#define deltaTempMax 60 // Zakres max ustawiania temperatur potencjometrem
#define PWMmin 200 // warto艣膰 PWM minimalna z kt贸r膮 uruchamiany jest wentylator
#define PWMmax 0 // warto艣膰 PWM maksymalna do kt贸rej dochodzi po przekroszeniu temperaury delta

#define PWMFanPin 1 // P1 -  Wyj艣cie na sterowanie wentylatorem
#define potentiometrTempPin 3   // P3 - Potencjometr temperatury w艂膮czenia wentylatora
#define potentiometrDeltaTempPin 2   // P4 - Potencjometr r贸偶nicy temperatury pomi臋dzy w艂膮czeniem wentylatora na jego minimalne obroty, a jego prac膮 na 100%

void setup() {
  // put your setup code here, to run once:
  
  pinMode(PWMFanPin, OUTPUT);  // ustaw Pin jako wyj艣cie
  digitalWrite(PWMFanPin, HIGH); // wy艂膮cz wentylator
}

void loop() {
  if (millis() - zapamietanyCzasPomiaruTemp >= 5000UL) {
    zapamietanyCzasPomiaruTemp = millis();
    tempThermistor = therm1.analog2temp(); // Odczytaj temperatur臋 i zapisz do zmiennej
    // odczyt z potencjometr贸w i konwersja na tempeartur臋
    potentiometrTempValue = map(analogRead(potentiometrTempPin), 0, 1023, tempMin, tempMax);
    potentiometrDeltaTempValue = map(analogRead(potentiometrDeltaTempPin), 0, 1023, deltaTempMin, deltaTempMax);
    tempMaxFan = potentiometrTempValue + potentiometrDeltaTempValue; // suma temperatury za艂膮czenia i delty temperatury (temperatura przy kt贸rej jest 100% mocy)


    if (tempThermistor < potentiometrTempValue) { // je艣li temperatura czujnika jest mniejsza od nastawionej temperatury za艂膮czenia
      if (tempThermistor <= potentiometrTempValue - 2) { // je艣li temperatura czujnika jest mniejsza o 2 stopnie od nastawionej temperatury za艂膮czenia to wy艂膮cz wentylator
        digitalWrite(PWMFanPin, HIGH);
        fanOn = false;
        
      }
      else if (fanOn == true) { // je艣li temperatura czujnika jest mniejsza ni偶 temp ustawiona, ale nie mniejsza od temperatury histerezy to podtrzymaj wentylator z min obrotami
        analogWrite(PWMFanPin, PWMmin); 
      }
    }

    if (tempThermistor >= potentiometrTempValue && tempThermistor <= tempMaxFan) { // zakres temperatur w kt贸rych regulowana jest warto艣膰 PWM
      analogWrite(PWMFanPin, map(tempThermistor, potentiometrTempValue, tempMaxFan, PWMmin, PWMmax)); // napisac jak ma si臋 za艂膮cza膰
      fanOn = true;
     
    }

    if (tempThermistor > tempMaxFan) {
      if (tempThermistor <= 150) {
 
      }
      else {
        digitalWrite(PWMFanPin, HIGH);
      }
    }
  }


}

Please explain what "doesn't work properly" means.

What did you expect to happen, and what happens instead?

For posting hints, see the "How to get the best out of the forum" post, linked at the head of very forum category.

You can try:

#define PWMFanPin PB1 // P1 -  Wyj艣cie na sterowanie wentylatorem
#define potentiometrTempPin A3   // P3 - Potencjometr temperatury w艂膮czenia wentylatora
#define potentiometrDeltaTempPin A2   // P4 - Potencjometr r贸偶nicy temperatury pomi臋dzy w艂膮czeniem wentylatora na jego minimalne obroty, a jego prac膮 na 100%

maybe

thermistor therm1(1, 0); // P2 - Analog Pin which is connected to the 3950 temperature sensor, and 0 represents TEMP_SENSOR_0 (see configuration.h for more information).

needs to change too.

The fuses are set differently than a stock Arduino attiny85.
Ref: High-Voltage Serial Programmer - Rescue AVR Chips (ericdraken.com)

It is difficult for me to say because I cannot use the serial port monitor. It seems to me that calculations are not performed correctly (maybe map ()?). To check, I removed the temperature sensor and assigned the variable tempThermistor = 40. But the program still didn't work properly. Renaming the pins doesn't help - I tried.

can you upload another sketch to digispark? try to blink the buil-in led to start isolating the problem.

I have uploaded the Blink example and it works fine. I also tried to upload the program via ISP - Blink works, but my program behaves the same as uploaded via USB

So now you can check by commenting parts of your code to try to find the issue, I don't know if the library thermistor.h can work out of the box with Attiny85, you can try to dim the build in led using each pots to see if the ADC's are working, use the led instead of the fan to pinpoint the problem. I think you can use softwareserial with Digispark, I think you can even replace the sensor with another pot to debug.

DigiKeyboard.h is also useful for debugging.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.