0

Trinket M0 light goggles
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Trinket M0 light goggles

by Hethacker on Mon Apr 15, 2019 8:53 pm

Hey,

I have been trying to convert the LED light goggles program to the trinket M0 from the original trinket program, but I have not been having luck. has anyone already tried this and has changed the program to work? I have tried updating and installing all of the files on the trinket M0 but no luck. It says on circuit python that there is a syntax error for the code "void setup" so I think I am missing something here...

main.py output:
Traceback (most recent call last):
File "main.py", line 73
SyntaxError: invalid syntax


Line 73 is: void setup() {


thank you for the help

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by franklin97355 on Mon Apr 15, 2019 10:27 pm

Are you trying to run the Arduino c code on a python enabled M0? What code are you trying to upload?

franklin97355
 
Posts: 20765
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket M0 light goggles

by Hethacker on Tue Apr 16, 2019 2:53 pm

yes, I am trying to run the arduino code from bluetooth goggles sketch. the code worked for the Trinket Pro when I tried it, and I tried using the same one, copied form arduino and put into circuit python through Mu editor.

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by franklin97355 on Tue Apr 16, 2019 3:50 pm

You would need to rewrite the code for Python to understand it. Arduino C code does not use the same syntax as Python.

franklin97355
 
Posts: 20765
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket M0 light goggles

by Hethacker on Wed Apr 17, 2019 12:00 am

Ah, that makes sense then. Okay, well going back to the normal way of programming the board, I am using the trinket M0 with arduino programming to keep the same program used with the trinket pro and changing the tools to configure it to:

board: adafruit Trinket M0
port: COM 10
programmer: tiny ISP

Arduino AVR, SAM, SAMD boards installed and updated to their latest files
adafruit AVR and SAMD boards installed and updated to their latest files

This is the error that I always get:

fatal error: core_cm0plus.h: No such file or directory

#include <core_cm0plus.h>

^

compilation terminated.

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by franklin97355 on Wed Apr 17, 2019 12:20 am

Can you post the link to the sketch you are running?

franklin97355
 
Posts: 20765
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket M0 light goggles

by Hethacker on Wed Apr 17, 2019 12:25 am

Code: Select all | TOGGLE FULL SIZE
#include <SoftwareSerial.h>

// Bluetooth Goggles Sketch -- shows the Adafruit Bluefruit LE UART Friend
// can be used even with Trinket or Gemma!

// https://www.adafruit.com/products/2479

// Works in conjunction with Bluefruit LE Connect app on iOS or Android --
// pick colors or use '1' and '2' buttons to select pinwheel or sparkle modes.
// You can try adding more, but space is VERY tight...helps to use Arduino IDE
// 1.6.4 or later; produces slightly smaller code than the 1.0.X releases.

// BLUEFRUIT LE UART FRIEND MUST BE SWITCHED TO 'UART' MODE

#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
#include <avr/power.h>
#endif

#define RX_PIN    0 // Connect this Trinket pin to BLE 'TXO' pin
#define CTS_PIN   1 // Connect this Trinket pin to BLE 'CTS' pin
#define LED_PIN   2 // Connect NeoPixels to this Trinket pin
#define NUM_LEDS 42 // Two 16-LED NeoPixel rings
#define FPS      30 // Animation frames/second (ish)

SoftwareSerial    ser(RX_PIN, -1);
Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN);

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  // MUST do this on 16 MHz Trinket for serial & NeoPixels!
  clock_prescale_set(clock_div_1);
#endif
  // Stop incoming data & init software serial
  pinMode(CTS_PIN, OUTPUT); digitalWrite(CTS_PIN, HIGH);
  ser.begin(9600);

  pixels.begin(); // NeoPixel init
  // Flash space is tight on Trinket/Gemma, so setBrightness() is avoided --
  // it adds ~200 bytes.  Instead the color picker input is 'manually' scaled.
}

uint8_t  buf[3],              // Enough for RGB parse; expand if using sensors
         animMode = 0,        // Current animation mode
         animPos  = 0;        // Current animation position
uint32_t color    = 0x400000, // Current animation color (red by default)
         prevTime = 0L;       // For animation timing

