The ARDUINO UNO R4 WiFi offers a second I2C channel called Wire1. The SDA and SCL lines are connected to pins 26 and 27, which are not available otherwise. Both pins can be used by the Adafruit Neopixel Library. WS2812 strips normally should be operated by a voltage of 5 volts, while the Qwiic channel (Wire1) only feeds 3.3 volts. Does it work nevertheless? Obviously it does.
Of course, only one strip can be connected to SDA, while the other one gets connected to SCL. You just need a Qwiic adapter and a Qwiic cable. Everything is mounted on a base board in the shape of the Plug-and-make kit.
This is how to solder the DI to the SCL pin:
The yellow wires are only used to fix the strip.
And this is some demo code to check that it really works:
/*
WS2812-strips connected to Qwiic SDA and SCL
can be driven independently
*/
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip1(8, 26, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip2(16, 27, NEO_GRBW + NEO_KHZ800);
int bright1, bright2;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(__FILE__);
strip1.begin();
strip2.begin();
}
void loop() {
strip1.rainbow(0, 2, 255, bright1);
strip1.show();
strip2.rainbow(0, 2, 255, bright2);
strip2.show();
delay(100);
bright1 = bright1 + 4;
bright2 = bright2 + 6;
}
Have fun!
Obviously, not all sensors would be happy hitten by WS2812-data.
For instance, the distance sensor VL53L0X-V2 does not like it In this case, just insert the associated "begin" commands just before accessing the sensor and the strip.
/*
connect VL53LoX to I2C Wire1 (Qwiic)
sensor.setBus(&Wire1);
------------------------------------
pullup resistors are not required
for combination of VL53 and WS2812
use Wire1.begin and strip.begin
*/
/* sensor */
#include <VL53L0X.h>
VL53L0X sensor;
#define HIGH_ACCURACY
int maxi = 1130;
/* display = WS2812 ring */
#include <Adafruit_NeoPixel.h>
const byte PIN = 26; // SCL pin // 27; = SDA pin //A0; //
const byte NUMPIXELS = 16;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
float ofs;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(__FILE__);
/* sensor */
/* --- for Wire1 --- */
Wire1.begin(); // <--- Wire1 !!!
sensor.setBus(&Wire1); // <--- Wire1 !!!
sensor.setTimeout(500);
if (!sensor.init()) {
Serial.println("Failed to detect and initialize sensor!");
while (true);
}
sensor.setMeasurementTimingBudget(200000);
}
void loop() {
/* sensor */
Wire1.begin();
int d = sensor.readRangeSingleMillimeters();
if (d > maxi) d = 9999;
Serial.print(d);
Serial.print(" ");
if (sensor.timeoutOccurred()) Serial.print(" TIMEOUT");
Serial.println();
/* display */
strip.begin();
myRainbow();
for (int i = d / 20; i < NUMPIXELS; i++)
strip.setPixelColor(i, 0xff0000);
strip.show();
delay(500);
}
void myRainbow() {
const byte A = 2;
const byte B = 3;
const byte C = 4;
const float D = 6;
for (int pixno = 0; pixno < NUMPIXELS; pixno++) {
float x = (pixno + ofs) * D / NUMPIXELS;
while (x < 0) x = x + 6;
while (x > 6) x = x - 6;
byte r = p(abs(x - B) - 1);
byte g = p(2 - abs(x - A));
byte b = p(2 - abs(x - C));
strip.setPixelColor(pixno, r, g, b);
}
ofs = ofs - 0.2;
if (ofs < 0) ofs = NUMPIXELS;
}
// auxiliar for rainbow:
float p(float x) {
if (x > 0) return 10 * x;
return 0;
}
Comments
Please log in or sign up to comment.