0

I cannot get this sketch to work
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I cannot get this sketch to work

by pinkpanda3310 on Sat Aug 12, 2017 4:31 am

I have some 3v trinkets and am keen to make them work in a custom flashlight. I went through the process of uploading the blink sketch and turning the red led on via switch. I even got the sketch to the goggles to upload and work.

https://www.hackster.io/Richa1/adafruit ... ode-43bcd8
I found this guy's work and it pretty much covered what I wanted to achieve in the flashlight but I cannot seem to get it working. I have a 12 led neopixel ring connected. I can upload the sketch (though it takes once or twice to get it uploaded successfully) but when I connect the battery and push the buttons the pixel ring does not light. The onboard leds are on indicating power but no power gets to the ring.

Any help would be appreciated and if you could dumb it down for me that would be even better :)

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sat Aug 12, 2017 5:58 am

If you post some photos showing your soldering and connections we'll take a look.

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sat Aug 12, 2017 7:57 am

I tried halving the clock speed on the special trinket code as well. Still no go. Hope these pics show what you're looking for...?

Image
Image
Image

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sat Aug 12, 2017 8:11 am

If you upload the strandtest example code from the Neopixel library and change the strip definition to use pin 2, do the pixels light up?

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sat Aug 12, 2017 8:13 am

I'll give it a go tomorrow so it may be a day or two before I reply. Thanks for the suggestion.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sat Aug 12, 2017 8:16 am

If the strandtest doesn't work, post some photos showing the soldering on the other side of the Trinket and ring.

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 7:46 am

I tried 2 different strand tests using PIN 2 and they both seem to work fine. I tried Richards colour code again noting PIN 2 but still no go. Though when I disconnected the battery it wasn't a clean break and a small part of the pixel ring light up for a split second. I tried changing the sensor to 0 but avr dude said I might have the wrong board?? So I tried a few different combinations including the buttons but all failed. I redid the strand test and it still seems to work fine with that.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sun Aug 13, 2017 7:57 am

If the strandtest is working, that confirms that the processor is functioning and your neopixel wiring is fine. So the problem must be either in your switch wiring, or the sketch itself.

If you have a multimeter, check that the voltage on pins #0 and #4 is at 5v when no button is pressed and goes to 0v when the corresponding button is pressed.

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 8:09 am

Connected to a lithium battery at 3.96v I get 3.12v across pins 0 and 4. The voltage drops to zero when the button is pressed.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sun Aug 13, 2017 8:14 am

So you are using a 3.3v Trinket. Have you removed the 5v-specific code from the sketch?

Code: Select all | TOGGLE FULL SIZE
void setup(){
     // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 8:16 am

Sorry I reread your instructions and see I screwed it up. Pin #4 to ground shows 3.1v and zero when the button is pressed. Pin #0 shows no voltage button pressed or not.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 8:18 am

I'll try removing that part of the code. I thought I had tried it before but I'll double check and do it again. I did however change the clock speed in that part of the code to 800000

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 8:22 am

I removed that part of the code and got this error -

Arduino: 1.8.2 (Windows 10), Board: "Adafruit Trinket 8MHz"

sketch_aug13a:36: error: expected constructor, destructor, or type conversion before '(' token

pinMode(C_BUTTON, INPUT_PULLUP);

^

sketch_aug13a:37: error: expected constructor, destructor, or type conversion before '(' token

pinMode(P_BUTTON, INPUT_PULLUP);

^

sketch_aug13a:38: error: 'strip' does not name a type

strip.begin();

^

sketch_aug13a:39: error: 'strip' does not name a type

strip.show(); // Initialize all pixels to 'off'

^

sketch_aug13a:41: error: expected constructor, destructor, or type conversion before '(' token

pinMode(Sensor,INPUT); // Interupt Code

^

In file included from c:\program files\arduino\hardware\tools\avr\avr\include\avr\io.h:99:0,

from c:\program files\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

from C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

from sketch\sketch_aug13a.ino.cpp:1:

sketch_aug13a:14: error: expected unqualified-id before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:42:3: note: in expansion of macro 'sbi'

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:42:3: note: in expansion of macro 'sbi'

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:42:3: note: in expansion of macro 'sbi'

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:42:3: note: in expansion of macro 'sbi'

sbi(GIMSK,PCIE); // Turn on Pin Change interrupt

^

sketch_aug13a:14: error: expected unqualified-id before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:43:3: note: in expansion of macro 'sbi'

sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:43:3: note: in expansion of macro 'sbi'

sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:43:3: note: in expansion of macro 'sbi'

sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt

^

sketch_aug13a:14: error: expected ')' before 'volatile'

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

^

C:\Users\Toshiba\AppData\Local\Temp\arduino_modified_sketch_37145\sketch_aug13a.ino:43:3: note: in expansion of macro 'sbi'

sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt

^

sketch_aug13a:44: error: expected declaration before '}' token

}

^

exit status 1
expected constructor, destructor, or type conversion before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Re: I cannot get this sketch to work

by adafruit_support_bill on Sun Aug 13, 2017 8:23 am

Did you delete just the 3 lines indicated? Please post your modified code.

adafruit_support_bill
 
Posts: 62309
Joined: Sat Feb 07, 2009 10:11 am

Re: I cannot get this sketch to work

by pinkpanda3310 on Sun Aug 13, 2017 8:29 am

modified code (I didn't copy all of it since the trinket code was somewhere near the start) -

/
Code: Select all | TOGGLE FULL SIZE
/Color and Patern Mode selector for NeoPixels
//Uses C_BUTTON to sycle through 9 colors and P_BUTTON to select any of the 8 patern sequanses.
// 64 total options are avalable
//code by Richard Albritton

#include <Adafruit_NeoPixel.h>
#include <avr/power.h>

// Interupt Code start
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
// Interupt Code end

#define PIN 0
#define Sensor 1
#define C_BUTTON 4
#define P_BUTTON 2
#define Pixels 12

Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);

int C_MODE = 4; // Current color mode.
int P_MODE = 7; // Current pattern mode.
int STrigger = 0; // This tells us if the sensor interupt was triggered.
int R = 0;
int G = 50;
int B = 50;
long randNumber;
int wait = 10;


  pinMode(C_BUTTON, INPUT_PULLUP);
  pinMode(P_BUTTON, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  pinMode(Sensor,INPUT); // Interupt Code
  sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
  sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt
}

void loop(){
ColorSelect();
PatternSelect();
    //colorMode(C_MODE);
    patternMode(P_MODE);
    STrigger = 0;
}
void ColorSelect(){
  while (digitalRead(P_BUTTON) == LOW) {
    colorChange(strip.Color(R/4, G/4, B/4));
    while (digitalRead(C_BUTTON) == LOW) {
      delay(500);
      C_MODE += 1;
      if (C_MODE > 9) {
        C_MODE = 1;
      }
      colorMode(C_MODE);
      colorChange(strip.Color(R/4, G/4, B/4));
    }
  }
}
void PatternSelect(){
  while(digitalRead(C_BUTTON) == LOW) {
    //colorChange(strip.Color(R/4, G/4, B/4));
    while(digitalRead(P_BUTTON) == LOW) {
      delay(500);
      P_MODE += 1;
      if (P_MODE > 9) {
        P_MODE = 1;
      }
      patternMode(P_MODE);
    }
  }
}
// Fill the all dots at once
void colorChange(uint32_t c) {
Last edited by adafruit_support_bill on Sun Aug 13, 2017 8:54 am, edited 1 time in total.
Reason: please use [code] tags when posting code to the forums.

pinkpanda3310
 
Posts: 13
Joined: Sat Aug 12, 2017 4:17 am

Please be positive and constructive with your questions and comments.