Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

LED Strip colouring in reverse with PiGPIO

Sun May 13, 2018 10:10 am

Hi All

I've been working pretty solidly on my RPi project and have managed to get my way through the majority of things with the sole exception of putting the two components together. The project is to have a sensor night light that will come on when movement is detected around the bed to avoid shin kicks etc when doing a 3am bio break. The bonus being that it won't be too harsh on the eyes and shouldn't wake my partner up.

I've got the sensor working.

I've got the LED strip working (using this tutorial and much other research)

My issue is that the colour of the LED's is reverse to what is being set.

my wiring is as follows

Code: Select all

PhysicalPin9 - Ground
GPIO17 - Red LED
GPIO27 - Green LED
GPIO22 - Blue LED

All feed to bread board currently where they are connected to the middle pin of a MOSFET (LM3940IT to be exact).

The left pin of the MOSFET connect to the strip with their appropriately labelled wire.

The +ve terminal of the LED is connected to the breadboard along with +ve terminal for the external power

There are grounds running from the right most pin of the MOSFETS to the ground on the bread board and then back to the Pi (see physicalpin9 comment before).
Basically the lights work. The only issue being that when I use the pigs commands the numerical value of the corresponding colour is in reverse so that 0 equals full brightness and 255 equals power off.

I'm not overly worried as I can work with this knowing that this is happening, just curious as to why?

Any thoughts?

Cheers
Rey

danjperron
Posts: 2854
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: LED Strip colouring in reverse with PiGPIO

Sun May 13, 2018 12:18 pm

This is strange,

Maybe you should check manually if everything is ok!

Did you forget to connect the GND of the PI to the GND of your 12V supply. Both ground need to be connected!


Ok to check manually is simple.

Connect all the gate of the mosfet to GND instead of the GPIO. No led should turn ON.

Connect one of the mosfet gate to 3.3V and the corresponding color leds should be ON at 100%.
Try it for all the color!

If this step works than your layout is ok and something inverts the signal inside the software code.

In any doubt the best way is to check everything manually! This is a step that a lot of people forget!

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Sun May 13, 2018 12:35 pm

danjperron wrote:
Sun May 13, 2018 12:18 pm
This is strange,

Maybe you should check manually if everything is ok!