void loop(void) {
  int      c;
  uint32_t t;

  // Animation happens at about 30 frames/sec.  Rendering frames takes less
  // than that, so the idle time is used to monitor incoming serial data.
  digitalWrite(CTS_PIN, LOW); // Signal to BLE, OK to send data!
  for (;;) {
    t = micros();                            // Current time
    if ((t - prevTime) >= (1000000L / FPS)) { // 1/30 sec elapsed?
      prevTime = t;
      break;                                 // Yes, go update LEDs
    }                                        // otherwise...
    if ((c = ser.read()) == '!') {           // Received UART app input?
      while ((c = ser.read()) < 0);          // Yes, wait for command byte
      switch (c) {
        case 'B':       // Button (Control Pad)
          if (readAndCheckCRC(255 - '!' - 'B', buf, 2) & (buf[1] == '1')) {
            buttonPress(buf[0]); // Handle button-press message
          }
          break;
        case 'C':       // Color Picker
          if (readAndCheckCRC(255 - '!' - 'C', buf, 3)) {
            // As mentioned earlier, setBrightness() was avoided to save space.
            // Instead, results from the color picker (in buf[]) are divided
            // by 4; essentially equivalent to setBrightness(64).  This is to
            // improve battery run time (NeoPixels are still plenty bright).
            color = pixels.Color(buf[0] / 4, buf[1] / 4, buf[2] / 4);
          }
          break;
        case 'Q':       // Quaternion
          skipBytes(17); // 4 floats + CRC (see note below re: parsing)
          break;
        case 'A':       // Accelerometer
#if 0
          // The phone sensors are NOT used by this sketch, but this shows how
          // they might be read.  First, buf[] must be delared large enough for
          // the expected data packet (minus header & CRC) -- that's 16 bytes
          // for quaternions (above), or 12 bytes for most of the others.
          // Second, the first arg to readAndCheckCRC() must be modified to
          // match the data type (e.g. 'A' here for accelerometer).  Finally,
          // values can be directly type-converted to float by using a suitable
          // offset into buf[] (e.g. 0, 4, 8, 12) ... it's not used in this
          // example because floating-point math uses lots of RAM and code
          // space, not suitable for the space-constrained Trinket/Gemma, but
          // maybe you're using a Pro Trinket, Teensy, etc.
          if (readAndCheckCRC(255 - '!' - 'A', buf, 12)) {
            float x = *(float *)(&buf[0]),
                  y = *(float *)(&buf[4]),
                  z = *(float *)(&buf[8]);
          }
          // In all likelihood, updates from the buttons and color picker
          // alone are infrequent enough that you could do without any mention
          // of the CTS pin in this code.  It's the extra sensors that really
          // start the firehose of data.
          break;
#endif
        case 'G':       // Gyroscope
        case 'M':       // Magnetometer
        case 'L':       // Location
          skipBytes(13); // 3 floats + CRC
      }
    }
  }
  digitalWrite(CTS_PIN, HIGH); // BLE STOP!

  // Show pixels calculated on *prior* pass; this ensures more uniform timing
  pixels.show();

  // Then calculate pixels for *next* frame...
  switch (animMode) {
    case 0: // Pinwheel mode
      for (uint8_t i = 0; i < NUM_LEDS / 2; i++) {
        uint32_t c = 0;
        if (((animPos + i) & 7) < 2) c = color; // 4 pixels on...
        pixels.setPixelColor(   i, c);         // First eye
        pixels.setPixelColor(NUM_LEDS - 1 - i, c); // Second eye (flipped)
      }
      animPos++;
      break;
    case 1: // Sparkle mode
      pixels.setPixelColor(animPos, 0);     // Erase old dot
      animPos = random(NUM_LEDS);           // Pick a new one
      pixels.setPixelColor(animPos, color); // and light it
      break;
  }
}

boolean readAndCheckCRC(uint8_t sum, uint8_t *buf, uint8_t n) {
  for (int c;;) {
    while ((c = ser.read()) < 0); // Wait for next byte
    if (!n--) return (c == sum); // If CRC byte, we're done
    *buf++ = c;                  // Else store in buffer
    sum   -= c;                  // and accumulate sum
  }
}

void skipBytes(uint8_t n) {
  while (n--) {
    while (ser.read() < 0);
  }
}

void buttonPress(char c) {
  pixels.clear(); // Clear pixel data when switching modes (else residue)
  switch (c) {
    case '1':
      animMode = 0; // Switch to pinwheel mode
      break;
    case '2':
      animMode = 1; // Switch to sparkle mode
      break;
    case '3':
      break;
    case '4':
      break;
    case '5': // Up
      break;
    case '6': // Down
      break;
    case '7': // Left
      break;
    case '8': // Right
      break;
  }
}
Last edited by franklin97355 on Wed Apr 17, 2019 1:06 am, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by adafruit_support_mike on Wed Apr 17, 2019 1:20 am

For starters, you can get rid of the SoftwareSerial interface. The Trinket M0 has a free hardware Serial interface identified as Serial1 in code, and that works much better than SoftwareSerial.

