ATMEGA 1280 PROGRAM TO ATMEGA 1281

Hi everyone. I wish someone can help me with my dilemma. I got a project and I accidentally bought the wrong arduino board for it. Whenever I try to compile the program to ATMEGA 1281, I am receiving an error :

C:\Users\nikki\Desktop\chessdox\arduino-1.0.1\arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)': C:\Users\nikki\Desktop\chessdox\arduino-1.0.1\arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:398: error: expected `;' before ')' token

The program is actually compatible with ATMEGA 1280. I wonder if i could change the program to make it compatible with ATMEGA 1280.

This is the program.

#include <SoftwareSerial.h>

//Give convenient names to the control pins
#define CONTROL0 5    
#define CONTROL1 4
#define CONTROL2 3
#define CONTROL3 2
#define rxPin 10
#define txPin 11


//Create arrays for data from the the MUXs
//See the Arduino Array Reference: http://www.arduino.cc/en/Reference/Array
int mux0array[16];
int mux1array[16];
int mux2array[16];
int digitalpins[16];

int mux0arraycheck[16];
int mux1arraycheck[16];
int mux2arraycheck[16];
int digitalpinscheck[16];

int descrepicount = 0;


char * squares[] = {"A1","A2","A3","A4","A5","A6","A7","A8","B1","B2","B3","B4","B5","B6","B7","B8","C1","C2","C3","C4","C5","C6","C7","C8","D1","D2","D3","D4","D5","D6","D7","D8","E1","E2","E3","E4","E5","E6","E7","E8","F1","F2","F3","F4","F5","F6","F7","F8","G1","G2","G3","G4","G5","G6","G7","G8","H1","H2","H3","H4","H5","H6","H7","H8"};

int lastprinted;

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()
{
  //Set MUX control pins to output
  pinMode(CONTROL0, OUTPUT);
  pinMode(CONTROL1, OUTPUT);
  pinMode(CONTROL2, OUTPUT);
  pinMode(CONTROL3, OUTPUT);
  
  for(int i=23; i < 39; i++){
    pinMode(i, INPUT);
  }
  //Open the serial port at 9600 bps
  Serial.begin(9600);
  Serial.println("Startup");
  
  //Set analog pins to digital input  
  pinMode(A0, INPUT);         
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  
  //Turn on pullup resistors
  digitalWrite(A0, HIGH);       
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  
  /*for(int i = 0; i < 16; i++){
    digitalpins[i] = 1;
    digitalpinscheck[i] = 1;
  }*/
    
 
  
}
  

