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:
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.
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?
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.
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
Osgeld:
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?
I've used the MIT cores without any major issues beyond my fat fingers. But it is absolutely mandatory to follow these instruction:
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.