See if that gets rid of the compiler error, and if not, delete your whole Arduino15 folder and reinstall the board support packages from scratch. That kind of problem usually means an older file didn't get deleted properly, which can happen during updates.. especially if you happen to skip a version. It's easier to start over from scratch than to try and trace the source of the problem.

adafruit_support_mike
 
Posts: 57856
Joined: Thu Feb 11, 2010 2:51 pm

Re: Trinket M0 light goggles

by Hethacker on Wed Apr 17, 2019 3:44 pm

Okay, I replaced the serial portion, I removed the library files, uninstalled arduino and reinstalled arduino and the newest libraries. when I ran the code this time I got this error:

Using core 'arduino' from platform in folder: C:\Users\h\Documents\ArduinoData\packages\adafruit\hardware\samd\1.3.0
Detecting libraries used...
recipe.preproc.macros pattern is missing

Error compiling for board Adafruit Trinket M0.

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by Hethacker on Wed Apr 17, 2019 3:44 pm

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
#include <avr/power.h>
#endif

#define RX_PIN    0 // Connect this Trinket pin to BLE 'TXO' pin
#define CTS_PIN   1 // Connect this Trinket pin to BLE 'CTS' pin
#define LED_PIN   2 // Connect NeoPixels to this Trinket pin
#define NUM_LEDS 42 // Two 16-LED NeoPixel rings
#define FPS      30 // Animation frames/second (ish)

Serial1(RX_PIN, -1);
Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN);

void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  // MUST do this on 16 MHz Trinket for serial & NeoPixels!
  clock_prescale_set(clock_div_1);
#endif
  // Stop incoming data & init software serial
  pinMode(CTS_PIN, OUTPUT); digitalWrite(CTS_PIN, HIGH);
  ser.begin(9600);

  pixels.begin(); // NeoPixel init
  // Flash space is tight on Trinket/Gemma, so setBrightness() is avoided --
  // it adds ~200 bytes.  Instead the color picker input is 'manually' scaled.
}

uint8_t  buf[3],              // Enough for RGB parse; expand if using sensors
         animMode = 0,        // Current animation mode
         animPos  = 0;        // Current animation position
uint32_t color    = 0x400000, // Current animation color (red by default)
         prevTime = 0L;       // For animation timing

void loop(void) {
  int      c;
  uint32_t t;

  // Animation happens at about 30 frames/sec.  Rendering frames takes less
  // than that, so the idle time is used to monitor incoming serial data.
  digitalWrite(CTS_PIN, LOW); // Signal to BLE, OK to send data!
  for (;;) {
    t = micros();                            // Current time
    if ((t - prevTime) >= (1000000L / FPS)) { // 1/30 sec elapsed?
      prevTime = t;
      break;                                 // Yes, go update LEDs
    }                                        // otherwise...
    if ((c = ser.read()) == '!') {           // Received UART app input?
      while ((c = ser.read()) < 0);          // Yes, wait for command byte
      switch (c) {
        case 'B':       // Button (Control Pad)
          if (readAndCheckCRC(255 - '!' - 'B', buf, 2) & (buf[1] == '1')) {
            buttonPress(buf[0]); // Handle button-press message
          }
          break;
        case 'C':       // Color Picker
          if (readAndCheckCRC(255 - '!' - 'C', buf, 3)) {
            // As mentioned earlier, setBrightness() was avoided to save space.
            // Instead, results from the color picker (in buf[]) are divided
            // by 4; essentially equivalent to setBrightness(64).  This is to
            // improve battery run time (NeoPixels are still plenty bright).
            color = pixels.Color(buf[0] / 4, buf[1] / 4, buf[2] / 4);
          }
          break;
        case 'Q':       // Quaternion
          skipBytes(17); // 4 floats + CRC (see note below re: parsing)
          break;
        case 'A':       // Accelerometer
#if 0
          // The phone sensors are NOT used by this sketch, but this shows how
          // they might be read.  First, buf[] must be delared large enough for
          // the expected data packet (minus header & CRC) -- that's 16 bytes
          // for quaternions (above), or 12 bytes for most of the others.
          // Second, the first arg to readAndCheckCRC() must be modified to
          // match the data type (e.g. 'A' here for accelerometer).  Finally,
          // values can be directly type-converted to float by using a suitable
          // offset into buf[] (e.g. 0, 4, 8, 12) ... it's not used in this
          // example because floating-point math uses lots of RAM and code
          // space, not suitable for the space-constrained Trinket/Gemma, but
          // maybe you're using a Pro Trinket, Teensy, etc.
          if (readAndCheckCRC(255 - '!' - 'A', buf, 12)) {
            float x = *(float *)(&buf[0]),
                  y = *(float *)(&buf[4]),
                  z = *(float *)(&buf[8]);
          }
          // In all likelihood, updates from the buttons and color picker
          // alone are infrequent enough that you could do without any mention
          // of the CTS pin in this code.  It's the extra sensors that really
          // start the firehose of data.
          break;
#endif
        case 'G':       // Gyroscope
        case 'M':       // Magnetometer
        case 'L':       // Location
          skipBytes(13); // 3 floats + CRC
      }
    }
  }
  digitalWrite(CTS_PIN, HIGH); // BLE STOP!

  // Show pixels calculated on *prior* pass; this ensures more uniform timing
  pixels.show();

  // Then calculate pixels for *next* frame...
  switch (animMode) {
    case 0: // Pinwheel mode
      for (uint8_t i = 0; i < NUM_LEDS / 2; i++) {
        uint32_t c = 0;
        if (((animPos + i) & 7) < 2) c = color; // 4 pixels on...
        pixels.setPixelColor(   i, c);         // First eye
        pixels.setPixelColor(NUM_LEDS - 1 - i, c); // Second eye (flipped)
      }
      animPos++;
      break;
    case 1: // Sparkle mode
      pixels.setPixelColor(animPos, 0);     // Erase old dot
      animPos = random(NUM_LEDS);           // Pick a new one
      pixels.setPixelColor(animPos, color); // and light it
      break;
  }
}

