So im using the adafruit_neopixel library to control some led strips, but the problem is my circuit essentially inverts the data signal making it not work. So i was thinking of inverting the code that iis controlling the data pin so that what the led strips will see is the correct signal
I am using the arduino MKR1000 wifi, and here is a link to the .cpp of the library looks really complicated, and dont know which one is responsible for actually outputting the signal
here is the example code that i striped down.
/ NeoPixel test program showing use of the WHITE channel for RGBW
// pixels only (won't look correct on regular RGB NeoPixel strips).
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 2
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 100
// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 10
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(BRIGHTNESS); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
colorWipe(strip.Color(255, 255, 255) , 50); // WHITE
delay(10000);
colorWipe(strip.Color(255, 0, 0) , 50); // Red
}
void colorWipe(uint32_t color, int wait) {
Serial.println("Wwriting single color");
for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
Serial.println("Wwriting single color FINISHED");
}
Humm, so there is a circuit that is attached to a pin of the MCU you are using and that circuit inverts the pin output for some double-secret thingy. Why not tap off the pin of the MCU before the inversion occurs and send the non inverted signal to the neopixels?
Okey. You've got the same idea. I can't tell how to do surgery in libs.
One way could be to use one more inverting transistor feeding the MOSFET gate. Possible to do?
Yes , but stores selling components wont be open for like another 12hours , so im kinda stuck. I will try doing it in software and when all else fails ill get the components tomorrow.
ALITOVE WS2812B WS2811 SPI Signal Amplifier Repeater, for WS2813 SK6812 WS2815 WS2801 RGB Addressable LED Pixel Strip Light and Dream Color Programmable LED Matrix Panel Light DC 5V~24V
I normally use 74hct04 's to boost the logic level and 'square-out' the signal, using 2 gates to re-invert the signal, but since the shops won't open i suggest to open neopixel.h and find the void show() function in neopixel.cpp
You will have to look through it to find the code for the processor you are using.
In probably a slightly older version i found the ARM specific section
#elif defined(__arm__)
// Paul Stoffregen: "This implementation may not be quite perfect, but
// it seems to work reasonably well with an actual 20 LED WS2811 strip.
// The timing at 48 MHz is off a bit, perhaps due to flash cache misses?
// Ideally this code should execute from RAM to eliminate slight timing
// differences between flash caches hits and misses. But it seems to
// [run] quite well. More testing is needed with longer strips."
/* If timing can be stabilized, something like this should work:
#define DELAY_800_T0H (0.40 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_800_T0L (0.85 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_800_T1H (0.80 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_800_T1L (0.45 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_400_T0H (0.50 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_400_T0L (2.00 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_400_T1H (1.20 * F_CPU / 1000000L / DCYC + 0.5)
#define DELAY_400_T1L (1.30 * F_CPU / 1000000L / DCYC + 0.5)
But in the meantime, a fixed set of tables is used:
*/
#ifdef __MK20DX128__ // Teensy 3.0
#if (F_CPU == 24000000)
#define DELAY_800_T0H 2
#define DELAY_800_T0L 4
#define DELAY_800_T1H 5
#define DELAY_800_T1L 1
#define DELAY_400_T0H 3
#define DELAY_400_T0L 10
#define DELAY_400_T1H 9
#define DELAY_400_T1L 5
#elif (F_CPU == 48000000)
#define DELAY_800_T0H 4
#define DELAY_800_T0L 9
#define DELAY_800_T1H 12
#define DELAY_800_T1L 1
#define DELAY_400_T0H 6
#define DELAY_400_T0L 20
#define DELAY_400_T1H 18
#define DELAY_400_T1L 11
#elif (F_CPU == 96000000)
#define DELAY_800_T0H 7
#define DELAY_800_T0L 17
#define DELAY_800_T1H 22
#define DELAY_800_T1L 2
#define DELAY_400_T0H 12
#define DELAY_400_T0L 40
#define DELAY_400_T1H 36
#define DELAY_400_T1L 22
#else
#error "CPU SPEED NOT SUPPORTED"
#endif
volatile uint8_t *set = portSetRegister(pin);
volatile uint8_t *clr = portClearRegister(pin);
#define SET_HI *set = 1;
#define SET_LO *clr = 1;
uint8_t *p = pixels,
*end = p + myBytes, pix, mask;
if((type & NEO_SPDMASK) == NEO_KHZ800) { // 800 KHz bitstream
while(p < end) {
pix = *p++;
for(mask = 0x80; mask; mask >>= 1) {
SET_HI
if(pix & mask) {
delayShort(DELAY_800_T1H);
SET_LO
delayShort(DELAY_800_T1L);
} else {
delayShort(DELAY_800_T0H);
SET_LO
delayShort(DELAY_800_T0L);
}
}
}
} else { // 400 kHz bitstream
while(p < end) {
pix = *p++;
for(mask = 0x80; mask; mask >>= 1) {
SET_HI
if(pix & mask) {
delayShort(DELAY_400_T1H);
SET_LO
delayShort(DELAY_400_T1L);
} else {
delayShort(DELAY_400_T0H);
SET_LO
delayShort(DELAY_400_T0L);
}
}
}
}
where you can simply invert the meaning of these 2 defines
#define SET_HI *set = 1;
#define SET_LO *clr = 1;
to
#define SET_HI *clr = 1;
#define SET_LO *set = 1;
which should do the trick. Of course you should, when modifying a library, first create a copy with a different name, where you modify both the .h & .cpp files names, and change how they are referenced in one another and the check for double include in the .h file. Then modify that and include that file in your code.
Thanks just as i thought the makers of the library did really have some way of inverting the signal easily,
but i have read your comment a bit to late, i have bought the parts needed and got it working. Ill mark your reply as an answer though since that is what i had origially asked help with