Did you forget to connect the GND of the PI to the GND of your 12V supply. Both ground need to be connected!
Yes, the pi has a ground on the same row of the bread board. The Power supply (5v as it's a single strip and they are from a 5v strip that runs off a USB.
danjperron wrote:
Sun May 13, 2018 12:18 pm
Ok to check manually is simple.

Connect all the gate of the mosfet to GND instead of the GPIO. No led should turn ON.

Connect one of the mosfet gate to 3.3V and the corresponding color leds should be ON at 100%.
Try it for all the color!

If this step works than your layout is ok and something inverts the signal inside the software code.

In any doubt the best way is to check everything manually! This is a step that a lot of people forget!
I'll work through your suggestion over the next couple of days. I did try a number of different wiring solutions but none of them were missing any of the connection points. Ive tried the ground in all three positions of the MOSFETs as well as for the wires but not with only two connected at any point.

I figured it was something I've done wrong but for the life of me I can't figure it out.... Yet.

Thanks for the help

User avatar
Burngate
Posts: 5257
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: LED Strip colouring in reverse with PiGPIO

Mon May 14, 2018 8:26 am

Reynastus wrote:
Sun May 13, 2018 10:10 am
... to the middle pin of a MOSFET (LM3940IT to be exact) ...
I was slightly bemused by that - I can't find a FET with that number. The only device numbered LM3940 is a low-drop-out regulator.
Could you confirm that number?

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Mon May 14, 2018 1:19 pm

Burngate wrote:
Mon May 14, 2018 8:26 am
Reynastus wrote:
Sun May 13, 2018 10:10 am
... to the middle pin of a MOSFET (LM3940IT to be exact) ...
I was slightly bemused by that - I can't find a FET with that number. The only device numbered LM3940 is a low-drop-out regulator.
Could you confirm that number?
No no that's definitely the right number. I did post in the beginner forum for a reason... I've never put a circuit together before either so I haven't got any of these ideas sorted.

danjperron
Posts: 2854
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: LED Strip colouring in reverse with PiGPIO

Mon May 14, 2018 1:44 pm

LM3940 is not a mosfet but 2SK3940 is.

The problem with a 2SK3940 is the VGS! VGS is a little to bit high to drive high current at 3.3V. Could you send a picture of your mosfet!

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 7:29 am

Image

Like I said. It's probably not a MOSFET as when I asked for one I got a strange look and then I talked with the guy more and ended up with these (I mean they look pretty similar but then I am a total noon at this)

Ben

https://www.dropbox.com/s/4s00e4sa5jutx ... 6.JPG?dl=0

User avatar
Burngate
Posts: 5257
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 9:53 am

Yeah, you're right - it's not a MOSFET!
It's a regulator, and the bottom line says -3.3, so it's a 3v3 version

FETs come in many flavours, the major divisions being N-channel (for which the gate has to be positive compared to the source for it to conduct) and P-channel (gate negative, you don't want that)
Then there's how much positive the gate needs to be to start switching on, and you want that to be less than 3v3.
And then there's how much power it can dissipate without destroying itself. Bigger and better ones are generally packaged like that device, with a screw hole to mount it on a metal plate, but that package can be used for all sorts of devices, so it's not really a clue for what's inside.

There are hundreds of similar FETs from different manufacturers, with different numbers.
The one mentioned in that tutorial - IRLZ34N - is called a HexFET. The name was given to the technology by International Rectifier who invented it. The gate is laid down on top of the silicon in a hexagonal pattern, which reduces the gate channel width and increases its current-carrying capability. For more info, have a look at Wikipedia, under "Power MosFET"

alphanumeric
Posts: 1422
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 1:28 pm

I used one of these https://www.adafruit.com/product/757 4-channel I2C-safe Bi-directional Logic Level Converter - BSS138, in one of my projects to drive 4 LEDs. A Red, Yellow, Green and Blue 10mm. I wired the Pi's GPIO to the 3.3v side and the 10mm LEDs to the 5V side with series resistors. The resistors set the brightness. Four FET's already all setup for you. And no worrying about damaging your Pi. :D

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 7:55 pm

So ordered one of those breakouts and will have to wait a few days to get it here.

My next question.

Will a 5v power supply run two led strips that are both 5v strips or should I use the 12v PS to run them?

Specifics - each strip is 1m long and has 30 leds. They came from USB plug in leds and the pi can per both just fine from the USB ports (which I'm obviously not doing now)

PiGraham
Posts: 3165
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 8:15 pm

Burngate wrote:
Tue May 15, 2018 9:53 am
Yeah, you're right - it's not a MOSFET!
It's a regulator, and the bottom line says -3.3, so it's a 3v3 version

That makes for a novel power switch!
I suppose that raising the ref pin to 3.3V turns the regulator off and dropping the voltage to zero puts it into normal regulator mode with shorted output so it goes into current limit which is enough to light the LEDs.
Hence the on/off state is inverted relative to what is expected for an N-channel FET.

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Tue May 15, 2018 8:19 pm

PiGraham wrote:
Tue May 15, 2018 8:15 pm
Burngate wrote:
Tue May 15, 2018 9:53 am
Yeah, you're right - it's not a MOSFET!
It's a regulator, and the bottom line says -3.3, so it's a 3v3 version

That makes for a novel power switch!
I suppose that raising the ref pin to 3.3V turns the regulator off and dropping the voltage to zero puts it into normal regulator mode with shorted output so it goes into current limit which is enough to light the LEDs.
Hence the on/off state is inverted relative to what is expected for an N-channel FET.
Novel maybe but insanely infuriating for someone whose never touched any electronics before in their life.

Ive assembled PC's a number of times and that's been fine but as far as any of this stuff is concerned it's all new

alphanumeric
Posts: 1422
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 9:10 am

Reynastus wrote:
Tue May 15, 2018 7:55 pm
So ordered one of those breakouts and will have to wait a few days to get it here.

My next question.

Will a 5v power supply run two led strips that are both 5v strips or should I use the 12v PS to run them?

Specifics - each strip is 1m long and has 30 leds. They came from USB plug in leds and the pi can per both just fine from the USB ports (which I'm obviously not doing now)
It depends on how much current the LED strips draw, and how much current your supply can deliver. Ideally the supply should have a higher current rating than what you intend too draw. You don't wat to try drawing the max current from the supply.

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 10:25 am

alphanumeric wrote:
Wed May 16, 2018 9:10 am
Reynastus wrote:
Tue May 15, 2018 7:55 pm
So ordered one of those breakouts and will have to wait a few days to get it here.

My next question.

Will a 5v power supply run two led strips that are both 5v strips or should I use the 12v PS to run them?

Specifics - each strip is 1m long and has 30 leds. They came from USB plug in leds and the pi can per both just fine from the USB ports (which I'm obviously not doing now)
It depends on how much current the LED strips draw, and how much current your supply can deliver. Ideally the supply should have a higher current rating than what you intend too draw. You don't wat to try drawing the max current from the supply.
I did come across this pretty much after google searching. I've been looking to find out what their draw is but so far have nothing that is really coming out much - I figure it can't be too high though if they can be powered by a standard USB port, furthering this thought (combining things I have read from multiple sources on the internet .... so it must be true....) USB compatible devices should draw no more than 500mA which would then indicate that I would need a 1Amp minimum powersupply @5V to power the two strips.... lets say have a bigger psu than draw and call it a 1.5 amp psu that would be required. Given the powersupply I was planning on using is a 5V, 2000mA supply I should be good? I have a 12v psu as well but just curious about the maths

Cheers

alphanumeric
Posts: 1422
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 11:26 am

Just a heads up, but feeding 12V into something designed for +5V isn't a good idea. That will almost certainly let out the magic blue smoke and destroy your Pi etc.
Depending on what Pi you use, and where you pick off your 5V for the LED's, you may run into a limit on current draw due to the Pi's poly fuse. Standard PC USB ports are limited to 500ma each, and can supply 500ma each. Thats not nessarliy so on Pi, see here, https://www.raspberrypi.org/help/faqs/#topPower

Reynastus
Posts: 12
Joined: Thu May 10, 2018 10:18 pm

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 12:04 pm

alphanumeric wrote:
Wed May 16, 2018 11:26 am
Just a heads up, but feeding 12V into something designed for +5V isn't a good idea. That will almost certainly let out the magic blue smoke and destroy your Pi etc.
Depending on what Pi you use, and where you pick off your 5V for the LED's, you may run into a limit on current draw due to the Pi's poly fuse. Standard PC USB ports are limited to 500ma each, and can supply 500ma each. Thats not nessarliy so on Pi, see here, https://www.raspberrypi.org/help/faqs/#topPower
Oh no I was planning on running the strips through a separate power supply. I have the 12V PSU available but was planning on using the 5V.

alphanumeric
Posts: 1422
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 12:30 pm

"DON"T use the 12V supply, you will fry your LED strips.
I wired the +5V on that board I linked to right to my +5V supply. It doesn't got through my PI at all. In my case its an A+ running headless.

danjperron
Posts: 2854
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 1:39 pm

"DON"T use the 12V supply, you will fry your LED strips.
Depending of the strip this is not true.

If a strip is marked 12V, it will be 3 LEDS in series plus a resistor. This is why the strip could be cut every third led.

Each SMD5050 drop ~3.6V for the green and blue LED but drop ~2.4V for the red one. You put 3 in series and the Voltage drop is 10.8V. The small resistance in series will do the rest.

alphanumeric
Posts: 1422
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: LED Strip colouring in reverse with PiGPIO

Wed May 16, 2018 7:16 pm

danjperron wrote:
Wed May 16, 2018 1:39 pm
"DON"T use the 12V supply, you will fry your LED strips.
Depending of the strip this is not true.

If a strip is marked 12V, it will be 3 LEDS in series plus a resistor. This is why the strip could be cut every third led.

Each SMD5050 drop ~3.6V for the green and blue LED but drop ~2.4V for the red one. You put 3 in series and the Voltage drop is 10.8V. The small resistance in series will do the rest.
That is correct. I was going by the OP's following comment "Will a 5v power supply run two led strips that are both 5v strips or should I use the 12v PS to run them?" Naimly that the strips are 5V strips. Wired in series you might get away with it, they would each get ~ 6V. Hooking them up normally will likely fry them.

Return to “Beginners”

Who is online

Users browsing this forum: jackandjill and 5 guests