boolean readAndCheckCRC(uint8_t sum, uint8_t *buf, uint8_t n) {
  for (int c;;) {
    while ((c = ser.read()) < 0); // Wait for next byte
    if (!n--) return (c == sum); // If CRC byte, we're done
    *buf++ = c;                  // Else store in buffer
    sum   -= c;                  // and accumulate sum
  }
}

void skipBytes(uint8_t n) {
  while (n--) {
    while (ser.read() < 0);
  }
}
Last edited by franklin97355 on Wed Apr 17, 2019 4:56 pm, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by franklin97355 on Wed Apr 17, 2019 4:58 pm

That is a compiler error with the Arduino IDE Try downloading a fresh copy and make sure the Arduino and Adafruit SAMD board files are present and installed.

franklin97355
 
Posts: 20765
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket M0 light goggles

by Hethacker on Wed Apr 17, 2019 7:22 pm

Okay, I have reinstalled the libraries and made sure that they are the current versions, all board files seem to be non corrupted. I ran the file and I received the same initial error that I had at the beginning of this thread:

C:\Users\h\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21e18a.h:233:26: fatal error: core_cm0plus.h: No such file or directory

#include <core_cm0plus.h>

^

compilation terminated.

exit status 1

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Re: Trinket M0 light goggles

by franklin97355 on Wed Apr 17, 2019 7:46 pm

The code you posted does not compile. Are you sure that is the exact code you are using?

franklin97355
 
Posts: 20765
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Trinket M0 light goggles

by XRAD on Wed Apr 17, 2019 10:07 pm

curious, what happens with this?

Code: Select all | TOGGLE FULL SIZE

#include <Adafruit_NeoPixel.h>


#define RX_PIN    0 // Connect this Trinket pin to BLE 'TXO' pin
#define CTS_PIN   1 // Connect this Trinket pin to BLE 'CTS' pin
#define LED_PIN   2 // Connect NeoPixels to this Trinket pin
#define NUM_LEDS 42 // Two 16-LED NeoPixel rings
#define FPS      30 // Animation frames/second (ish)
#define BUTTON 3

//Serial1(RX_PIN, -1);
Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN);

void setup() {

  // Stop incoming data & init software serial
  pinMode(CTS_PIN, OUTPUT); digitalWrite(CTS_PIN, HIGH);
  Serial.begin(9600);

  pinMode(BUTTON, INPUT);

  pixels.begin(); // NeoPixel init
  // Flash space is tight on Trinket/Gemma, so setBrightness() is avoided --
  // it adds ~200 bytes.  Instead the color picker input is 'manually' scaled.
}

uint8_t  buf[3],              // Enough for RGB parse; expand if using sensors
         animMode = 0,        // Current animation mode
         animPos  = 0;        // Current animation position
uint32_t color    = 0x400000, // Current animation color (red by default)
         prevTime = 0L;       // For animation timing

