Control "ws2811" addressable rgb led strip with esp32 - esp32

I have bought an addressable RGB Led Strip from banggood. It was titled as an ws2811 RGB Led Strip. But I only have found ws2811 RGB Leds which aren't Strip, but LEDs connected with some wire. I have some doubt that these are ws2811 LEDs. I think they are ws2812 LEDs titled as ws2811s. Now I try to control them with my ESP32 with the FastLED library but it does not want to work...
Here is my code:
#include <FastLED.h>
#define LED_PIN 27
#define LED_COUNT 1
CRGB leds[LED_COUNT];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, RGB>(leds, LED_COUNT);
}
void loop() {
leds[0] = CRGB(255, 0, 0);
FastLED.show();
}
Here is my wiring:
My problem is that it does not want to work!
Has anyone an idea why?
Thanks a lot!

The esp 32 if I'm correct outputs 3.3V signal. The minimum voltage for WS2811 signal input is 5V. So you will need to use transistor to step up the voltage. I tried it but it didn't work, perhaps i choose the wrong transistor but it was the only one i had available that is PNP. Also please respond if you find the solution. :)

Related

How to implement rc command on virtual joystick?

I need to implement a Tello command, which is rc a b c d on a virtual joystick. From different forums, I came to know that for virtual joystick, we need to use rc commands to move the Tello drone. But I don't know how to implement it. In their SDK documentation, they have mentioned it as
a:left/right (-100~100) b: forward/backward (-100~100) c: up/down (-100~100) d: yaw (-100~100)
What do these negative values mean? How can I use the rc command to move the drone?
This is the virtual joystick code which I am using:
JoystickView joystick = (JoystickView) findViewById(R.id.joystickView);
joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
#Override
public void onMove(int angle, int strength) {
// code goes here
}
});
The values -100~100 normally are the velocity for their respective axis. Depending on the coordinate system set and the control modes for the axes, the aircraft move along the axis corresponding to the value. Based on the code you provided I assume the strength value represents the percentage how much the stick is pushed/shifted and the angle value shows the direction into which the stick is pushed.
For the virtual Sticks you need to set the Control modes and coordinate system by accessing the flight Controller:
setRollPitchControlMode(RollPitchControlMode.VELOCITY);
setYawControlMode(YawControlMode.ANGULAR_VELOCITY);
setVerticalControlMode(VerticalControlMode.VELOCITY);
setRollPitchCoordinateSystem(FlightCoordinateSystem.BODY);
The modes chosen above ensure that the virtual controller behaves the same as the default physical remote controller.
Additionally you need to activate the virtual Sticks with the setVirtualStickModeEnabled method before you can use them.
Now for the continuous control over the aircraft you need to send the virtualStickData with at least 5 Hz:
SendVirtualStickDataTask task = new SendVirtualStickDataTask();
this.timer = new Timer();
this.timer.schedule(task, 0, 200);
In this example SendVirtualStickDataTask extends TimerTask and only sends the current pitch, roll, yaw, and vertical throttle values to the drone via the sendVirtualStickFlightControlData method from DJI SDK inside the run() method of TimerTask.
Finally the current pitch, roll, yaw, and vertical throttle values are set inside your onMove() method you posted in your question. E.g. you can use the trigonometric functions sin and cos to determine the x- and y- parts of the strength value, something like this:
pitch = Math.cos(angle)*strength;
roll = Math.sin(angle)*strength;
Please note that the angle needs to be radian and you probably need to cast the angle/strength to float. Furthermore depending on how the angle value is determined you need to adjust the value accordingly.
The second joystick can be used to control the vertical throttle and the yaw. you will need a bit of fine-tuning and testing.
For the control modes/coordinate system, the following DJI SDK Documentation is helpful (scroll down to "Virtual Sticks"):
https://developer.dji.com/mobile-sdk/documentation/introduction/component-guide-flightController.html
DJI also has a basic code example for the virtual Sticks usage:
https://developer.dji.com/mobile-sdk/documentation/android-tutorials/SimulatorDemo.html
I highly recommend using the DJI Flight Assistant 2 Software to test your code before you attempt to fly in the real world.

Running NodeMCU with Arduino

I got my first NodeMCU today and I'm trying to run the blink sketch from Arduino http://www.arduino.cc/en/Tutorial/Blink
I've installed ch340G driver (as its mentioned in my nodemcu) and everything went without any errors.
However the problem is, it says the program is uploaded 100%, but the LED is not blinking. I would expect the LED to blink after the upload.
Following is a screen shot of my setup:
Also, I did bit of googling and I've seen port errors can be caused by poor cables, but I'm using my GoPro cable here.
There are 2 leds on the Nodemcu.
It might just be that the second led might be faulty.
Add this at the start of your blink code example
#ifdef LED_BUILTIN
#undef LED_BUILTIN
#endif
#define LED_BUILTIN 2
This will change the pin number for the builtin led, to the 2nd led on the Nodemcu.
Check if it works. If it does, then the 1st led is probably faulty.
I hope this helps.
It seems to be loading fine, try restarting the board(reset button).
Maybe the LED is on another pin,
nodeMCU pin numbers do not have to correspond to the ones used in arduino framework, take a look here for a possible pin mapping, example sketch and schema.
EDIT:
LED is on pin D4

