Sketch works fine on ATmega but not on ATtiny

It’s a kill switch for a RC car. It reads in a signal from a RC car receiver using PulseIn(). This value varies a bit so I map it so that any signal outside it’s normal range of 12100-12600 turns on a LED. This does exactly what I want it to on a UNO but gives me weird results when I load it on the ATtiny85. One of the biggest things is that it should turn the LED on if the signal drops out but even that doesn’t work. It does seem to respond to the trigger on the controller but I can’t figure what it thinks it’s doing. My guess is that PulseIn() is giving different values on the ATtiny?

const int sensorMin = 12100;
const int sensorMax = 12600;

void setup() {   
 
  pinMode(0, INPUT);
  pinMode(1,OUTPUT);
}


void loop() {
    int i = pulseIn(0, LOW);
    while (i == 0) {
      digitalWrite(1,HIGH);
      break;
    }
    int range = map(i,sensorMin,sensorMax,1,3);
    switch (range) {
    case 1:
      digitalWrite(1,HIGH);
      break;
    case 2:
      digitalWrite(1,LOW);
      break;
    case 3:
      digitalWrite(1,HIGH);
      break;
    }
}

My guess is that PulseIn() is giving different values on the ATtiny?

Given that the ATtiny runs at 8MHz I would say it would do.

You could use Serial.print(PulseIn() ); just to check your values.

Erni: You could use Serial.print(PulseIn() ); just to check your values.

I didn't know if I could do a serial print on the ATtiny. This is the first time I've tried to use one. I'll try it. Thanks.

Given that the ATtiny runs at 8MHz I would say it would do.

Why would that be ? 1 ms is 1 ms or?

I just tryed my RC receiver on a 8Mhz Attiny85, and the value of pulseIn(0, HIGH); is 1524 when I set the stick in middle pos. (The same value as when I use my Arduino)

The output from Serial.print on the Attiny comes on pin PB3 You can only use 9600, 38400 and 115200 baud

It is also possible to use softwareSerial, but as you only needs output from the tiny this TinyDebugSerial is much simpler.

To see the output you can connect tiny PB3 to pin1 on your Arduino, and connect reset to ground also on your ARduino. And ofcource ground to ground

Erni:

Given that the ATtiny runs at 8MHz I would say it would do.

Why would that be ? 1 ms is 1 ms or?

I just tryed my RC receiver on a 8Mhz Attiny85, and the value of pulseIn(0, HIGH); is 1524 when I set the stick in middle pos. (The same value as when I use my Arduino)

The output from Serial.print on the Attiny comes on pin PB3 You can only use 9600, 38400 and 115200 baud

It is also possible to use softwareSerial, but as you only needs output from the tiny this TinyDebugSerial is much simpler.

To see the output you can connect tiny PB3 to pin1 on your Arduino, and connect reset to ground also on your ARduino. And ofcource ground to ground

Got it working now. Thanks!