void loop(void) {
  int      c;
  uint32_t t;
digitalRead(BUTTON );

  // Animation happens at about 30 frames/sec.  Rendering frames takes less
  // than that, so the idle time is used to monitor incoming serial data.
  digitalWrite(CTS_PIN, LOW); // Signal to BLE, OK to send data!
  for (;;) {
    t = micros();                            // Current time
    if ((t - prevTime) >= (1000000L / FPS)) { // 1/30 sec elapsed?
      prevTime = t;
      break;                                 // Yes, go update LEDs
    }                                        // otherwise...
    if ((c = Serial.read()) == '!') {           // Received UART app input?
      while ((c = Serial.read()) < 0);          // Yes, wait for command byte
      switch (c) {
        case 'B':       // Button (Control Pad)
          if (readAndCheckCRC(255 - '!' - 'B', buf, 2) & (buf[1] == '1')) {
             
             if(BUTTON,HIGH){
              (buf[0]); // Handle button-press message
            }
          }
          break;
        case 'C':       // Color Picker
          if (readAndCheckCRC(255 - '!' - 'C', buf, 3)) {
            // As mentioned earlier, setBrightness() was avoided to save space.
            // Instead, results from the color picker (in buf[]) are divided
            // by 4; essentially equivalent to setBrightness(64).  This is to
            // improve battery run time (NeoPixels are still plenty bright).
            color = pixels.Color(buf[0] / 4, buf[1] / 4, buf[2] / 4);
          }
          break;
        case 'Q':       // Quaternion
          skipBytes(17); // 4 floats + CRC (see note below re: parsing)
          break;
        case 'A':       // Accelerometer
#if 0
          // The phone sensors are NOT used by this sketch, but this shows how
          // they might be read.  First, buf[] must be delared large enough for
          // the expected data packet (minus header & CRC) -- that's 16 bytes
          // for quaternions (above), or 12 bytes for most of the others.
          // Second, the first arg to readAndCheckCRC() must be modified to
          // match the data type (e.g. 'A' here for accelerometer).  Finally,
          // values can be directly type-converted to float by using a suitable
          // offset into buf[] (e.g. 0, 4, 8, 12) ... it's not used in this
          // example because floating-point math uses lots of RAM and code
          // space, not suitable for the space-constrained Trinket/Gemma, but
          // maybe you're using a Pro Trinket, Teensy, etc.
          if (readAndCheckCRC(255 - '!' - 'A', buf, 12)) {
            float x = *(float *)(&buf[0]),
                  y = *(float *)(&buf[4]),
                  z = *(float *)(&buf[8]);
          }
          // In all likelihood, updates from the buttons and color picker
          // alone are infrequent enough that you could do without any mention
          // of the CTS pin in this code.  It's the extra sensors that really
          // start the firehose of data.
          break;
#endif
        case 'G':       // Gyroscope
        case 'M':       // Magnetometer
        case 'L':       // Location
          skipBytes(13); // 3 floats + CRC
      }
    }
  }
  digitalWrite(CTS_PIN, HIGH); // BLE STOP!

  // Show pixels calculated on *prior* pass; this ensures more uniform timing
  pixels.show();

  // Then calculate pixels for *next* frame...
  switch (animMode) {
    case 0: // Pinwheel mode
      for (uint8_t i = 0; i < NUM_LEDS / 2; i++) {
        uint32_t c = 0;
        if (((animPos + i) & 7) < 2) c = color; // 4 pixels on...
        pixels.setPixelColor(   i, c);         // First eye
        pixels.setPixelColor(NUM_LEDS - 1 - i, c); // Second eye (flipped)
      }
      animPos++;
      break;
    case 1: // Sparkle mode
      pixels.setPixelColor(animPos, 0);     // Erase old dot
      animPos = random(NUM_LEDS);           // Pick a new one
      pixels.setPixelColor(animPos, color); // and light it
      break;
  }
}

boolean readAndCheckCRC(uint8_t sum, uint8_t *buf, uint8_t n) {
  for (int c;;) {
    while ((c = Serial.read()) < 0); // Wait for next byte
    if (!n--) return (c == sum); // If CRC byte, we're done
    *buf++ = c;                  // Else store in buffer
    sum   -= c;                  // and accumulate sum
  }
}

void skipBytes(uint8_t n) {
  while (n--) {
    while (Serial.read() < 0);
  }
}

XRAD
 
Posts: 440
Joined: Sat Nov 19, 2016 3:28 pm

Re: Trinket M0 light goggles

by Hethacker on Sun Apr 21, 2019 1:30 am

Same results, the program gives me the error that it is missing its compile.core file

Hethacker
 
Posts: 34
Joined: Fri Apr 05, 2019 9:02 pm

Please be positive and constructive with your questions and comments.