Daisy Seed Arduino development in VSCode?

Hi!
Coming from Arduino, and just bought my first Daisy Seed. Im used to Arduino and the IDE. However, I would like to use VS Code instead, but maybe not ready to do the full transition to C++. I would like to continue code Arduino style, but not in Arduino IDE. I’ve seen examples of ppl using VSCode + PlatformIO to program the Daisy Seed. But whatever I try, I can’t get it to work. The guides/howtos/videos are quite limited in detail, so my question is this:

Are there any good/simple instructions on how to get VS Code to work with Daisy Seed and the Arduino framework?

Thanks!

Hello Olle!

Ok, I didn’t have PlatformIO setup BUT I’ll set it up and get it working with DaisyDuino right now.

Please note that I juuuuust did this so there might be some unnessary steps and such, but I was able to get it working. I’ll do a more detailed tutorial on this in the future. Thank you for bringing it up!
If anyone with more experience using PlatformIO+DaisyDuino, please feel free to provide feedback. Thanks so much!

I do think it flashes faster than the Arduino IDE :slight_smile:

Ok, let’s get this working!


First, open up VS Code and install “PlatformIO IDE” in the “Extensions”.

After restarting VS Code, click on the ant/alien icon on the left.

“Create New Project” and click on “+ Project” and call it “DaisyBlink” or etc and arbitrary select “ST STM32“F0308DISCOVERY”. And then select “Arduino” as Framework. Click “Finish”.

I don’t know if you have to install STM32Cube but I recommend doing it just in case. I had it installed already.

After creating a new project, VS Code should automatically open up platform.ini. Please replace what’s already there with the following:

[env:electrosmith_daisy]
platform = ststm32
board = electrosmith_daisy
framework = arduino
; ----------
; Everything(?) below this needs to be added to use DaisyDuino in PlatformIO.
; Setting up a new project or importing from Arduino does not add any of this.
; ----------
lib_deps = 
    electro-smith/DaisyDuino@^1.5.2
    Wire 

build_flags = 
    ; -w                            ; optional - to suppress redundant definition warnings
    -D HAL_SDRAM_MODULE_ENABLED     ; required? build fails without this one
    ; These flags enable serial monitor over USB UART
    -D USBD_USE_CDC                 ; Define USB Communications Device Class (for serial I/O)
    -D USBCON                       ; Enable USB connection in Arduino (?)
; This is not documented on PlatformIO website but
; enables the DFU firmware upload (over USB)
upload_protocol = dfu

Thank you Nick (@infrasonicaudio) for this!! I referenced this post.

Open main.cpp in “src”, and copy and paste:

#include <Arduino.h>

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

Click on the checkmark icon on the top right and click “build”. Put Daisy into bootloader mode. And then click “Upload”. And the onboard LED should blink!!

Don’t worry about these “errors”.

dfu-util: Error during download get_status
*** [upload] Error 74

Let’s test audio…
Choose audio example of your choice. Since I have a Pod, I chose the oscillator example:

#include <Arduino.h>

// Title: oscillator
// Description: Control a sine wave freq with a knob
// Hardware: Daisy Seed
// Author: Ben Sergentanis
// Breadboard
// https://raw.githubusercontent.com/electro-smith/DaisyExamples/master/seed/Osc/resources/Osc_bb.png
// Schematic:
// https://raw.githubusercontent.com/electro-smith/DaisyExamples/master/seed/Osc/resources/Osc_schem.png

#include "DaisyDuino.h"

DaisyHardware hw;

size_t num_channels;

static Oscillator osc;

float pitchknob;

void MyCallback(float **in, float **out, size_t size) {
  // Convert Pitchknob MIDI Note Number to frequency
  osc.SetFreq(mtof(pitchknob));
  for (size_t i = 0; i < size; i++) {
    float sig = osc.Process();

    for (size_t chn = 0; chn < num_channels; chn++) {
      out[chn][i] = sig;
    }
  }
}

void setup() {
  float sample_rate;
  // Initialize for Daisy pod at 48kHz
  hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
  num_channels = hw.num_channels;
  sample_rate = DAISY.get_samplerate();

  osc.Init(sample_rate);
  osc.SetFreq(440);
  osc.SetAmp(0.5);
  osc.SetWaveform(osc.WAVE_TRI);

  DAISY.begin(MyCallback);
}

void loop() { pitchknob = 24.0 + ((analogRead(A0) / 1023.0) * 60.0); }

“Build” and then “Upload” and it’s beeping!!

Let me know if you have any questions!!