void loop()
{
  
    
     
  
  
  
   for (int i=0; i<16; i++)
  {
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    
    //Read and store the input
    //Since internal pullup is on, the pin goes low on changing, so the value needs to be flipped from 0 to 1 (!)
    mux0array[i] = !digitalRead(A0);
    
   
  
  }
  
  //This for loop is used to scroll through the SECOND multiplexer
  for (int i=0; i<16; i++)
  {
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    mux1array[i] = !digitalRead(A1);
    
    
    
  }
  
  //This for loop is used to scroll through the THIRD multiplexer
  for (int i=0; i<16; i++)
  {
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    mux2array[i] = !digitalRead(A2);
    
     
      
    
  }    
  
   for (int b = 0; b < 16; b++){
     
     digitalpins[b] = digitalRead(b + 23);
   }


//delay(1000); //Wait for the computer to move so we don't detect any false input from the other magnets
//it adds 12 seconds to startup time but that doesn't really matter... we're setting the board up anyway :)
  //sets the array to digitalreads of built in mega pins 23 - 39

  
  
  //This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
  for (int i=0; i<16; i++)
  {
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    
    //Read and store the input
    //Since internal pullup is on, the pin goes low on changing, so the value needs to be flipped from 0 to 1 (!)
    mux0array[i] = !digitalRead(A0);
    
   
  
  }
  
  //This for loop is used to scroll through the SECOND multiplexer
  for (int i=0; i<16; i++)
  {
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    mux1array[i] = !digitalRead(A1);
    
    
    
  }
  
  //This for loop is used to scroll through the THIRD multiplexer
  for (int i=0; i<16; i++)
  {
    digitalWrite(CONTROL0, (i&15)>>3); 
    digitalWrite(CONTROL1, (i&7)>>2);  
    digitalWrite(CONTROL2, (i&3)>>1);  
    digitalWrite(CONTROL3, (i&1));     
    mux2array[i] = !digitalRead(A2);
    
     
      
    
  }    
  
  
  ////////////Check if anything has changed...
  
  for (int b = 0; b < 16; b++){
    
  if(digitalpinscheck[b] != digitalpins[b]){
                 if(lastprinted != b || descrepicount == 0){
                Serial.print((squares[b]));
                 lastprinted = b;
                 descrepicount = descrepicount + 1;
                 }
 
                 
                  if(descrepicount >= 2){
                Serial.println();
                 descrepicount = 0;
              }
  }
  }
  
   for (int b = 0; b < 16; b++){
    
     
               if(mux0arraycheck[b] != mux0array[b]){
                 if(lastprinted != b || descrepicount == 0){
                Serial.print((squares[b + 16]));
                 lastprinted = b;
                 descrepicount = descrepicount + 1;
                 }
                 
                 
                 
                  if(descrepicount >= 2){
                Serial.println();
                 descrepicount = 0;
              }
                 
               }
      }
      
         for (int b = 0; b < 16; b++){
               if(mux1arraycheck[b] != mux1array[b]){
                  if(lastprinted != b || descrepicount == 0){
                 Serial.print((squares[b + 32]));
                 lastprinted = b;
                   descrepicount = descrepicount + 1;
                  }
               
                 
                  if(descrepicount >= 2){
                Serial.println();
                 descrepicount = 0;
              }
               }
      }
         for (int b = 0; b < 16; b++){
               if(mux2arraycheck[b] != mux2array[b]){
                  if(lastprinted != b || descrepicount == 0){
                 Serial.print((squares[b + 48]));
                 lastprinted = b;
                 descrepicount = descrepicount + 1;
                  }
                 
                 
                  if(descrepicount >= 2){
                Serial.println();
                descrepicount = 0;
              }
                 
               }
      }
      
        
      ////////////////////////////////////////////////  
  
    for (int b = 0; b < 16; b++){
		digitalpinscheck[b] = digitalpins[b];
      }
  
   for (int b = 0; b < 16; b++){
		mux2arraycheck[b] = mux2array[b];
      }
      
    for (int b = 0; b < 16; b++){
		mux1arraycheck[b] = mux1array[b];
      }
      
    for (int b = 0; b < 16; b++){
		mux0arraycheck[b] = mux0array[b];
      }
    //////////////////////////////////////////////


      



}
/*
 //DEBUG    
  //The following lines are for printing out results of the internal pins
   Serial.print("internal pins: ");
  for (int i=0; i<16; i++)
  {
    Serial.print(digitalpins[i]);
    Serial.print(",");
  }
  Serial.println();  //line feed
  
  
  
  //The following lines are for printing out results of array0
  Serial.print("mux0array: ");
  for (int i=0; i<16; i++)
  {
    Serial.print(mux0array[i]);
    Serial.print(",");
    Serial.print(mux0array[i]);
    Serial.print(",");
  }
  Serial.println();  //line feed
  
  
  //The following lines are for printing out results of array1
  Serial.print("mux1array: ");
  for (int i=0; i<16; i++)
  {
    Serial.print(mux1array[i]);
    Serial.print(",");
     Serial.print(mux1array[i]);
    Serial.print(",");
  }
  Serial.println();

  
  //The following lines are for printing out results of array2
  Serial.print("mux2array: ");
  for (int i=0; i<16; i++)
  {
    Serial.print(mux2array[i]);
    Serial.print(",");
     Serial.print(mux2array[i]);
    Serial.print(",");
  }
  Serial.println();
   delay(1000);
}
*/

I wish you can help me in anyway so I could compile and load it to my ATMEGA 1281. Thank you in advance. :slight_smile:

How are you selecting 1281 for a board type?

I accidentally bought 1281 instead of a 1280. Too bad for me. I am going to wait for the store to have the board I need, it would take time. It would be also cost efficient if I would just be able to adjust the program.

Can you help me? It would be highly appreciated, Sir!

