So my program fails to run because there is not enough room for my variables as well as the Arduino Core and Stack. I can't find any more ways to optimize my program so I'm thinking about just rewriting it in C.
However, I'm not sure if that will actually help me. For example I know that in C my program will run faster because things like digitalWrite()
and analogRead()
have a bunch of "extras" that make it go slower, but I don't know if this will affect RAM.
So can any of the experts on here tell me if writing my code will help before I waste time doing so?
Here is my code:
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>
#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
SoftwareSerial mySerial(0,1) PROGMEM;
byte i;
byte pixelsArray1[128]; //Array to hold the values of the individual pixles.
byte pixelsArray2[128]; //Array to hold the values of the individual pixles.
byte pixelsArray3[128]; //Array to hold the values of the individual pixles.
void setup()
{
#if FASTADC
// set prescale to 16
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
#endif
pinMode(1,OUTPUT); //Setting the 1 pin to be used for output
pinMode(0,OUTPUT); //Setting the 0 pin to be used for output
pinMode(A3,INPUT); //Input for Camera 3
pinMode(A2,INPUT); //Input for Camera 2
pinMode(A1,INPUT); //Input for Camera 1
mySerial.begin(9600); //Setting the data transfer rate
}
Notes:
- I'm programming on the ATtiny85
- I'm running Windows 10
- I've never programmed in Arduino before
SoftwareSerial
and running the USI by hand, but have you tried the code on a larger device yet? – Ignacio Vazquez-Abrams Jun 14 '16 at 17:59SoftwareSerial
has a buffer that takes up RAM regardless of where the object itself is located. AVR307 – Ignacio Vazquez-Abrams Jun 14 '16 at 18:07