Pages: 1 2 [3]   Go Down
Author Topic: ATtiny85 + Arduino  (Read 3794 times)
0 Members and 1 Guest are viewing this topic.
Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh my.  I'd love to have a copy of that ArduinoISP!
That would make debugging so much easier!
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12290
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


I'll get a copy to you sometime this week.  Bear in mind that I have no idea if it does or does not work with Serial Monitor; I've been using Tera Term.

What are you using for Serial?
Logged

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I use the serial monitor right now.  I have putty and other terminal type software I can use though, I don't mind mucking about trying to get it to work.
Really, I'll grab whatever is necessary to be able to debug via ArduinoISP in serial, blinking LEDs for debugging gets real old real fast.
So far I've had decent luck doing the coding and debugging on a 328 before stuffing it into an attiny85, but code that runs great on my 328 may or may not run great on an attiny (I tend to forget to change pin definitions, or change them to the wrong port).

EDIT:
Of course, I've got the fan controller attiny85 OSCCAL'd low enough that serial is probably a lost cause.  On the plus side, that's only one of many potential projects, and it pretty much works anyway.
« Last Edit: June 05, 2011, 09:53:13 pm by Bobnova » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12290
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Really, I'll grab whatever is necessary to be able to debug via ArduinoISP in serial, blinking LEDs for debugging gets real old real fast.

I hear that!

Quote
Of course, I've got the fan controller attiny85 OSCCAL'd low enough that serial is probably a lost cause.

If you have a board with more than one serial port (Mega, Teensy) you can probably pull it off.  The trick is to calculate and use the actual baud rate rather than the specified rate.

In the long run, I have plans to use a knock + Manchester code to eliminate baud rate differences and make communications much more efficient.  But, that has to wait for another day.
Logged

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

Sorry about the late reply, had a huge amount of work over the last few days so not much time to play with this unfortunately.

Difficult to say.  You haven't provided enough information.  Which core did you decide to use?  What serial-to-USB converter are you using?  How do you have the converter connected?

I used your core, with the ATtiny85 simply connected to the Arduino Uno, connected to the PC via USB.

fadeLight is always a negative int value bounded to zero.

That was the problem! I changed fadeLight to 255 instead of 0 in the then-clause of:
Code:
if (soundLevel >= threshold)

This fixed the problem entirely, so now my sketch behaves properly on the ATtiny85. A huge thank you for your invaluable help Coding Badly! Thinking about it now it was actually quite a stupid error on my part, because of course the LED brightness should start at maximum, not zero! I'm quite interested to know why my sketch worked on the Arduino in the first place...

analogWrite does not clamp the value so, when the value changes from -256 to -257 the value actually written to the hardware goes from 0 (full off) to 255 (full on).

Where do the values -256 and -257 come from? I assumed the limit for analogWrite was 255?

There is an assumption that the fading stops at -90 but that may not be true because of the next problem...

Why -90?

Finally, I doubt the application will be running continuously for 49 days but, if it is, it will not work correctly.  millis values and addition (and direct comparison) do not mix.

In practice my circuit will run on a battery so it definitely won't be running for 49 days! But from a technical standpoint I'm interested to know what I can do to make the code work indefinitely. What happens after 49 days? Does millis not simply reset to zero?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12290
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serial ala ... ATtiny85 simply connected to the Arduino Uno, connected to the PC via USB.

I'm in the process of adding "serial relay" to the Arduino ISP Sketch.  Until then, you can use the Uno as a serial converter.  Hold the processor in reset by connecting a jumper between RESET and GND.  Connect the serial output from the ATtiny85 to pin 1 on the Uno.  The ATtiny85 and the Uno will have to have the grounds connected.  You should then be able to use a terminal program to collect output from the ATtiny85.

Quote
A huge thank you for your invaluable help Coding Badly!

You are welcome.

Quote
Where do the values -256 and -257 come from? I assumed the limit for analogWrite was 255?

The low byte of the value passed to analogWrite makes it to the hardware.  The high byte is stripped away / ignored.  Convert the int value -256 to hexadecimal ... 0xFF00.  The low byte is 0x00.  So, when -256 is passed to analogWrite the actual value written to the hardware is zero.  The int value -257 in hexadecimal is 0xFEFF.  The low byte is 0xFF which is what gets written to the hardware.  So, when the value is decremented from -256 to -257 the output value goes from full off to full on.

Quote
Why -90?

Uh, I got that one wrong.  Sorry about that.

Quote
But from a technical standpoint I'm interested to know what I can do to make the code work indefinitely. What happens after 49 days? Does millis not simply reset to zero?

Yes.  The phrase is "roll over" or "wrap".  The value goes from 0xFFFFFFFF to 0x00000000.  The trick is to always use subtraction to calculate a difference.  Give this a look...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260223964/1

There are some small bugs in this one but the technique is valid...
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

The corrections...
http://arduino.cc/forum/index.php/topic=55372.0
Logged

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

Hi again,

Sorry for the late response - work has been extremely hectic lately! But I have a couple of hours free today so I thought I'd continue on with this project.

During more thorough testing, I noticed something strange about the way my sketch works on the ATtiny85 - The potentiometer which is supposed to adjust the noise threshold ('threshold' in my code) at or above which the LEDs are illuminated, behaves differently on the ATtiny85. It's supposed to allow adjustment through the entire range of 0-1023, and does so on the Arduino. But with my sketch on the ATtiny85, when the pot is turned roughly a quarter of the way up, it becomes impossible to make the LEDs illuminate at all, even with very loud noises. I guess I should try and get serial monitor working to be able to read the actual value of 'threshold' on the Attiny85.

I'm in the process of adding "serial relay" to the Arduino ISP Sketch.  

Would your modified Arduino ISP sketch allow use of the serial monitor on the Attiny85 through the Arduino IDE, in the same way that it currently works for the Ardunio itself?

Until then, you can use the Uno as a serial converter.  Hold the processor in reset by connecting a jumper between RESET and GND.  Connect the serial output from the ATtiny85 to pin 1 on the Uno.  The ATtiny85 and the Uno will have to have the grounds connected.  You should then be able to use a terminal program to collect output from the ATtiny85.

What would be a good terminal program to use for this? Would the Arduino IDE be suitable?
« Last Edit: June 29, 2011, 10:41:16 am by Eli_Ben » Logged

Pages: 1 2 [3]   Go Up
Jump to: