Adafruit BusIO library - can't find such file or directory

Hello all!
I have ran into an issue while trying out the adafruit seesaw library. I think the problem is related to library dependency, although I am not certain since I am still a novice.
I think the issue is somewhere with the BusIO, within this library or it’s dependency.
I browsed the forum for similar issues and unfortunately adding #include <SPI.h> does not solve the problem.
I have pasted the message from the terminal below,
I appreciate any help or information regarding this topic,
Thank you in advance kind stranger.

  • The terminal process “C:\Users\Me.platformio\penv\Scripts\platformio.exe ‘run’” terminated with exit code: 1.

  • Terminal will be reused by tasks, press any key to close it.

  • Executing task in folder Light game: C:\Users\Me.platformio\penv\Scripts\platformio.exe run

Processing nano_33_iot (platform: atmelsam; board: nano_33_iot; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Atmel SAM (8.1.0) > NANO 33 IoT
HARDWARE: SAMD21G18A 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (atmel-ice) External (atmel-ice, blackmagic, jlink)
PACKAGES:

  • framework-arduino-samd @ 1.8.13
  • framework-cmsis @ 1.40500.0 (4.5.0)
  • framework-cmsis-atmel @ 1.2.2
  • toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 17 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- Adafruit seesaw Library @ 1.7.0
    |-- SPI @ 1.0
    Building in release mode
    Compiling .pio\build\nano_33_iot\src\main.cpp.o
    Compiling .pio\build\nano_33_iot\lib046\Adafruit BusIO\Adafruit_BusIO_Register.cpp.o
    Compiling .pio\build\nano_33_iot\lib046\Adafruit BusIO\Adafruit_SPIDevice.cpp.o
    src\main.cpp: In function ‘void (* blink(keyEvent))(keyEvent)’:
    src\main.cpp:24:47: error: ‘Wheel’ was not declared in this scope
    trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
    ^~~~~
    src\main.cpp:30:7: error: ‘flash’ was not declared in this scope
    flash(GREEN);
    ^~~~~
    src\main.cpp:30:7: note: suggested alternative: ‘fflush’
    flash(GREEN);
    ^~~~~
    fflush
    src\main.cpp:37:9: error: ‘restart_game’ was not declared in this scope
    restart_game();
    ^~~~~~~~~~~~
    src\main.cpp:40:7: error: ‘flash’ was not declared in this scope
    flash(RED);
    ^~~~~
    src\main.cpp:40:7: note: suggested alternative: ‘fflush’
    flash(RED);
    ^~~~~
    fflush
    src\main.cpp:42:7: error: ‘show_solution’ was not declared in this scope
    show_solution(game_sequence, current_difficulty);
    ^~~~~~~~~~~~~
    src\main.cpp: In function ‘void restart_game()’:
    src\main.cpp:57:3: error: ‘start_game’ was not declared in this scope
    start_game(current_difficulty);
    ^~~~~~~~~~
    src\main.cpp:57:3: note: suggested alternative: ‘restart_game’
    start_game(current_difficulty);
    ^~~~~~~~~~
    restart_game
    src\main.cpp: In function ‘void setup()’:
    src\main.cpp:98:37: error: ‘Wheel’ was not declared in this scope
    trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
    ^~~~~
    src\main.cpp:112:3: error: ‘start_game’ was not declared in this scope
    start_game(current_difficulty);
    ^~~~~~~~~~
    src\main.cpp:112:3: note: suggested alternative: ‘restart_game’
    start_game(current_difficulty);
    ^~~~~~~~~~
    restart_game
    src\main.cpp: In function ‘void start_game(int)’:
    src\main.cpp:121:3: error: ‘show_solution’ was not declared in this scope
    show_solution(game_sequence, level);
    ^~~~~~~~~~~~~
    src\main.cpp: In function ‘void show_solution(int*, int)’:
    src\main.cpp:127:39: error: ‘Wheel’ was not declared in this scope
    trellis.pixels.setPixelColor(led, Wheel(map(led, 0, trellis.pixels.numPixels(), 0, 255)));
    ^~~~~
    *** [.pio\build\nano_33_iot\src\main.cpp.o] Error 1

Please post your platformio.ini and src/main.cpp.

This is the main, it’s just an example code for NeoTrellis I wanted to check out.

/* Small game for Adafruit NeoTrellis
 * Works fine with smaller chips like Nano
*/

#include "Adafruit_NeoTrellis.h"
#include <SPI.h>

Adafruit_NeoTrellis trellis;
#define RED 0xFF00000
#define GREEN 0x00FF000

/*Defines the maximum difficulty (16 patterns in a row)*/
#define MAX_DIFFICULTY 16

int game_sequence[MAX_DIFFICULTY]  = {};
int current_difficulty = 2;
int cur = 0;

//define a callback for key presses
// Release event will trigger the game check
TrellisCallback blink(keyEvent evt){
  // Check is the pad pressed?
  if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
    trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
  } else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
  // or is the pad released?
    trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
    // Check if the pressed button it correct
    if (game_sequence[cur] == evt.bit.NUM){
      flash(GREEN);
      cur++;
      if (cur == current_difficulty){
        flash(GREEN);
        flash(GREEN);
        flash(GREEN);
        cur = 0;
        restart_game();
      }
    } else{
      flash(RED);
      cur = 0;
      show_solution(game_sequence, current_difficulty);
  
    }
    }

  // Turn on/off the neopixels!
  trellis.pixels.show();
  return 0;
}

/*Increse difficulty and restart the game*/
void restart_game(){
  if (current_difficulty <= MAX_DIFFICULTY){
    current_difficulty++;  
  }
  start_game(current_difficulty);
}
/*
 * Flash all leds for a short time
 */
void flash(uint32_t color){
  
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, color);
  }
  trellis.pixels.show();
  delay(200);
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
  
    trellis.pixels.setPixelColor(i, 0x000000);
  }
  trellis.pixels.show();

}

void setup() {
  randomSeed(analogRead(0));
  Serial.begin(9600);
  //while(!Serial);
  
  if (!trellis.begin()) {
    Serial.println("Could not start trellis, check wiring?");
    while(1) delay(1);
  } else {
    Serial.println("NeoPixel Trellis started");
  }

  //activate all keys and set callbacks
  for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
    trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
    trellis.registerCallback(i, blink);
  }

  //do a little animation to show we're on
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
    trellis.pixels.show();
    delay(50);
  }
  delay(50);
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
  
    trellis.pixels.setPixelColor(i, 0x000000);
    trellis.pixels.show();
    delay(50);
  }
  trellis.pixels.show();
  
  delay(1000);
  start_game(current_difficulty);
  
}

void start_game(int level){
  for (int x = 0; x <= level; x++){
    int led = random(trellis.pixels.numPixels());
    game_sequence[x] = led;
  }
  show_solution(game_sequence, level);
}

void show_solution(int solution[], int level){
  for (int x=0; x < level; x++){
    int led = solution[x];
    trellis.pixels.setPixelColor(led, Wheel(map(led, 0, trellis.pixels.numPixels(), 0, 255)));
    trellis.pixels.show();
    delay(500);
    trellis.pixels.setPixelColor(led, 0x000000);
    trellis.pixels.show();
    delay(50);
  }

}

void loop() {
  trellis.read();  // interrupt management does all the work! :)
  delay(20); //the trellis has a resolution of around 60hz
}


/******************************************/

// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }

Here is the .ini code:

; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:nano_33_iot]
platform = atmelsam
board = nano_33_iot
framework = arduino
lib_deps = adafruit/Adafruit seesaw Library @ 1.7.0

You’re trying to use a .ino file as .cpp file without doing the conversion. Either do the conversion per FAQ or rename src/main.cppsrc/main.ino.

Okay, including the Arduino.h did not work, but renaming the file to .ino fixed the issue.
Could you please explain the works behind it?

  1. Add #include <Arduino.h> at the top of the source file

Was only the first step that the FAQ mentioned, exactly as critical is to add the predeclaration of the functions that are auto-generated in the Arduino IDE. Otherwise it’s not valid C++ code at all. See c++ - Why do functions need to be declared before they are used? - Stack Overflow.

1 Like

Looks like I have a long road ahead of me, thank you so much for your help.