Offline
Newbie
Karma: 0
Posts: 4
|
 |
« on: September 05, 2012, 05:53:41 pm » |
Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different. Here is my code, Im aware of the clock speed difference and Ive adjusted the delays and the delays appears to be fine. byte leds[9][6] = {{LOW, HIGH, HIGH, HIGH, LOW, LOW}, {LOW, HIGH, HIGH, LOW, HIGH, LOW}, {LOW, HIGH, HIGH, LOW, LOW, HIGH}, {HIGH, LOW, HIGH, HIGH, LOW, LOW}, {HIGH, LOW, HIGH, LOW, HIGH, LOW}, {HIGH, LOW, HIGH, LOW, LOW, HIGH}, {HIGH, HIGH, LOW, HIGH, LOW, LOW}, {HIGH, HIGH, LOW, LOW, HIGH, LOW}, {HIGH, HIGH, LOW, LOW, LOW, HIGH} }; byte n[9][9] = {{0,0,0,0,1,0,0,0,0}, // 1 {1,0,0,0,0,0,0,0,1}, // 2 {1,0,0,0,1,0,0,0,1}, // 3 {1,0,1,0,0,0,1,0,1}, // 4 {1,0,1,0,1,0,1,0,1}, // 5 {1,0,1,1,0,1,1,0,1}, // 6 {1,0,1,1,1,1,1,0,1}, // 7 {1,1,1,1,0,1,1,1,1}, // 8 {1,1,1,1,1,1,1,1,1}}; // 9 byte misc[11][9] = {{0,0,0,1,1,0,1,1,0}, {1,1,0,1,1,0,0,0,0}, {0,1,1,0,1,1,0,0,0}, {0,0,0,0,1,1,0,1,1}, {1,0,1,0,1,0,1,0,1}, {1,0,0,1,0,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {0,0,1,0,0,1,0,0,1}, {1,1,1,0,0,0,0,0,0}, {0,0,0,1,1,1,0,0,0}, {0,0,0,0,0,0,1,1,1} }; byte prop[4][9] = {{0,0,0,1,1,1,0,0,0}, {0,0,1,0,1,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {1,0,0,0,1,0,0,0,1} }; byte raider[4][9] = {{1,0,0,1,0,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {0,0,1,0,0,1,0,0,1}, {0,1,0,0,1,0,0,1,0}, };
void setup() { pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); clearLeds(); digitalWrite(2, LOW); digitalWrite(5, HIGH); delay(125); digitalWrite(2, HIGH); digitalWrite(5, LOW); delay(125); }
void loop() { for( int repeat=0; repeat<10; repeat++) { for(int i=0; i<4; i++) { for(int j=0; j<200; j++) { printPatern(raider[i]); } } } for( int repeat=0; repeat<10; repeat++) { int i = random(11); { for(int j=0; j<250; j++) { printPatern(misc[i]); } } } for( int repeat=0; repeat<1; repeat++) { for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { clearLeds(); digitalWrite(i+2, LOW); digitalWrite(j+5, HIGH); delay(25); } } } for( int repeat=0; repeat<1; repeat++) { for(int i=0; i<9; i++) { for(int j=0; j<200; j++) { printPatern(n[i]); } } } for( int repeat=0; repeat<10; repeat++) { for(int i=0; i<4; i++) { for(int j=0; j<200; j++) { printPatern(prop[i]); } } } }
void clearLeds() { digitalWrite(2, HIGH); digitalWrite(3, HIGH); digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, LOW); digitalWrite(7, LOW); }
void printPatern(byte* number) { for(int i=0; i<9; i++) { if(number[i] == 1) { for(int j=0; j<6; j++) { digitalWrite(j+2, leds[i][j]); } }
delayMicroseconds(12.5); } }
|
|
|
|
« Last Edit: September 05, 2012, 06:56:46 pm by punker12 »
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #1 on: September 06, 2012, 02:02:37 am » |
1 - How much storage do your arrays need? 2 - How much SRAM does an ATtiny44 have?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25551
Solder is electric glue
|
 |
