So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Gdipstick
#70275 i am able to use the RGBLED.h library on my Arduino UNO. can i use the use the same library on the esp8266 and if so, how do i map the pins?

i have my experiment working on the Uno, and tips on converting it over to the esp8266 would be great, tutorials, forums etc... would be greatly appreciated.

thx!

:?:
User avatar
By Gdipstick
#71181 i have the example sketch partially working but i can't get the rgb led to turn off, trying to troubleshoot this issue, wondering if anyone else has the same problem?

RGBLED won't turn off using the example sketch:
#include <RGBLED.h>

// Declare an RGBLED instanced named rgbLed
// Red, Green and Blue LED legs are connected to PWM pins D6,D5 & D2 respectively
// In this example, we have a COMMON_ANODE LED, use COMMON_CATHODE otherwise
RGBLED rgbLed(D6,D5,D2,COMMON_ANODE);

* i tried D8 to make jumpering easier but it throws errors when i do that, so switched to D2, but the result is te same as using D7 which i realized later is not PWM

* later on in the sketch...

//Turn off the RGBLED
rgbLed.turnOff();
printRgbValues();
delay(delayMs);

* this part doesn't work either, otherwise i think i'm close

maybe the nodemcu would prefer a common cathode rgbled?
help?
User avatar
By Gdipstick
#71250 thanks for offering to help! no, i was uncertain about 7 being a pwm pin, i was using a reference from acrobotics "ESP-12E DEVELOPMENT BOARD PINOUT" this may not be accurate...

using a very simple sketch modified for the board... it's the example sketch that comes with the library, "doesn't work" is not helpful at all... i cannot get the LED to turn off, i've added my own code to attempt to make the LED go dark, unsuccessfully, another "doesn't work" is getting red hues, but that's trivial for my experiment, i think it's a matter of resistor values....

attached image of wiring


/*
RGBLedExample
Example for the RGBLED Library
Created by Bret Stateham, November 13, 2014
You can get the latest version from http://github.com/BretStateham/RGBLED
*/
#include <RGBLED.h>

// Declare an RGBLED instanced named rgbLed
// Red, Green and Blue LED legs are connected to PWM pins D8,D6 & D5 respectively
// In this example, we have a COMMON_ANODE LED, use COMMON_CATHODE otherwise
RGBLED rgbLed(13,12,14,COMMON_ANODE);

//How long to show each color in the example code (in milliseconds);
int delayMs = 2000;

void setup() {
//Initialize Serial communications
Serial.begin(115200);

//Report the LED type and pins in use to the serial port...
Serial.println("Welcome to the RGBLED Sample Sketch");
String ledType = (rgbLed.commonType==0) ? "COMMON_CATHODE" : "COMMON_ANODE";
Serial.println("Your RGBLED instancse is a " + ledType + " LED");
Serial.println("And the Red, Green, and Blue legs of the LEDs are connected to pins:");
Serial.println("r,g,b = " + String(rgbLed.redPin) + "," + String(rgbLed.greenPin) + "," + String(rgbLed.bluePin) );
Serial.println("");
}

void loop() {

//The code in the loop shows multiple exampls

//Set the RGBLED to show RED only
//printRgbValues() prints various LED values to the Serial port
//you can monitor the serial port to see the values printed
//The delay(delayMs) waits for 1 second to be able to see the color shown
rgbLed.writeRGB(255,0,0);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show GREEN only
rgbLed.writeRGB(0,255,0);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show BLUE only
rgbLed.writeRGB(0,0,255);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show YELLOW (RED & GREEN) only
rgbLed.writeRGB(255,255,0);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show ORANGE (RED & partial GREEN) only
rgbLed.writeRGB(255,128,0);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show PURPLE (RED & BLUE) only
rgbLed.writeRGB(255,0,255);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show PINK (RED & partial BLUE) only
rgbLed.writeRGB(255,0,128);
printRgbValues();
delay(delayMs);

//Set the RGBLED to show a random color
rgbLed.writeRandom();
printRgbValues();
delay(delayMs);

//Set the pins individually if needed
rgbLed.writeRed(255);
rgbLed.writeGreen(255);
rgbLed.writeBlue(255);
printRgbValues();
delay(delayMs);

//The above code does the same thing as...
rgbLed.writeRGB(255,255,255);
printRgbValues();
delay(delayMs);

//Show the color wheel
Serial.println("Showing RGB Color Wheel...");
Serial.println("------------------------------");
//Use a 25ms delay between each color in the wheel
rgbLed.writeColorWheel(25);

//Turn off the RGBLED
rgbLed.turnOff();
printRgbValues();
delay(delayMs);

//Turn off the RGBLED
rgbLed.writeRGB(HIGH,HIGH,HIGH);
printRgbValues();
delay(delayMs);

rgbLed.writeRGB(LOW,LOW,LOW);
printRgbValues();
delay(delayMs);

rgbLed.writeRGB(0,0,0);
printRgbValues();
delay(delayMs);

digitalWrite(D7, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(D6, HIGH); // turn the LED off by making the voltage LOW
digitalWrite(D5, HIGH); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a seconddelay(1000); // wait for a second
[/b]
}

//printRgbValues prints the LED pins and values to the serial port
//You can monitor the serial port to see those values
void printRgbValues() {
Serial.println("Requested RGB Values:");
Serial.println("(r,g,b)=(" + String(rgbLed.redValue) + "," + String(rgbLed.greenValue) + "," + String(rgbLed.blueValue) + ")");
Serial.println("Mapped RGB Values based on type (COMMON_ANODE or COMMON_CATHODE):");
Serial.println("Mapped(r,g,b)=(" + String(rgbLed.redMappedValue) + "," + String(rgbLed.greenMappedValue) + "," + String(rgbLed.blueMappedValue) + ")");
Serial.println("------------------------------");
}
You do not have the required permissions to view the files attached to this post.
User avatar
By schufti
#71259 if OFF would result in a pwm value of 255 then your problem is the incompatibility of Atmel Arduino and ESP Arduino implementation of PWM. The "original is 0...255 on ESP it is 0...1024, so maybe i little tinkering with the lib is necessary to get it compatible with ESP.