0

Trinket M0 light goggles
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Trinket M0 light goggles

by Hethacker on Sat Apr 27, 2019 9:53 pm

I have tried several more complete uninstalls and re-installs, using only the files provided by Adafruit and the related articles in Github. I still have not had any luck, any other recommendations?

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Mon Apr 29, 2019 12:19 pm

What guide are you following? I just did a test compile of this:
https://learn.adafruit.com/kaleidoscope ... duino-code
on a Trinet M0 and it worked OK.

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Mon Apr 29, 2019 3:20 pm

the bluetooth controlled neopixel goggles version, using a strip of neopixels in each lens

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Mon Apr 29, 2019 4:02 pm

Switching to hardware serial is the correct approach. I got this working on a little breadboard mock up. Here's the code:
Code: Select all | TOGGLE FULL SIZE
// 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    2 // Connect this Trinket pin to BLE 'TXO' pin
#define CTS_PIN   1 // Connect this Trinket pin to BLE 'CTS' pin
#define LED_PIN   0 // Connect NeoPixels to this Trinket pin
#define NUM_LEDS 32 // Two 16-LED NeoPixel rings
#define FPS      30 // Animation frames/second (ish)

//SoftwareSerial    ser(RX_PIN, -1);
#define ser Serial1

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;
  }
}

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Wed May 01, 2019 3:03 pm

Thank you, I switched to the old 1.6.13 arduino format and that helped. when I ran your code to verify it, it worked! but when I actually went to upload to the trinket, it would initially look like it compiled and finished uploading but then right before it would finish, it would say that a debug was needed. it would take about 30-40 seconds and then say that I have an invalid library in C/users/h/arduino/downloads twice and then say that debug was successful and code is done uploading. but the trinket has the same led color that means syntax error.

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Wed May 01, 2019 4:02 pm

Go ahead and try with the latest Arduino IDE.

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Wed May 01, 2019 4:17 pm

adafruit_support_carter wrote:Go ahead and try with the latest Arduino IDE.


same results as before:

Detecting libraries used...
"C:\\Users\\\\Documents\\ArduinoData\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m0plus -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=48000000L -DARDUINO=10809 -DARDUINO_TRINKET_M0 -DARDUINO_ARCH_SAMD -DCRYSTALLESS -DADAFRUIT_TRINKET_M0 -D__SAMD21E18A__ -DARM_MATH_CM0PLUS -DUSB_VID=0x239A -DUSB_PID=0x801E -DUSBCON "-DUSB_MANUFACTURER=\"Adafruit\"" "-DUSB_PRODUCT=\"Trinket M0\"" "-IC:\\Users\\\\Documents\\ArduinoData\\packages\\arduino\\tools\\CMSIS\\4.5.0/CMSIS/Include/" "-IC:\\Users\\\\Documents\\ArduinoData\\packages\\arduino\\tools\\CMSIS-Atmel\\1.2.0/CMSIS/Device/ATMEL/" "-IC:\\Users\\Documents\\ArduinoData\\packages\\adafruit\\hardware\\samd\\1.3.0\\cores\\arduino" "-IC:\\Users\\\Documents\\ArduinoData\\packages\\adafruit\\hardware\\samd\\1.3.0\\variants\\trinket_m0" "C:\\Users\\\\AppData\\Local\\Temp\\arduino_build_253750\\sketch\\Ampli_Tie_Dynamic.ino.cpp" -o nul
In file included from C:\Users\hunter\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:59:0,

from C:\Users\\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:87,

from C:\Users\\Documents\ArduinoData\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,

from C:\Users\\Documents\ArduinoData\packages\adafruit\hardware\samd\1.3.0\cores\arduino/Arduino.h:48,

from C:\Users\\AppData\Local\Temp\arduino_build_253750\sketch\ledgoggles.ino.cpp:1:

C:\Users\\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
Error compiling for board Adafruit Trinket M0.

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Wed May 01, 2019 4:40 pm

Looks like you haven't installed SAMD support:
https://learn.adafruit.com/adafruit-tri ... rduino-ide

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Wed May 01, 2019 8:40 pm