« Reply #2 on: September 06, 2012, 02:29:10 am » |
Using a byte array when all you use is one bit is very wasteful. Try and see if you can just use single bits and save some space.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #3 on: September 06, 2012, 08:10:25 am » |
1 - How much storage do your arrays need? 2 - How much SRAM does an ATtiny44 have?
Not very much 2.5kb, and the attiny44 has 256B of SRAM. Using a byte array when all you use is one bit is very wasteful. Try and see if you can just use single bits and save some space.
This code was borrowed for testing purposes, I plan to do something else with the chip. If I can get this code working on it then my other project will be a snap. Also space is not an issue.
|
|
|
|
|
Logged
|
|
|
|
|
Massachusetts, USA
Offline
Tesla Member
Karma: 97
Posts: 6376
|
 |
« Reply #4 on: September 06, 2012, 08:48:24 am » |
Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different.
Of course the pins are different. The 'core' you are using will map the Arduino pin names to physical pins. You'll have to look at the documentation for the core you are using to find out what that mapping is. The core should also take care of the timing so you shouldn't need to modify delays to get it to work. Did you "burn a bootloader" to get the fuses set properly?
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #5 on: September 06, 2012, 09:06:54 am » |
Not very much 2.5kb, and the attiny44 has 256B of SRAM. By my reckoning, these arrays require 306 of your 256 bytes of SRAM. byte leds[9][6] = {{LOW, HIGH, HIGH, HIGH, LOW, LOW}, {LOW, HIGH, HIGH, LOW, HIGH, LOW}, {LOW, HIGH, HIGH, LOW, LOW, HIGH}, {HIGH, LOW, HIGH, HIGH, LOW, LOW}, {HIGH, LOW, HIGH, LOW, HIGH, LOW}, {HIGH, LOW, HIGH, LOW, LOW, HIGH}, {HIGH, HIGH, LOW, HIGH, LOW, LOW}, {HIGH, HIGH, LOW, LOW, HIGH, LOW}, {HIGH, HIGH, LOW, LOW, LOW, HIGH} }; byte n[9][9] = {{0,0,0,0,1,0,0,0,0}, // 1 {1,0,0,0,0,0,0,0,1}, // 2 {1,0,0,0,1,0,0,0,1}, // 3 {1,0,1,0,0,0,1,0,1}, // 4 {1,0,1,0,1,0,1,0,1}, // 5 {1,0,1,1,0,1,1,0,1}, // 6 {1,0,1,1,1,1,1,0,1}, // 7 {1,1,1,1,0,1,1,1,1}, // 8 {1,1,1,1,1,1,1,1,1}}; // 9 byte misc[11][9] = {{0,0,0,1,1,0,1,1,0}, {1,1,0,1,1,0,0,0,0}, {0,1,1,0,1,1,0,0,0}, {0,0,0,0,1,1,0,1,1}, {1,0,1,0,1,0,1,0,1}, {1,0,0,1,0,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {0,0,1,0,0,1,0,0,1}, {1,1,1,0,0,0,0,0,0}, {0,0,0,1,1,1,0,0,0}, {0,0,0,0,0,0,1,1,1} }; byte prop[4][9] = {{0,0,0,1,1,1,0,0,0}, {0,0,1,0,1,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {1,0,0,0,1,0,0,0,1} }; byte raider[4][9] = {{1,0,0,1,0,0,1,0,0}, {0,1,0,0,1,0,0,1,0}, {0,0,1,0,0,1,0,0,1}, {0,1,0,0,1,0,0,1,0}, };
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #6 on: September 06, 2012, 09:17:35 am » |
Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. It seems as if the pins are different.
Of course the pins are different. The 'core' you are using will map the Arduino pin names to physical pins. You'll have to look at the documentation for the core you are using to find out what that mapping is. The core should also take care of the timing so you shouldn't need to modify delays to get it to work. Did you "burn a bootloader" to get the fuses set properly? Yes Im aware of this, I have changed them to match. I know that its not the same as the arduino. Ive looked to the documentation and matched accordingly. One section of the sketch works fine but the rest is all over the place. I haven't "bootloaded" it yet so I should do that and give it a try.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25551
Solder is electric glue
|
 |
« Reply #7 on: September 06, 2012, 11:27:05 am » |
Im tring to get this code to work with my 3x3 panel and it works with my arduino uno, but Im trying to program an attiny44 to work with this code, but it seems like its not displaying properly. Also space is not an issue. It is an issue as dxw00d points out:- these arrays require 306 of your 256 bytes of SRAM. It works on the UNO because it has enough memory, it does not work on the Attiny44 because it does not have enough memory. If I can get this code working on it then my other project will be a snap Yes then you will have succeeded in fitting a quart into a pint pot. http://en.wiktionary.org/wiki/you_can%27t_get_a_quart_into_a_pint_pot
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #8 on: September 06, 2012, 05:18:43 pm » |
For future reference, how do I figure out how much ram is required for the script?
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3117
|
 |
« Reply #9 on: September 07, 2012, 01:58:17 am » |
It won't give you the complete picture, but you can start by simply working out how much space all your variables need. byte leds[9][6] byte n[9][9] byte misc[11][9] byte prop[4][9] byte raider[4][9] So here, you have (9x6) + (9x9) + (11x9) + (4x9) + (4x9) = 306 bytes. Your loop variables will also require some storage space, as will any other variables used.
|
|
|
|
|
Logged
|
|
|
|
|
Westbrook, CT
Offline
Full Member
Karma: 2
Posts: 128
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
|
 |
« Reply #10 on: September 08, 2012, 05:41:52 pm » |
Hey man! Unfortunately the attinies are just sort of "stupid". I've used the attiny84 (the same as yours but with 8KB of flash) in my project and it just seems that when you put allot of functions, loops, if's, for's, outputs and inputs it becomes exusted.
I don't know, thats my opinion on my experience.
|
|
|
|
|
Logged
|
Arduino Uno R3 Mac OSX Lion
|
|
|
|
Virginia
Offline
Newbie
Karma: 0
Posts: 33
|
 |
« Reply #11 on: September 09, 2012, 09:56:49 am » |
I don't know how familiar you are with using macros in C/C++, but they can make the task of storing constant bits in packed bytes a lot easier. Also, if you use the "const" keyword for arrays which should be constant, they should be stored in Flash area, not in SRAM, saving the precious SRAM space. Here is a small example of defining a graphic character using macros. This 8x8 pixel character (including space) uses only 8 bytes of constant Flash memory. Please note that I coded this on-the-fly and have not compiled it, so...
#define ROW(b7,b6,b5,b4,b3,b2,b1,b0) \ (((b7)<<7)|((b6)<<6)|((b5)<<5)|((b4)<<4)|((b3)<<3)|((b2)<<2)|((b1)<<1)|b0) static const byte Graphic[] = { ROW(0,0,1,1,1,1,0,0), ROW(0,1,0,0,0,0,1,0), ROW(0,1,0,0,0,0,1,0), ROW(0,1,1,1,1,1,1,0), ROW(0,1,0,0,0,0,1,0), ROW(0,1,0,0,0,0,1,0), ROW(0,1,0,0,0,0,1,0), ROW(0,0,0,0,0,0,0,0), };
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Online
Brattain Member
Karma: 277
Posts: 25551
Solder is electric glue
|
 |
« Reply #12 on: September 10, 2012, 05:48:24 am » |
it just seems that when you put allot of functions, loops, if's, for's, outputs and inputs it becomes exusted. Well what ever is happening it is not attributed to exhaustion, there is no such thing in electronics.
|
|
|
|
|
Logged
|
|
|
|
|
|