So you bought the wrong chip? http://www.atmel.com/Images/2549S.pdf 1280 has 100 pins, 1281 has 64 pins. I am not aware of any board that uses it yet, so its not clear to me how you are selecting it in the IDE to compile for it. Please explain.

I bought an Arduino software compatible board and I did not notice that it was using a 1281 chip. When I try to compile the program, it gives me error warnings and I google whats wrong. Eventually, I think what I need is a board with a 1280 chip.

Thank you sir! :)

Ok, so you went into boards.txt and made a section like this:

########Added for testing ##################################

mega1281.name=Arduino Mega (ATmega1281)

mega1281.upload.protocol=arduino
mega1281.upload.maximum_size=126976
mega1281.upload.speed=57600

mega1281.bootloader.low_fuses=0xFF
mega1281.bootloader.high_fuses=0xDA
mega1281.bootloader.extended_fuses=0xF5
mega1281.bootloader.path=atmega
mega1281.bootloader.file=ATmegaBOOT_168_atmega1280.hex
mega1281.bootloader.unlock_bits=0x3F
mega1281.bootloader.lock_bits=0x0F

mega1281.build.mcu=atmega1281
mega1281.build.f_cpu=16000000L
mega1281.build.core=arduino
mega1281.build.variant=mega

and when you select that board type & compile you get these errors:

C:\Arduino-1.0.2\libraries\SoftwareSerial\SoftwareSerial.cpp:59: warning: only initialized variables can be placed into program memory area
C:\Arduino-1.0.2\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)':
C:\Arduino-1.0.2\libraries\SoftwareSerial\SoftwareSerial.cpp:399: error: 'PCMSK2' was not declared in this scope
C:\Arduino-1.0.2\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::end()':
C:\Arduino-1.0.2\libraries\SoftwareSerial\SoftwareSerial.cpp:414: error: 'PCMSK2' was not declared in this scope

Yet when you select Atmega1280 you don't get the errors. I can duplicate this in 1.0.2, I don't understand the error tho.

Is there any way so I can compile the program to my 1281? I do not understand the error. And I actually do not know what to do now to make this work using my 1281.

BTW, this is the error I got when I tried to load the program:

C:\Users\nikki\Desktop\chessdox\arduino-1.0.1\arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp: In member function 'void SoftwareSerial::begin(long int)': C:\Users\nikki\Desktop\chessdox\arduino-1.0.1\arduino-1.0.1\libraries\SoftwareSerial\SoftwareSerial.cpp:398: error: expected `;' before ')' token

I am using arduino 1.0.1 for the compiler for now. Thank you very much, Sir!

I do not know. Perhaps send a PM to CodingBadly, ask him to review this thread.

CrossRoads:
Perhaps send a PM to CodingBadly, ask him to review this thread.

Coding Badly. Coding Badly. Coding Badly. (with apologies to Tim Burton) :smiley:

A “pin mapping” file for the processor is located in the “variants” directory…
{Arduino IDE Root Director}\hardware\arduino\variants\

For the “mega” boards, the pin mapping file is located here…
{Arduino IDE Root Director}\hardware\arduino\variants\mega\pins_arduino.h

In the pin mapping file is a macro that maps a pin number to a Pin Change Mask Register (PCMSKn)…

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

That macro is used by SoftwareSerial to enable pin change interrupts for the receive pin. The macro references two Pin Change Mask Register: PCMSK0 and PCMSK2. The compile is complaining that PCMSK2 does not exist. There are two possibilities…

  1. PCMSK2 really does not exist for your processor (ATmega1281)

  2. PCMSK2 is not defined in the AVR-Libc header files

In either case, it does not make much difference. You are using pin 10 for receive which maps to PCMSK0. The solution is to copy the pins_arduino.h file from the mega directory into a new directory under variants and remove the reference to PCMSK2.

Sir,

I would greatly appreciate some assistance too.

I have a similar concern. Although my programming skills are VERY limited. Is there a way for me to alter this code for my Arduino compatible board?

The code may be downloaded at Download - Firmata

The code is the latest: Firmata 2.3.6

I tried posting the code but it is too large.

I have attached a screen capture of the error generated by the IDE.

Thank you very much.