Sketch compiles, won't run. Code Structure?

I coded most of my project in Arduino IDE on Win7.
I now need my code to be compiled by a Raspberry Pi using Ino via SSH.
To get Ino to compile, I had to move a lot of code around, add prototypes and add ‘extern’ statements in Globals.h.

The project now compiles by Ino and uploads to the Arduino Mega 2650, but doesn’t run at all.
I get two flashes of the LED on pin 13, then nothing.

My code now doesn’t compile in Arduino IDE on Win7. My pin definements aren’t found for some reason.

My question is, is there a fundemental problem with my project structure?
Have I used header files correctly? In particular, Globals.ino/Globals.h.

I have attached my project files and libraries. They can also be downloaded here:
https://dl.dropboxusercontent.com/u/3730812/Fishtankv2.zip

The #include statements have relative paths to overcome an issue with Ino finding the header files.

I appreciate any help anyone can provide.

Fishtankv2.zip (735 KB)

I see a lot of constant strings, but not many F() macros. What is the platform for this project?

AWOL: I see a lot of constant strings, but not many F() macros. What is the platform for this project?

Sorry I don't understand what you mean by Platform.

It's to be run on an Arduino Mega 2560. Initially developed and working within Arduino IDE. Now to be built/uploaded by Arduino/Ino on Raspbian Linux,

The project takes commands over Serial/USB from the Raspberry Pi. It was working until I started chopping/changing to be build/uploaded on the rPi.

So who has ported the compiler for the avr chips to the Pi? Provide a link.

Mark

holmes4: So who has ported the compiler for the avr chips to the Pi? Provide a link.

Mark

I used Ino, available here: https://pypi.python.org/pypi/ino/

Installation is detailed on page 8/9 of the following online magazine: http://issuu.com/themagpi/docs/issue15final

The compiler takes the source code and produces machine code for the target machine. So you need a compiler (not a build system) that runs on the Pi and produce machine code for the arduino.

Mark

holmes4: The compiler takes the source code and produces machine code for the target machine. So you need a compiler (not a build system) that runs on the Pi and produce machine code for the arduino.

Mark

Yes I understand. I used Arduino for Linux on the rPi, downloaded using 'apt-get install arduino'

hade: It's to be run on an Arduino Mega 2560. Initially developed and working within Arduino IDE. Now to be built/uploaded by Arduino/Ino on Raspbian Linux,

The project takes commands over Serial/USB from the Raspberry Pi. It was working until I started chopping/changing to be build/uploaded on the rPi.

I guess I don't understand the problem. Why do you have to compile it with a Raspberry Pi? Does the Arduino get reprogrammed by the RaspPi while it's in operation?

You say it receives commands from RaspbPi over serial, but that doesn't matter at all to the Arduino. Serial commands are serial commands. Why can't you use the Arduino code that you compile and upload via an Arduino IDE?

Could you show us the original code before you got hacking and chopping at it?

lar3ry:

hade:
It’s to be run on an Arduino Mega 2560.
Initially developed and working within Arduino IDE.
Now to be built/uploaded by Arduino/Ino on Raspbian Linux,

The project takes commands over Serial/USB from the Raspberry Pi.
It was working until I started chopping/changing to be build/uploaded on the rPi.

I guess I don’t understand the problem.
Why do you have to compile it with a Raspberry Pi? Does the Arduino get reprogrammed by the RaspPi while it’s in operation?

You say it receives commands from RaspbPi over serial, but that doesn’t matter at all to the Arduino. Serial commands are serial commands. Why can’t you use the Arduino code that you compile and upload via an Arduino IDE?

Could you show us the original code before you got hacking and chopping at it?

Code before ‘fixes’ linked below. I think this code worked due to Arduino IDE’s automatic prototype generation as I needed very few of them and few header files.

https://dl.dropboxusercontent.com/u/3730812/fishtank-v2-pre-pi-changes.zip

My decision to program the Arduino from the rPi is due to the two being plugged together in the completed project.
It made sense to allow the Arduino to be programmed remotely, in-situ.

However now I’d probably settle with just unplugging and programming with my laptop if necessary.
I feel I must be so close to having this working The fact that it builds and uploads must mean I’m almost there, I just need to get the bastard to run again!

and add 'extern' statements in

An extern still has to have a real declaration for example

extern int myExtern; in one file still needs an

int myExtern=123; in another file.

The c/c++ compilers work on one file at a time the result is a .o file. The .o are then linked. So adding an extern will get it passed the compiler but the code without the real declaration will be rubbish. You should have solved your problems by including the write .h files.

The linker should have warned you of this but warning are turned off so ....

Mark

Mark

holmes4:

and add 'extern' statements in

An extern still has to have a real declaration for example

extern int myExtern; in one file still needs an

int myExtern=123; in another file.

