Programming problem

I compile and connect the program through uno , all is fine even i tested on the components. However when i tried to transfer it to nano. here the error message below which i had not seen before: " fork/exec /Users/lungyankhoo/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino2/bin/avr-g++: bad CPU type in executable

Compilation error: fork/exec /Users/lungyankhoo/Library/Arduino15/packages/arduino/tools/avr-gcc/4.8.1-arduino2/bin/avr-g++: bad CPU type in executable"

what does it mean and what is the fix for it please? thanks

It means you have selected the wrong board. The soloution is to select the correct board.

Without seeing more, like the code you are trying to run, and a schematic of your circuit, it is impossible for us to try it out and therefore help you.

appreciate the prompt reply!
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

int countdownSeconds = 24; // Set countdown time here

void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(7);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);

delay(1000);
}

void loop() {
for (int i = countdownSeconds; i >= 0; i--) {
display.clearDisplay();
display.setCursor(30, 10);

  if (i <10 ) {
 display.clearDisplay();
 display.setCursor(50, 10);  



}
display.print(i);
display.display();
delay(1000);

}
display.clearDisplay();
display.setCursor(0, 20);

delay(5000);
}

below is the code. , just a simple oled countdown seconds clock, however even now i just comply the program, also comes up with this error message before i connect to any uno or nano boards. Thanks!

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

int countdownSeconds = 24; // Set countdown time here

void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(7);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);

delay(1000);
}

void loop() {
for (int i = countdownSeconds; i >= 0; i--) {
display.clearDisplay();
display.setCursor(30, 10);

  if (i <10 ) {
 display.clearDisplay();
 display.setCursor(50, 10);  



}
display.print(i);
display.display();
delay(1000);

}
display.clearDisplay();
display.setCursor(0, 20);

delay(5000);
}

Hi @songoku8.

This error is caused by the GCC compiler build that is distributed by Arduino having been built for the x86 (AKA "Intel") CPU architecture, while the CPU on your Mac has the Apple Silicon architecture.

Fortunately this is not a real problem because Apple provides the Rosetta 2 translator, which allows x86 binaries to run on Apple Silicon machines. You only need to install Rosetta 2 to solve this problem.

You can follow the instructions here to install it:

https://support.arduino.cc/hc/en-us/articles/7765785712156-Error-bad-CPU-type-in-executable-on-macOS#if-your-mac-computer-has-an-apple-silicon-processor

You might want to look at this How to get the best out of this forum before you proceed any further.

It tells you how to post code on this forum. As it is it is difficult to read and almost impossible for us to get it into our machines. The simple way is to select all the code in your sketch and select the "copy for forum" option, and then simply paste it into your reply. You can edit the above reply.

Also what about the schematic I asked about?

Ah, I just noticed the "4.8.1-arduino2". So please ignore my previous comment. The error has a different cause in this specific case:

The cause of the error is that the compiler you are using is a 32-bit application.

Support for such applications was dropped starting from macOS Catalina:

The reason you are experiencing this problem is that you are using an extremely outdated version of the "Arduino AVR Boards" platform that adds support for the Arduino Uno board to Arduino IDE. At the time that version was made, macOS still supported 32-bit applications and so it was sensible for Arduino to use a 32-bit build of the compiler.

Later when Apple dropped support for 32-bit applications, Arduino made a new release of the platform that uses a 64-bit build of the compiler. So the solution is for you to update your "Arduino AVR Boards" installation to a modern version, which will also update the compiler to the 64-bit version. I'll provide instructions you can follow to do that:

  1. Select Tools > Board > Boards Manager from the Arduino IDE menus.
    A "Boards Manager" dialog will appear.
  2. Wait for the updates to finish, as shown by the messages printed at the bottom of the "Boards Manager" dialog.
  3. Scroll down through the list of boards platforms until you find the "Arduino AVR Boards" entry. Click on it.
    Some buttons will appear on the entry.
  4. Click the "Update" button on the "Arduino AVR Boards" entry.
  5. Wait for the update to finish.
  6. Click the "Close" button on the "Boards Manager" dialog.

Now try compiling your sketch again. Hopefully this time there won't be any errors.

Thanks for your information. I followed the steps on updating the AVR boards , and compile the program and comes up with another long error message as below

because the error is far too long, thus i only copy and paste the first few lines., see if you can see the error behind . thanks

/Users/lungyankhoo/Library/Caches/arduino/sketches/D3BE873A646052126921197307BBCB7A/libraries/Adafruit_GFX_Library/Adafruit_GFX.cpp.o (symbol from plugin): In function Adafruit_GFX::writeLine(int, int, int, int, unsigned int)': (.text+0x0): multiple definition of Adafruit_GFX::writeLine(int, int, int, int, unsigned int)'
/Users/lungyankhoo/Library/Caches/arduino/sketches/D3BE873A646052126921197307BBCB7A/libraries/Adafruit_GFX_Library/Adafruit_GFX 2.cpp.o (symbol from plugin):(.text+0x0): first defined here
/Users/lungyankhoo/Library/Caches/arduino/sketches/D3BE873A646052126921197307BBCB7A/libraries/Adafruit_GFX_Library/Adafruit_GFX.cpp.o (symbol from plugin): In function Adafruit_GFX::writeLine(int, int, int, int, unsigned int)': (.text+0x0): multiple definition of Adafruit_GFX::startWrite()'

OK, great. This is progress! The error you are encountering now is completely unrelated to the "bad CPU type in executable" error you had before, so this means you solved the cause of that error. That allowed you to progress to the next unrelated problem.

The new problem is caused by a duplicate copy of one of the "Adafruit GFX Library" library's source files file having been created. This seems to happen sometimes when you are using iCloud. I think you can solve easily by reinstalling a fresh copy of the library. I'll provide instructions you can follow to do that:

  1. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE menus to open the "Library Manager" view in the left side panel.
  2. Type Adafruit GFX Library in the "Filter your search..." field.
  3. Find the "Adafruit GFX Library" entry in the list of search results.
  4. Hover the mouse pointer over the "Adafruit GFX Library" entry.
  5. You will see a ●●● icon appear near the top right corner of the library entry. Click on that icon.
    A context menu will open.
  6. Select "Remove" from the menu.
    An "Uninstall" dialog will open.
  7. Click the "YES" button in the "Uninstall" dialog to confirm that you want to uninstall the library.
    The dialog will close.
  8. Wait for the uninstall process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully uninstalled library ...

  9. Select the newest version from the drop-down version menu at the bottom of the "Adafruit GFX Library" entry.
  10. Click the "INSTALL" button at the bottom of the "Adafruit GFX Library" entry.
    An "Install library dependencies" dialog will open.
  11. Click the "INSTALL ALL" button in the "Install library dependencies" dialog.
    The dialog will close.
  12. Wait for the installation process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    ⓘ Successfully installed library ...

Now try compiling or uploading your sketch again. Hopefully this time it will be successful. If not, just post the error output you got and we'll provide further assistance.