I have been using Arduino for the past 2 years and created some very complex projects interfacing with the Blynk app.
Then suddenly yesterday I get the following compiler error. I added 4 lines of code to a program that has been compiled, loaded and run for more than a year. I take out the 4 lines and it compiles fine. I put them back and bingo. I uninstalled everything, downloaded the latest of everything I used and re-installed the IDE and all libraries. No solution:
I use W10 with all the latest updates and an Arduino Mega 2560.
In function 'global constructors keyed to 65535_0_LoadSchedWiFi.ino.cpp.o':
lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status
This bug is specific to the 5.4.0-atmel3.6.1-arduino2 version of avr-gcc used by Arduino AVR Boards 1.6.22 and newer. It has been reported here:
Here's the traditional workaround:
Tools > Board > Boards Manager
Wait for downloads to finish.
When you move the mouse pointer over "Arduino AVR Boards", you will see a "Select version" dropdown menu appear. Select "1.6.21".
Click "Install".
Wait for installation to finish.
Click "Close".
Due to a bug, this workaround doesn't work with Arduino IDE 1.8.6, but it will work with any other version of the Arduino IDE.
If you have File > Preferences > Check for updates on startup checked, the Arduino IDE may occasionally notify you that a new version of Arduino AVR Boards is available, you'll need to refrain from updating back to the new Arduino AVR Boards version, otherwise you'll be back to seeing the segmentation fault error again.
Alternate workaround:
One of the Arduino developers recently worked on this and claims to have fixed it. There is a special beta testing hardware package you can install via the Arduino IDE's Boards Manager that has the fix:
If you already have an additional Boards Manager URL in that field, you can separate multiple URLs with commas or click the button on the right side of the field to open a dialog that allows you to add each on its own line.
Thanks pert: I followed the second option and used the url. The versions are slightly different but it seems to work now. I will test on job site computers that have been driving me nuts during the week and report if I find something else.
When you move the mouse pointer over "Arduino AVR Boards", you will see a "Select version" dropdown menu appear. Select "1.6.21".
Click "Install".
Wait for installation to finish.
Click "Close".
Due to a bug, this workaround doesn't work with Arduino IDE 1.8.6, but it will work with any other version of the Arduino IDE.
If you have File > Preferences > Check for updates on startup checked, the Arduino IDE may occasionally notify you that a new version of Arduino AVR Boards is available, you'll need to refrain from updating back to the new Arduino AVR Boards version, otherwise you'll be back to seeing the segmentation fault error again.
Alternate workaround:
One of the Arduino developers recently worked on this and claims to have fixed it. There is a special beta testing hardware package you can install via the Arduino IDE's Boards Manager that has the fix:
If you already have an additional Boards Manager URL in that field, you can separate multiple URLs with commas or click the button on the right side of the field to open a dialog that allows you to add each on its own line.
I mean that the workaround works with any version of the Arduino IDE other than 1.8.7. The Segmentation fault issue could occur with any version of the Arduino IDE. It has nothing to do with the Arduino IDE version. It's about the Arduino AVR Boards version.
I was having the segmentation fault problem last December. Luckily I found your work around about going back to 1.6.21. It fixed the problem. But I have just recently encountered a similar problem. I wrote a sketch exercising the various commands of the Adafruit OLED library. Everything was proceeding nicely, until a couple of days ago, when I added a function to print an entire buffer to the OLED device. The function is not called on entry to the program. I typed in the function call and compiled the program with no errors. Upon running the program, the Adafruit initialization failed. I tested the OLED hardware with other programs and found no problem. So I backtracked to the last thing I did before the failure. I commented out the line containing the function call I had just entered and recompiled. Everything worked fine. This is very similar to the old segmentation fault. Before your fix, I fixed them by adding code around the code that was causing the fault. Could the segmentation fault problem still be in 1.6.21 and is simply not reported as an error? I was just wondering if anybody else has encountered a similar situation.
If it compiles, it's not related to the segmentation fault of this thread.
Any chance that you're running low on memory? Be aware that a function that uses lots of space with local variables is not reported in the IDE's memory usage statistics.
The compiled statistics for the sketch is 18014 bytes (58%) program storage, 908 bytes (44%) of memory. The function dumps a buffer already filled by keyboard input to the OLED device. It is a rather low level function adding a byte and integer value. Just now, as an experiment, I commented out the function and created a null function call to satisfy the compiler. Stats, 17310 and 846. Code does now work. I am stumped. I have written other much larger sketches, that reported a warning of low memory, but still worked. I have included the function just for clarity as to how minor an addition it is.
// ================= write_buffer_to_oled =============== //
void write_buffer_to_oled() {
uint8_t oled_row = 0;
uint16_t oled_index = 0;
oled.clearDisplay();
set_oled_cursor(HOME_COL, HOME_ROW);
for (uint8_t r = 0; r < row_cnt; r++, oled_row++) {
col_cnt = line_lengths[r];
if (col_cnt == 0) { // null line, go to next line.
set_oled_cursor(oled_row, col_cnt);
continue;
}
for (uint8_t s = 0; s < col_cnt; s++) { // print line of 'col_cnt' chars.
uint8_t x = buffer[oled_index++];
set_oled_cursor(oled_row, col_cnt);
oled.print(x);
oled.display(); // for debugging
}
}
oled.display();
}
I wanted to thank you for your reply and for steering me in the right direction. I think you were right on the problem, low memory. The Adafruit library must use a lot of local variable space, as my program does not. I went looking for a stripped down OLED ASCII text library. I found a gem created by Bill Greiman, called SSD1306Ascii. It uses about 3K of program storage and 107 bytes of RAM.
Your comment: "Be aware that a function that uses lots of space with local variables is not reported in the IDE's memory usage statistics." is something I knew nothing about.
I don't know if you're need for vertical and horizontal line drawing involves draw a box on the OLED, but I knocked out some quick code to do such a thing. The cp437font8x8 has drawing characters included.
I hope this was what you were looking for.
Reg Mason
// ****************** //
// *** draw_a_box *** // 4/6/19
// ****************** //
#include<Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiWire oled;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
uint16_t char_width;
uint16_t char_height;
// current character cursor location:
uint8_t cursor_row;
uint8_t cursor_col;
// current cursor location in pixels:
uint16_t cursor_row_pixels; // = cursor_row*char_height;
uint16_t cursor_col_pixels; // = cursor_col*char_width;
// ========= setup ===================== //
void setup() {
Wire.begin();
Wire.setClock(400000L);
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
oled.setFont(cp437font8x8);
char_width = oled.fontWidth();
char_height = oled.fontHeight();
#define N_ROWS SCREEN_HEIGHT/char_height
#define N_COLS SCREEN_WIDTH/char_width
draw_a_box();
}
// ============= loop =================== //
void loop() {}
// ================ draw_a_box() ========== //
// Draw a box below the yellow upper two lines.
#define UL 218
#define UR 191
#define LL 192
#define LR 217
#define HL 196
#define VL 179
void draw_a_box() {
oled.clear();
set_oled_cursor(2,0); // print upper left corner
oled.write(UL);
set_oled_cursor(2,1); // print top horizontal line
for (uint8_t i = 1; i <= 14; i++) {
oled.write(HL);
}
set_oled_cursor(2,15); // print upper right corner
oled.write(UR);
for (uint8_t i = 3; i <= 6; i++) { // print right vertical line
set_oled_cursor(i,15);
oled.write(VL);
}
set_oled_cursor(7,15); // print lower right corner
oled.write(LR);
set_oled_cursor(7,1); // print bottom horizontal line
for (uint8_t i = 1; i <= 14; i++) {
oled.write(HL);
}
set_oled_cursor(7,0); // print lower left corner
oled.write(LL);
for (uint8_t i = 3; i <= 6; i++) { // print left vertical line
set_oled_cursor(i,0);
oled.write(VL);
}
}
// ========================== set_oled_cursor ================== //
// My OLED set cursor command. Converts character row, col to OLED pixel values.
// ************************** implementation note ****************** //
// SSD1306Ascii.h 'setCursor' command wants column in pixels and row as a
// number from 1 to 8. Go figure.
// ***************************************************************** //
void set_oled_cursor(uint8_t row, uint8_t col) {
cursor_row = row;
cursor_col = col;
cursor_col_pixels = col*char_width;
oled.setCursor(cursor_col_pixels,cursor_row);
}
I don't know if you're need for vertical and horizontal line drawing involves draw a box on the OLED, but I knocked out some quick code to do such a thing. The cp437font8x8 has drawing characters included.
I hope this was what you were looking for.
Reg Mason
Not quite what I was after. Hoping for all points addressable line drawing in order to draw small bar charts and diagonal lines would be the cream on the top. On the same idea being able to place the text at a finer resolution than rows and columns... and rotated.
Sounds like its getting big again and I've already reduced the character set by half to save space.
Thank you very much Pert, I was getting error when I wanted to use more than one analogWrite with 1.6.23 version in my project. The problem has improved with version 1.6.21, thank you very much.