Using Attiny to interpret signals from rc-receiver

Hello guys.

I'm having trouble getting an Attiny85 do to exactly as I want it to do, which is basically to read and interpret the impulse signals from an rc-receiver and turn an LED on or off, depending on the impulse. (flipping a lever on the transmitter off/on sends an impulse of about 1300 micros and 1950 micros respectively) I tried at first to hook it directly to the arduino, which worked wonderfully, but with the Attiny85 the led flashes on and off for a couple of times, but then stays on regardless of lever position. Is it even possible to use the Attiny for this project, perhaps I've missed something? The Attiny85 workes fine for other simple projects such as "Blink". (I tried to make a LED blink with different frequencies by taking input from a potentiometer, but that one failed for unknown reasons).

The plan here is to use the attiny85 onboard a quad to switch on/off leds.

The sketches for both the arduino (works fine) and the Attiny (doens't work fine), are shown below.

Arduino:

long pulse; //gear channel on receiver 
#define signalPin 9
#define outputPin 13
int outputState;


void setup() {

  pinMode(signalPin, INPUT); 
  pinMode(outputPin, OUTPUT);
  Serial.begin(9600); 
  digitalWrite(outputPin, LOW);
}

void loop() {

  pulse = pulseIn(signalPin, HIGH, 25000); // Read the pulse width
  if (pulse > 1800) {
    outputState = LOW;
  }
  else {
    outputState = HIGH;
  }
  digitalWrite(outputPin, outputState);
  Serial.print(pulse);
  Serial.print('\t');
  Serial.println(outputState);
  delay(50);
}

Attiny:

long pulse; //gear channel on receiver 
#define signalPin 1
#define outputPin 0
int outputState;


void setup() {

  pinMode(signalPin, INPUT); 
  pinMode(outputPin, OUTPUT);
  //Serial.begin(9600); 
  digitalWrite(outputPin, LOW);
}

void loop() {

  pulse = pulseIn(signalPin, HIGH, 25000); // Read the pulse width
  if (pulse > 1800) {
    outputState = LOW;
  }
  else {
    outputState = HIGH;
  }
  digitalWrite(outputPin, outputState);
  // Serial.print(pulse);
  // Serial.print('\t');
  // Serial.println(outputState);
  delay(10);
}

For signalPin 1 you are connecting to ATtiny85 physical pin 6 and for outputPin 0 you are connecting to ATtiny85 physical pin 5?

[quote author=Runaway Pancake link=topic=188770.msg1396954#msg1396954 date=1379549107]

For signalPin 1 you are connecting to ATtiny85 physical pin 6 and for outputPin 0 you are connecting to ATtiny85 physical pin 5? [/quote]

Yes, sir!

Physical pin conf.:

1 8 2 7 3 6 4 5

When you say that "the led flashes on and off for a couple of times" do you mean that it responds correctly to the inputs on 4? occasions and after that it stays on? If 4 isn't the correct number what is? Does it matter how fast you provide the inputs?

Or do you mean that it flashes randomly and then stays on?

...R

It seems that it responds correctly for "on - off - on", but then hangs at "on". Doesn't seem to depend on how fast I flick the switch. Another thing is that (I suspect)the receiver looses contact with the transmitter. No idea why that happens. Perhaps the attiny shorts it in any way? The receiver is connected in parallell to pin 4 and 8 (gnd and vcc). Everything runs on 5 volts.

Robin2: When you say that "the led flashes on and off for a couple of times" do you mean that it responds correctly to the inputs on 4? occasions and after that it stays on? If 4 isn't the correct number what is? Does it matter how fast you provide the inputs?

Or do you mean that it flashes randomly and then stays on?

...R

Is there enough power for both receiver and Attiny? Is it possible that the receiver is drawing down the voltage to a level where the Attiny doesn't work? - perhaps even for a very short interval?

How is the LED powered and how much current does it draw?

...R

Robin2: Is there enough power for both receiver and Attiny? Is it possible that the receiver is drawing down the voltage to a level where the Attiny doesn't work? - perhaps even for a very short interval?

How is the LED powered and how much current does it draw?

...R

I don't know how much current the receiver draws, but the led with resistor draws about 5mA. Everything is powered by a 4.8V rc-receiver battery pack. Should be enough to power the receiver + one led.

Why did you comment out the Serial.print's ?

if you use this core:

https://code.google.com/p/arduino-tiny/

You can get the debugging output like you are used to from your Uno

Erni: Why did you comment out the Serial.print's ?

if you use this core:

https://code.google.com/p/arduino-tiny/

You can get the debugging output like you are used to from your Uno

I thought about it but couldn't find out how to do it. It would be very helpful in debugging though.

The output from Serial.print will be on pin PB3. All you have to do is connect that pin to a serial/usb converter (you can use your Uno as serial/usb converter)

There are other options. I have written an overview here: http://www.ernstc.dk/arduino/tinycom.html

Erni:
The output from Serial.print will be on pin PB3.
All you have to do is connect that pin to a serial/usb converter
(you can use your Uno as serial/usb converter)

There are other options. I have written an overview here:
Communication with Tiny's

I’m not able to get this to work. I installed the files (downloaded the stuff in the link and placed it in the correct directory) and uploaded a simple “Serial.print”-sketch to the Attiny85. I then connected it appropriately to the Arduino (Duemillanove), but nothing comes up when I open the serial monitor. Do I have to upload a certain sketch to the Arduino first?

Edit:
Okay, I somehow managed to get something out of it. The sketch I uploaded is a simple counter which prints the number to serial. When I connect it to the Arduino and open the serial monitor I get a reasonable number, however the serial monitor doesn’t refresh automatically and I have to press ‘reset’ on the arduino in order to get the next number and so on. Is there a way to make it print the numbers continually?

I have to press 'reset' on the arduino

Did you connect a jumper wire from reset to ground ?

Do I have to upload a certain sketch to the Arduino first?

You could upload an empty sketch, just for safety. The point is that you dont use the Atmega chip, when you keep it in reset (the jumperwire), but only the serial/USB circuit on the board. Actually you cpuld remove the chip from the Arduino instead of the jumper wire

Erni:

I have to press 'reset' on the arduino

Did you connect a jumper wire from reset to ground ?

Do I have to upload a certain sketch to the Arduino first?

You could upload an empty sketch, just for safety. The point is that you dont use the Atmega chip, when you keep it in reset (the jumperwire), but only the serial/USB circuit on the board. Actually you cpuld remove the chip from the Arduino instead of the jumper wire

I hadn't connected reset to ground, but when I did that it works(!), and I get a continuous feed in the serial monitor. Now that's sorted!

Then I tried to connect it to the rc-receiver as before; this time using the core provided in the link you gave earlier and it works for as many times as I flip the switch! (sketch is below). When I run the serial monitor however I sometimes get strange symbols or unexpected numbers on the "outputState"-print, and when the switch is ON and the pulse is expected to be longer than 1800ms it only displays long strings of strange symbols, any clue on why it does that?

EDIT: After a little more testing it seems it's still not working flawlessly, it still eventually "hang" in either on/off-position, but far less than in my first attempts. Any clues in the sketch?

long pulse; //gear channel on receiver 
#define signalPin 1
#define outputPin 0
int outputState;


void setup() {

  pinMode(signalPin, INPUT); 
  pinMode(outputPin, OUTPUT);
  Serial.begin(9600); 
  digitalWrite(outputPin, LOW);
}

void loop() {

  pulse = pulseIn(signalPin, HIGH, 25000); // Read the pulse width
  if (pulse > 1800) {
    outputState = LOW;
  }
  else {
    outputState = HIGH;
  }
  digitalWrite(outputPin, outputState);
  Serial.print(pulse);
  Serial.print('\t');
  Serial.println(outputState);
  delay(10);
}

I tried your sketch but I can not replicate your errors

A few ideas: Is there anything else connected to pin 0 and 1 than a LED and your receiver? You might use pin 3 and 4 instead Are you running your attiny of 1 MHz, if so try running it at 8MHz:

Select board -> Attiny85@8MHZ Select ->Tools->Programmer->(Your Programmer) select ->Tools->Burn Bootloader

This do not burn a bootloader to your chip, it is only used to set the fuses to another clock-speed.

Then upload your sketch again

Erni: I tried your sketch but I can not replicate your errors

A few ideas: Is there anything else connected to pin 0 and 1 than a LED and your receiver? You might use pin 3 and 4 instead Are you running your attiny of 1 MHz, if so try running it at 8MHz:

Select board -> Attiny85@8MHZ Select ->Tools->Programmer->(Your Programmer) select ->Tools->Burn Bootloader

This do not burn a bootloader to your chip, it is only used to set the fuses to another clock-speed.

Then upload your sketch again

Did you try using a reiceiver also?

I will try usig other pins tomorrow, maybe that helps. Nothing else is connected besides led (+resistor) and receiver. Everything is put on breadboard so perhaps capacitance can be a problem? Programming procedure is as you described.

Did you try using a reiceiver also?

Yes

Erni:

Did you try using a reiceiver also?

Yes

Okay, thanks :). Did you use pb0 (physial pin 5) as output and pb1 (physical pin 6) for signal as well?

What I find strange is that it's the same with two different Attiny85 chips (implying that the chip is okay), and that it does not occur when running the sketch on the arduino (implying that the receiver is working fine).

Maybe the Attiny is auto resetting: Connect a 10 K ohm resistor from RESET to VCC, and A 0.1 uF across VCC and GND as close to the processor as possible

Erni: Maybe the Attiny is auto resetting: Connect a 10 K ohm resistor from RESET to VCC, and A 0.1 uF across VCC and GND as close to the processor as possible

I will try that. As far as I understand this will pull the RESET HIGH, but what will the capacitor do, filter noise?