graphics card getting activated during video? A test using a java (Processing) program

I have an application I was running that I created with Processing where I was drawing a lot of objects to the screen. Normally the sketch runs at 60 fps and predictably when a lot of stuff is drawn to the screen, it starts to reduce. I wanted to see what changing Processing's renderer would do, as there is a P3D option when you set the size. P3D is a '3D graphics renderer that makes use of OpenGL-compatible graphics hardware.'
I noticed that the performance improved when i used this in that I could draw more objects to the screen before framerate dropped, without really having to change anything in the code. Then i noticed something odd.
I started up the computer the next day and ran the program again and noticed that suddenly the framerate was lower, around 50 fps. There didn't seem to be anything wrong with my computer as it wasn't doing anything else. Then I thought it probably has something to do with the graphics card. I opened a youtube video and it seemed to be fine. Then I ran the sketch again and it went back up to 60fps.
I just want to know what might be going on here hardware wise. I'm using an NVIDIA GTX970 (i think its OC edition). It seems to me that watching the video sort of jump started the card and made it perform on the processing sketch properly. Why didn't the sketch itself make that happen?
as an example:
Vector<DrawableObject> objects;
void setup()
{
size(400,400, P3D); /// here is the thing to change. P3D is an option
objects = new Vector<DrawableObject>();
for(int i=0;i<400;i++)
{
objects.add(new DrawableObject());
}
}
void draw()
{
for(int i=0; i<objects.size(); i++)
{
DrawableObject o = objects.get(i);
o.run();
}
}

Getting pixel colour not accurate

I'm currently using colour picking in my application.
This works on the PC, however I'm having trouble to get it working on a variety of devices.
This is probably due to the context being set up differently, depending on the device. For example, as far as I'm aware the PC is set to a colour of 888, whereas a device might default to 565.
I was wondering if there's a way in OpenGL to get the current pixel/colour format, so that I can retrieve the colour data properly?
This is the function I'm using which works fine on the PC:
inline void ProcessColourPick(GLubyte *out, KDfloat32 x, KDfloat32 y)
{
GLint viewport[4];
GLubyte pixel[3];
glGetIntegerv(GL_VIEWPORT,viewport);
//Read colour of pixel at a specific point in the framebuffer
glReadPixels(x,viewport[3]-y,1,1,
GL_RGB,GL_UNSIGNED_BYTE,(void *)pixel);
out[0] = pixel[0];
out[1] = pixel[1];
out[2] = pixel[2];
}
Any ideas?
Yes, but it's a bit complicated.
Querying the bitdepth of the current framebuffer is fairly easy in ES 2.0 (note: this is also legal in Desktop GL, but this functionality was removed in GL 3.1 core. It's still accessible from a compatibility profile). You have to get the bitdepth of each color component:
GLint bitdepth;
glGetIntegerv(GL_x_DEPTH, &bitdepth);
Where x is one of RED, GREEN, BLUE, or ALPHA.
Once you have the bitdepth, you can test to see if it's 565 and use appropriate pixel transfer parameters and color values.
The format parameter for glReadPixels must be either GL_RGBA (always supported) or the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES (different on different devices). It's a OpenGL ES restriction.

OpenCV cv::Mat displays empty gray images? Cant find the reason

I just want to display this "img1.jpg" image in a c++ project with using opencv libs for future processes, but it only displays an empty gray window. What is the reason of this. Is there a mistake in this code? please help!
Here is the code;
Mat img1;
char imagePath[256] = "img1.jpg";
img1 = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE);
namedWindow("result", 1);
imshow("result", img1);
Thanks...
I had the same problem and solved putting waitKey(1); after imshow(). The OpenCV documentation explains why:
This function is the only method in HighGUI that can fetch and handle
events, so it needs to be called periodically for normal event
processing, unless HighGUI is used within some environment that takes
care of event processing.
Thanks #b_froz.
For more detials about this issue,you can refer to: http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html#imshow
Note This function should be followed by waitKey function which displays the image for specified milliseconds. Otherwise, it won’t display the image. For example, waitKey(0) will display the window infinitely until any keypress (it is suitable for image display). waitKey(25) will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)
So,not only waitkey(1)could be put after imshow(),but also waitkey(0) or waitkey(other integers).Here is the explanation of the function waitkey() : http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html#waitkey
Are you importing the correct library ?
This is other very easy way to load one image:
#define CV_NO_BACKWARD_COMPATIBILITY
#include <cv.h>
#include <highgui.h>
#include <math.h>
main(){
IplImage* img = cvLoadImage("yourPicture.jpg");
cvNamedWindow("Original", 1);
cvShowImage("Original", img);
}
I think you have openCV correctly installed, so yo can type this (Ubuntu):
g++ NameOfYourProgram.cpp -o Sample -I/usr/local/include/opencv/ -L/usr/local/lib -lcv -lhighgui ./sample
The problem you are having is due to the type of your Mat img1. When you load your image with the flag CV_LOAD_IMAGE_GRAYSCALE, the type of your Mat is 0 (CV_8UC1), and the function imshow() is not able to show the image correctly.
You can solve this, converting your Mat to type 16 (CV_8UC3):
img1.convertTo(img1,CV_8UC3);
and then show it with imshow():
imshow("result", img1);
I hope this help.

Resources