okay, I do that but I get this response when I install the adafruit SAMD board:
Warning: non trusted contribution, skipping script execution (C:\Users\\Documents\ArduinoData\packages\adafruit\hardware\samd\1.4.1\post_install.bat)
java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at cc.arduino.contributions.packages.ui.ContributionManagerUI.lambda$onInstallPressed$2(ContributionManagerUI.java:175)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at cc.arduino.contributions.packages.ContributionInstaller.findAndExecutePreUninstallScriptIfAny(ContributionInstaller.java:197)
at cc.arduino.contributions.packages.ContributionInstaller.remove(ContributionInstaller.java:243)
at cc.arduino.contributions.packages.ui.ContributionManagerUI.lambda$onInstallPressed$2(ContributionManagerUI.java:170)
... 1 more

can this be the problem?
otherwise, all of the arduino SAMD board downloads fine and even when I get this comment about the adafruit SAMD not being able to upload all of the files, they still all show up in the downloaded boards.

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Wed May 01, 2019 9:00 pm

That's odd. It looks like something is broken with your Arduino installation. Can you even get a basic blink sketch to load and run?
https://learn.adafruit.com/adafruit-tri ... blink-6-21

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Thu May 02, 2019 8:26 pm

I cannot, it has the same error as earlier.

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

Re: Trinket M0 light goggles

by adafruit_support_carter on Thu May 02, 2019 8:31 pm

I'd suggest trying a clean re-install of the Arduino IDE. Be sure to also do a manual delete of the folder:

C:\Users\(username)\AppData\Roaming\Arduino15

and/or

C:\Users\(username)\AppData\Local\Arduino15

adafruit_support_carter
 
Posts: 12958
Joined: Tue Nov 29, 2016 2:45 pm

Re: Trinket M0 light goggles

by Hethacker on Sat May 04, 2019 1:14 am

okay, I removed everything, got all of the new boards and their updates with no issues. I put in the link code and I get the syntax error light and this result:

Sketch uses 10080 bytes (3%) of program storage space. Maximum is 262144 bytes.
Atmel SMART device 0x1001000a found
Device : ATSAMD21E18A
Chip ID : 1001000a
Version : v1.1 [Arduino:XYZ] Nov 2 2018 22:53:16
Address : 8192
Pages : 3968
Page Size : 64 bytes
Total Size : 248KB
Planes : 1
Lock Regions : 16
Locked : none
Security : false
Boot Flash : true
BOD : true
BOR : true
Arduino : FAST_CHIP_ERASE
Arduino : FAST_MULTI_PAGE_WRITE
Arduino : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.804 seconds

Write 10336 bytes to flash (162 pages)

[=========== ] 39% (64/162 pages)
[======================= ] 79% (128/162 pages)
[==============================] 100% (162/162 pages)
done in 0.076 seconds

Verify 10336 bytes of flash with checksum.
Verify successful
done in 0.016 seconds
CPU reset.
Invalid library found in C:\Users\\Documents\Arduino\libraries\Downloads: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\Downloads
Invalid library found in C:\Users\\Documents\Arduino\libraries\libraries: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\libraries
Invalid library found in C:\Users\\Documents\Arduino\libraries\Downloads: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\Downloads
Invalid library found in C:\Users\\Documents\Arduino\libraries\libraries: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\libraries

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

Re: Trinket M0 light goggles

by franklin97355 on Sat May 04, 2019 2:32 am

Code: Select all | TOGGLE FULL SIZE
Invalid library found in C:\Users\\Documents\Arduino\libraries\Downloads: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\Downloads
Invalid library found in C:\Users\\Documents\Arduino\libraries\libraries: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\libraries
Invalid library found in C:\Users\\Documents\Arduino\libraries\Downloads: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\Downloads
Invalid library found in C:\Users\\Documents\Arduino\libraries\libraries: no headers files (.h) found in C:\Users\\Documents\Arduino\libraries\libraries

This is the IDE telling you you have some corrupt libraries in your libraries folder. You should not have a folder called libraries in your libraries folder.

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

Re: Trinket M0 light goggles

by Hethacker on Mon May 06, 2019 1:52 pm

okay, I removed the library folder inside of the library folder, removed previous versions of the libraries and reinstalled the newest versions, and the trinket finally took the code.
I got the program uploaded and the program picked up the bluetooth reciever and linked to my phone, it would recieve inputs from my phone whenever I sent color updates (the red light would flash twice on the bluefruit) but the neopixel strip only makes the same animation of a red, blue and green light moving down the strip, it will not change the strip color to the color I am putting in on the app.

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

Please be positive and constructive with your questions and comments.