Wire.h not found simulation

When I try to simulate my program I get this error message.

ws/sketchbook/11ef6620bc0fdd90f4af4aa800c928b645053afe35da2367d7faf65e652edaaa/sketch/sketch.ino:984:10: fatal error: ‘Wire.h’ file not found
#include <Wire.h>
^~~~~~~~
1 error generated.
shared:ERROR: ‘/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/bin/clang++ -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=1 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libcxx -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/lib/libcxxabi/include -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/compat -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/libc -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/local/include -DLLVM_ROOT=/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/bin -DARDUINO_WASM_SIMULATION -DARDUINO_ARCH_WASM -O2 -std=c++11 -nostdlib -fno-exceptions -fno-rtti -c -I/tmp/arduino-sketch-8F281F5099F06167E4F580D4E7FBD396/sketch -I/ws/arduino_data/packages/xod/hardware/wasm/0.2.0/cores/simulation -I/ws/arduino_data/packages/xod/hardware/wasm/0.2.0/variants/simulation -DEMSCRIPTEN /tmp/arduino-sketch-8F281F5099F06167E4F580D4E7FBD396/sketch/sketch.ino.cpp -Xclang -isystem/ws/arduino_data/packages/xod/tools/emscripten/1.39.2/emscripten/system/include/SDL -c -o /dev/null -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr’ failed (1)

The generated C++ code contains errors. It can be due to a bad node implementation
or if your board is not compatible with XOD runtime code. The original compiler error
message is above. Fix C++ errors to continue. If you believe it is a bug, report the
problem to XOD developers.

It compiles in the Arduino IDE as expected but I want to try running simulations before I have some of the hardware. Im very new to XOD so it’s entirely possible i’m doing something wrong.

After looking further into the oled library I am working with there is a section for C++ integration which I beleive has something to do with getting this to work.

// Tell XOD where it could download the library:
#pragma XOD require "https://github.com/adafruit/Adafruit_SSD1306"
#pragma XOD require "https://github.com/adafruit/Adafruit-GFX-Library"

//Include C++ libraries
{{#global}}
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
{{/global}}

// Adafruit_SSD1306 class wants to know id and address in the moment of instantiation
// but we don't know them at this moment.
// Therefore, we reserve memory to store an instance of the class,
// and create the instance later:
struct State {
    uint8_t mem[sizeof(Adafruit_SSD1306)];
};

// Define our custom type as a pointer on the class instance.
using Type = Adafruit_SSD1306*;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    // It should be evaluated only once on the first (setup) transaction
    if (!isSettingUp())
        return;

    auto state = getState(ctx);
    auto width = getValue<input_WIDTH>(ctx);
    auto height = getValue<input_HEIGHT>(ctx);
    auto reset_pin = getValue<input_RESET_PIN>(ctx);

    // Create a new object in the memory area reserved previously.
    Type display = new (state->mem) Adafruit_SSD1306(width, height, &Wire, reset_pin);

    // Attempt to initialize display module; if attempt fails emit pulse from error port
    auto address = getValue<input_ADDRESS>(ctx);
    if (!display->begin(SSD1306_SWITCHCAPVCC, address)) {
      raiseError(ctx);
      return;
    }
    emitValue<output_DEV>(ctx, display);
}

The simulator has no way of simulating external devices, so there is no reason for it to have access to Wire.h. You need to replace the device nodes with tweak or watch nodes so simulator knows what to do with them.

1 Like