Pages: [1]   Go Down
Author Topic: ATTiny85 assistance - Blinky LED works, other program does not  (Read 1568 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm having quite an issue programming the ATTiny85-20pu and getting the results I expect.  I prototyped an Arduino based lightning sensor that will transmit (via IR) a signal to my Nikon camera to tell it to take a picture.  The project worked fine using the Arduino, and so to slim it down, I wanted to move it over to the ATTiny.

I followed the tutorial on the high-low tech page (http://hlt.media.mit.edu/?p=1695), and was able to get the Blink LED program to work once I solved the power issue (Thanks Coding Badly!).  I then uploaded my sketch for the lightning trigger after changing the input/output pins accordingly, but my test LED (in place of the IR transmitter for now) is not flashing.

Schematic View:


Breadboard View:


Code:
int shutterPin = 0;      // assign the Infrared emitter/ diode to pin 0
int triggerPin = 3;       // assign the lightning receiver to analog pin 3
int threshold = 5;        // set the threshold to not fire shutter on erraneous signals
int lightningVal;         // define an integer to be used later

void setup() {
  pinMode(shutterPin, OUTPUT);         // set the pin as an output
  digitalWrite(shutterPin, LOW);       // set the initial IR state to off

  lightningVal = analogRead(triggerPin);    // set a baseline value for the receiver. later, anything greater than this + threshold will trigger shutter
}

// sets the pulse of the IR signal.
void pulseON(int pulseTime) {
  unsigned long endPulse = micros() + pulseTime;        // create the microseconds to pulse for
  while( micros() < endPulse) {
    digitalWrite(shutterPin, HIGH);                     // turn IR on
    delayMicroseconds(13);                              // half the clock cycle for 38Khz (26.32×10-6s) - e.g. the 'on' part of our wave
    digitalWrite(shutterPin, LOW);                      // turn IR off
    delayMicroseconds(13);                              // delay for the other half of the cycle to generate wave/ oscillation
  }

}

void pulseOFF(unsigned long startDelay) {
  unsigned long endDelay = micros() + startDelay;       // create the microseconds to delay for
  while(micros() < endDelay);
}

void takePicture() {
  for (int i=0; i < 2; i++) {                           // loop the signal twice.
    pulseON(2000);                                      // pulse for 2000 uS (Microseconds)
    pulseOFF(27850);                                    // turn pulse off for 27850 us
    pulseON(390);                                       // and so on
    pulseOFF(1580);
    pulseON(410);
    pulseOFF(3580);
    pulseON(400);
    pulseOFF(63200);
  }                                                     
}

void loop() {
  int newLightningVal = analogRead(triggerPin);

  if (abs(newLightningVal - lightningVal) > threshold)
  {
    takePicture();
    delay(1200); // delay 1.2 sec before continuining to sense for lightning bolts
  }

  lightningVal = newLightningVal;
}

Thanks for taking a look.  I look forward to any comments.
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

with no current limiting on the LED are you sure you didnt burn it out?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your response, and good point.  I just placed a resistor into the circuit (220ohm between pin 0 and positive of LED) and used a known good LED, still with no blinking.

I am curious, are all the commands in my code supported on the ATTiny?  According to High-Low Tech, the following are supported:
pinMode()
digitalWrite()
digitalRead()
analogRead()
analogWrite()
shiftOut()
pulseIn()
millis()
micros()
delay()
delayMicroseconds()
SoftwareSerial

... and I assumed that simple things like while, for, abs, unsigned long, etc. are supported as well.  Am I wrong?
« Last Edit: August 31, 2012, 09:31:18 pm by benmctee » Logged

Canada
Offline Offline
Sr. Member
****
Karma: 0
Posts: 318
Sometimes teaching, always learning,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've also tried to make a remote trigger for my camera with an ATtiny 85. I've tried setting the internal clock to 1MHz and 8MHz, but I can't seem to get it to work. I just figured the ATtiny resonator is not precise enough to send a properly timed IR signal. It's just a hunch... I don't have a scope to verify this.
Logged


SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I helped a guy on the hackaday forums with that same "core" it doesnt set the CPU frequency correctly so (instead of taking my suggestion and using arduino tiny) he just halved all his timer event.

I also used that core when software serial was having issues in arduino tiny and while I got it working, 2400 baud with a large time delay between bytes was the best I could get.

its ok instructions, crap software, would work better with a few changes, but why, arduino tiny already works great, and supports more mcu's

Also the speed should be more than suffecent, worst your looking at is a sony/nec/Japanese  system running at 38khz
« Last Edit: August 31, 2012, 10:37:47 pm by Osgeld » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I helped a guy on the hackaday forums with that same "core" it doesnt set the CPU frequency correctly so (instead of taking my suggestion and using arduino tiny) he just halved all his timer event.

I also used that core when software serial was having issues in arduino tiny and while I got it working, 2400 baud with a large time delay between bytes was the best I could get.

its ok instructions, crap software, would work better with a few changes, but why, arduino tiny already works great, and supports more mcu's

Also the speed should be more than suffecent, worst your looking at is a sony/nec/Japanese  system running at 38khz

Thanks for your reply.  I have been messing with / googling the Arduino Tiny code.  It seems there is much less documentation out there for getting this up and running than the High-Low tech stuff.  I've changed the .txt file such that I show the ATTiny85 in my boards menu, with Arduino as ISP, but that's about as far as I've gotten.  Do you recommend a good place to find a tutorial?  Also, why do you recommend this project over the High-Low tech group project?
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1083
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware setup is the same for both cores, so not realy any need for another tutorial.

If you download the tiny core http://code.google.com/p/arduino-tiny/ , there is a readme file explaing how to install it.
BTW I once made a short tutorial for the attiny2313 found here http://www.ernstc.dk/arduino/2313.htm , it is basically the same as for the attiny85 (apart from the pin numbers etc)
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why do you recommend this project over the High-Low tech group project?

cause its done right

and it works with 7 other tiny chips
« Last Edit: September 04, 2012, 07:03:46 pm by Osgeld » Logged


Atlanta, USA
Offline Offline
Edison Member
*
Karma: 55
Posts: 1809
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've used the MIT cores without any major issues beyond my fat fingers.  But it is absolutely mandatory to follow these instruction:
Quote
By default, the ATtiny’s run at 1 MHz (the setting used by the unmodified “ATtiny45″, etc. board menu items). You need to do an extra step to configure the microcontroller to run at 8 MHz – necessary for use of the SoftwareSerial library. Once you have the microcontroller connected, select the appropriate item from the Boards menu (e.g. “ATtiny45 (8 MHz)”). Then, run the “Burn Bootloader” command from the Tools menu. This configures the fuse bits of the microcontroller so it runs at 8 MHz.


- Ray
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the problem is that many, if not all timer functions are still expected to run at 16Mhz as its using the normal arduino core for most everything

that right there put it in the "ugh" pile for me
Logged


Pages: [1]   Go Up
Jump to: