Seeeduino Xiao w/CircuitPython

Hello. I'm fairly green with coding and Arduino, though I have a lot of experience with modifying existing code on open source lightsaber sound boards. I guess I'm good at seeing it and making modifications, but very green with starting from scratch.

I'm looking to write up, I believe, a simple code for a Seeeduino Xiao wit CircuitPython

It's going to be powered by a 3.7 Li-Ion, and have only one momentary switch and one WS2812 "neopixel".

I'd like to have the momentary switch act as an on/off for the neopixel. Maybe a short click on and long press off. But with the ability to double click and cycle through approximately 6 colors that have a bit of color flicker, so "Red/White, Green/White, etc.

I've got Arduino installed on my computer, which I use to program lightsaber boards, so I can use that if need be. Not sure if the libraries for the neopixel and whatnot are already part of the Seeeduino/Circuitpython.

Attached is my wiring diagram. The pixel has an on board capacitor and resistor. Any help would be appreciated. Even better if someone has a recommendation for an existing sketch. :slight_smile:

This is not the Forum for advice on CircuitPython programming.

CircuitPython was developed by Adafruit and they probably have a Forum for it.

This Forum is for programming Arduinos using C++

...R

Might be more appropriate to ask questions about MicroPython in the MicroPython Forum;

https://forum.micropython.org/

The processor on the Xiao is a 3.3V processor; I don't think that the outputs are 5V in which case you might need a buffer (not the standard level converter) like a 74HC14 between the data pin and the WS2812.

You will need two sections of it in series as the 74HC14 is an inverter.

I didn't know that circuitpython was a 'proprietary' or rival thing, honestly. Lol

I'll stick with using my Arduino program for uploading, then. :slight_smile:

And I'm pretty sure neopixels will run fine with 3.7V through the 5v pad but I'll have to double check. All my current lightsabers use a teensy based board that runs on 3.7v exclusively, so we'll see...

Ok, so I've had my first breakthrough. Wired as shown, with a simple pixel sketch uploaded through Arduino, it works perfectly. Now I just need some guidance on how to add a momentary switch and change the pixel behavior. :slight_smile: This is the sketch I used to test...

#include <Adafruit_NeoPixel.h>

// constants won't change. They're used here to
// set pin numbers:
const int ledPin = 10; // the number of the neopixel strip
const int numLeds = 1;

//Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, ledPin);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numLeds, ledPin, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.setBrightness(80); // 1/3 brightness

}

void loop() {

rainbow(30);

delay(10);

}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i*1+j) & 255));
}
strip.show();
delay(wait);
}
}

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

I would say, have a look at the following examples

02 Digital -> Button
02 DigitalInputPullup

The following might also be useful
02 StateChangeDetection
02 Debounce

Note
Please edit reply #5 and add
** **[code]** **
before your code and
** **[/code]** **
after your code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.