Go Down

Topic: Problems using I2C_graphical_LCD_display library (N. Gammon) (Read 205 times) previous topic - next topic

Hero_123

Hello


My system: ATMega168pa, 16Mhz, TWI 400kHz,  MCP23017, GLCD 128x64; WIN7 PRO 32 Bit
The fuses are set as follows: EXT 0xF9, HIGH 0xDD, LOW 0xFF, LOCK 0xFF

I use the Arduino IDE to compile and generate the *.hex file without the boot loader as I use an SPI programmer to flash the sw onto my ATMega168pa.

I use always the Arduino IDE 1.8.10 to compile my sw and I experience problems when using Nick Gammon's "I2C_graphical_LCD_display" library.

When I compile the sw Arduino style (with "void setup()" and "void loop()") all is ok and the 128x64 display (hooked up to MCP23017) works perfect (shows messages).

When I compile the sw AVRStudio style (with "int main()) the 128x64 display (hooked up to MCP23017) shows nothing at all and the ATMega168 seems to be frozen.

I can't get that sw working when compiled it with the Arduino IDE using "int main()" instead of "void setup()" and "void loop()" and now I hit the middle stump.

Help/advice would be very much appreciated

I already posted that question at the "avrfreaks.net" Arduino forum "Problems with Library "I2C_graphical_LCD_display" but nobody could explain that behaviour.

Attached is the file "Klaus_01.c"

regards

Hero_123

pert

When I compile the sw AVRStudio style (with "int main()) the 128x64 display (hooked up to MCP23017) shows nothing at all and the ATMega168 seems to be frozen.

I can't get that sw working when compiled it with the Arduino IDE using "int main()" instead of "void setup()" and "void loop()" and now I hit the middle stump.
Here is what the main() function looks like when compiling for any of the Arduino AVR Boards (e.g., Nano, Pro Mini):
https://github.com/arduino/ArduinoCore-avr/blob/1.8.2/cores/arduino/main.cpp#L33-L51
Code: [Select]
int main(void)
{
init();

initVariant();

#if defined(USBCON)
USBDevice.attach();
#endif

setup();
   
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
       
return 0;
}

In this case, the important difference between your main() and the stock main is the call to init(). That does hardware configuration. I don't have the hardware to test, but I suspect this is the cause of your problem.

Attached is the file "Klaus_01.c"
I don't know how you got that to compile. The I2C_graphical_LCD_display library is C++. You can't use C++ library code in a C program.

Hero_123

Hello pert

Thank you for your reply.

I use the Arduino IDE 1.8.10 to compile my "Klaus_01.c" as the I2C lib was written for Arduino.

I'll try the "int main()" which you mentioned in your reply.

regards

Hero_123

pert

I use the Arduino IDE 1.8.10 to compile my "Klaus_01.c" as the I2C lib was written for Arduino.
It doesn't change the fact that the library is C++ and your .c file will be compiled as C. The .ino files of Arduino sketches are compiled as C++, but if you add a .c file to the sketch, that file is compiled as C.

I'll try the "int main()" which you mentioned in your reply.
The rest of the code in the main() function I posted above is not needed, only the call to init(). Try this:
Code: [Select]
int main(void) {
init();
        init_prg(); /* initialisation */
for(;;) {
}
return 0;
}




Hero_123

Hello pert

Thank you very much for your help!

First I tried the "int main()" which you mentioned in your first post (#1) and it did work! Great!

Then I tried the reduced "int main()" of your second post (post #3) and it did work, too! Great!

So now I'll use the reduced "int main()" and Nick Gammon's library is now working, too - great!!

When I edit my source files I use Notepad++ and rename the file extension to ".c" and afterwards I
rename the file extension to ".ino" (when I compile it using the Arduino IDE).

And when I posted my file I thought it better to have it renamed with the extension ".c", but only for the
upload.

regards

Hero_123

pert

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

Go Up