The c/c++ compilers work on one file at a time the result is a .o file. The .o are then linked. So adding an extern will get it passed the compiler but the code without the real declaration will be rubbish. You should have solved your problems by including the write .h files.

The linker should have warned you of this but warning are turned off so ....

Mark

Mark

Thank you, but every single Extern declaration in Globals.h has a corresponding variable declaration in Globals.ino. Or have you spotted something I have missed? What did you mean by 'warning are turned off'? Is this a config setting for the compiler? I've not seen an Ino switch to enable warnings. Can you please recommend a course of action?

but every single Extern declaration in Globals.h has a corresponding variable declaration in Globals.ino.

Where /how did you find the defaults/initialization values for these?

What did you mean by 'warning are turned off'? Is this a config setting for the compiler?

Yes its a switch on the command line - try alook at nick gamons site.

Mark

Where /how did you find the defaults/initialization values for these?

Sorry I don’t understand. The default values are set at the declaration, in Globals.ino.
Globals.h is included in every other file. Shouldn’t that make the variables available to every other .ino file?
I can’t understand why Arduino IDE on Win7 complains that it can’t find my pin assignment variables.

Yes its a switch on the command line - try alook at nick gamons site.

Just took a look, looks like a lot of good content on there thank you.

EDIT:
I fixed the relative paths and renamed all the extra .ino files to .cpp.
Please try compiling the project in Arduino IDE:
https://dl.dropboxusercontent.com/u/3730812/Fishtankv2-cppfiles-includepaths.zip

I don’t understand why I’m seeing these errors. Any ideas?

Eeprom.cpp: In function 'void initEeprom()':
Eeprom.cpp:10: error: 'matrixFullBrightness' was not declared in this scope
Eeprom.cpp:10: error: 'EEPROM' was not declared in this scope
Eeprom.cpp:10: error: 'matrixFullBrightnessAddr' was not declared in this scope
Eeprom.cpp:11: error: 'lightLevel' was not declared in this scope
Eeprom.cpp:11: error: 'lightLevelAddr' was not declared in this scope
Eeprom.cpp:12: error: 'timeOnHour' was not declared in this scope
Eeprom.cpp:12: error: 'timeOnHourAddr' was not declared in this scope
Eeprom.cpp:13: error: 'timeOnMinute' was not declared in this scope
Eeprom.cpp:13: error: 'timeOnMinuteAddr' was not declared in this scope
Eeprom.cpp:14: error: 'timeOffHour' was not declared in this scope
Eeprom.cpp:14: error: 'timeOffHourAddr' was not declared in this scope
Eeprom.cpp:15: error: 'timeOffMinute' was not declared in this scope
Eeprom.cpp:15: error: 'timeOffMinuteAddr' was not declared in this scope
Eeprom.cpp:17: error: 'autoFeedEnabled' was not declared in this scope
Eeprom.cpp:17: error: 'autoFeedEnabledAddr' was not declared in this scope
Eeprom.cpp:18: error: 'autoFeedHour' was not declared in this scope
Eeprom.cpp:18: error: 'autoFeedHourAddr' was not declared in this scope
Eeprom.cpp:19: error: 'autoFeedMinute' was not declared in this scope
Eeprom.cpp:19: error: 'autoFeedMinuteAddr' was not declared in this scope
Eeprom.cpp:21: error: 'voiceVolume' was not declared in this scope
Eeprom.cpp:21: error: 'voiceVolumeAddr' was not declared in this scope
Eeprom.cpp: At global scope:
Eeprom.cpp:26: error: variable or field 'eepromWrite' declared void
Eeprom.cpp:26: error: 'uint8_t' was not declared in this scope
Eeprom.cpp:26: error: 'uint8_t' was not declared in this scope
Eeprom.cpp:31: error: 'uint8_t' does not name a type

They all look like a missing .h try searching for a .h that contains 'matrixFullBrightness' and include it.

Mark

holmes4:
They all look like a missing .h try searching for a .h that contains ‘matrixFullBrightness’ and include it.

Mark

It was included :slight_smile:

I’ve made some discoveries:
One of the reasons Arduino IDE was kicking off is this erroneous function declaration:

void matrixScrollMessage(char message[], int8_t speed = 150, int8_t fontSize = 2){}

This used to build, upload and work fine, but now it doesn’t. Had to change it to this (ie. remove default values):

void matrixScrollMessage(char message[], int8_t speed, int8_t fontSize){}

I’d imagine function overloading may be the way to achieve default values.

I also learned that this:

#include <header.h>

will cause the compiler to look in the standard path for libraries, but this:

#include "header.h"

Will cause it to look in your project directory first, then fallback to standard path.

It now compiles in Arduino IDE. I’ll see if Ino starts playing ball, or just use Arduino IDE from here on in.

Thank you for your assistance and suggestions. Your support is what makes this community exist. Without your help, many many people would give up electronics and coding altogether. Each and everyone of you are fantastic, so thank you.