Arduino Simulation Multipe Source files *ino

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
rkhpd
Professional User
Posts: 3
Joined: Tue 2023-11-07 19:10

Arduino Simulation Multipe Source files *ino

Post by rkhpd »

Good Day,

I created a new project with the following details:

Arduino 328
Arduino board with ATmega328P

Controller
Family: AVR
Device: ATmega328P
Compiler: Arduino AVR

As Source code I added 3 *ino files from my project, which i created with the Arduino IDE.

But compiling failes. I get errors like "was not declared in the scope".
So functions, which I wrote in the second and third *ino file are not availabe in the main *ino.

How can I solve this problem?

PS:With only one *ino file it works.


Thank you
Ettore
Labcenter Staff
Posts: 2931
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Arduino Simulation Multipe Source files *ino

Post by Ettore »

I think you should declare explicitly the prototype of the functions in main.ino. For example given the func1 and func2 in funcs.ino:

Code: Select all

int func1(void) {
static int a;
  return ++a;
}

int func2(void) {
static int b;
  return ++b;
}
You need to do this in your main.ino in order to compile without errors:

Code: Select all

/* Main.ino file generated by New Project wizard
 *
 * Created:   mer nov 8 2023
 * Processor: Arduino Uno
 * Compiler:  Arduino AVR
 */
// ***************************************************************
// ********  Declare the functions prototype in funcs.ino
// ***************************************************************
int func1(void);
int func2(void);

int a, b;

void setup () {

}

void loop() {

  a = func1();
  b = func2();
}
Please send your customer number in to support@labcenter.com so that we will provide you with further support.
Kind regards,
Ettore Arena - Labcenter Electronics.
rkhpd
Professional User
Posts: 3
Joined: Tue 2023-11-07 19:10

Re: Arduino Simulation Multipe Source files *ino

Post by rkhpd »

Thanks for the support, but this solution seams not very practical.

Writing the declarations is ok:

Code: Select all

void led_blinking_off(void);
void serial_receive_string(void);
but I also have to implement all variables which are used in the func1 and func2 manually:

Code: Select all

extern int LED1;
extern int LED2;
extern int LED3;
extern int LED4;
I also not found out, how to implement a SoftwareSerial port in func1 and func2. I tried it with

Code: Select all

extern SoftwareSerial charger;
but doesnt work.

What other options are possible?

I use the Arduino AVR Compiler.
Would the Arduino IDE Version Compiler solve this problem?
I couldnt test it, Download Link inside Proteus doesnt work.
If I install the Arduino IDE manually, Proteus doesnt find the compiler.

On Youtube, I found a lot of videos, importing the arduino library and using the compiled hex file.
But with this solution Im not able to see AVR/Variables window.
Andrew
Labcenter Staff
Posts: 453
Joined: Fri 2006-03-24 15:34
Contact:

Re: Arduino Simulation Multipe Source files *ino

Post by Andrew »

Hello,

In order to have multiple .ino files, you need to create project selecting "Arduino IDE 2" in the Compiler field. I've tested it and everything works just fine, including source level code debugging.

Regards,
Andy
rkhpd
Professional User
Posts: 3
Joined: Tue 2023-11-07 19:10

Re: Arduino Simulation Multipe Source files *ino

Post by rkhpd »

Thanks, now it works fine.

For others, who have the same problem:

Install at least Proteus Version 8.17 (Beta) to use the Arduino IDE 2, important notes:

New Project (New Project Wizard)

Create Firmware Project (Compiler Arduino IDE 2).

Unhook the " Create Quick Start Files" and "Create Peripherals".

Right Click on the "ARDUINO_*" Folder in the left upper corner. Projects Settings.

If you want to use the original Arduino .ino files unhook "Embed Files".

A right click again on the "ARDUINO_*" Folder. Add Files.

At your .ino files.

Now you can use the Arduino IDE 2 and Proteus 8.17 at the same.

Make changes in the Arduino IDE then compile, save or autosave. After that you can directly simulate the code in Proteus.
Post Reply