I have a GrovePi which I would like to use to control a LED light fixture, as well as report some environmental data.
Specifically, I’d like to control power on/off and dimming of the light, and sense temperature, humidity and electrical consumption.
I have already installed a Grove relay into the fixture, and can power on/off the light with no issue. Adding the environmental sensors has been straightforward as well.
For the next part of my project, I’d like to be able to dim the fixture, and report on the electricity consumption.
For dimming the fixture, the power supply above supports a dimming function using either 1~10VDC, PWM signal, or resistance.
I have looked at the Grove options for this, and I see the MOSFET as a potential solution, however my knowledge in electronics isn’t very strong, and it would be great if I could get some suggestions on the best way to implement dimming with my GrovePi.
As far as electricity usage monitoring, I have also noticed the current sensor options for Grove are limited. Are there any other options for being able to monitor the electrical consumption of the power supply as well?
Hey Paolo, I’m assumng the LED fixture is a 220V sort of thing? You should be VERY Careful working with this.
For dimming, you can get a 5V DC PWM signal out of almost any one of the analog ports on the GrovePi. This would require just a little bit of wire cutting.
For monitoring the current consumption, I think the Grove Current monitor is your best bet. Safest too: you can install it without cutting the line or anything.
I saw in my earlier research that the GrovePi ports can put out a 5V DC PWM signal, unfortunately this won’t work for the LED power supplies I intend on using, because the signal voltage is required to be 10V DC for PWM. This is why I was considering the Grove MOSFET here: http://www.seeedstudio.com/depot/Grove-MOSFET-p-1594.html
I’m leaning towards the Grove Current sensor as well for that part of the project, the current limit of the sensor should be just enough for what I need.
I’ll be more than happy to share the results once we’re done!
I received the MOSFET’s this week and had a chance to sit down and play around a bit tonight.
I have a some questions about the functionality. Based on the example code, I was expecting that the MOSFET would deliver 100% of the source voltage (either from the Pi or an external source) with the command ‘grovepi.analogWrite(mosfet,255)’ and 50% of the source power with ‘grovepi.analogWrite(mosfet,128)’ and so on.
When I connect my multimeter to the output of the MOSFET, I get different results than expected, and also different results depending on which port I plug the MOSFET into.
Here’s a summary of the MOSFET settings and corresponding voltages, with the last column of data showing the voltage readings with a 12v power supply connected to the MOSFET on port D3 of the GrovePi:
analogWrite() Value Voltage Pi #6 Voltage Pi #5 Voltage Pi #3 Voltage Ext #3
0 0 0 0 0
1 3 3 1.68 3.34
2 3.02 3.02 1.71 3.39
4 3.05 3.04 1.74 3.49
8 3.1 3.05 1.82 3.68
16 3.22 3.22 1.96 4.06
32 3.44 3.44 2.25 4.81
64 3.84 3.84 2.81 6.32
128 4.44 4.45 3.84 9.2
147 4.57 4.57 4.11 10
255 4.7 4.7 4.69 12.08
It seems that the output with the MOSFET on port D3 on the GrovePi is somewhat closer to what I would expect than the output while connected to port 5 or 6 on the GrovePi.
Now my main question - Is it possible to get the voltage any lower? With my external 12v power supply attached, I’m unable to get below 3.34 volts.
No, giving analogWrite(3,1) gives ~ 1.68V. It gives ~ 3.3V when I have a 12V power supply connected to the MOSFET’s input.
I was just using the example code for my initial testing, so I would just fire up a python shell and manually run the commands, checking the output voltage each time. The 4th column in my attachment above shows the voltages with the 12V power supply turned on, and the 3rd column shows the voltages without the external 12V, both on D3.
What I’m trying to ultimately achieve is to supply an output voltage of 1 - 10 volts to control a dimmable LED power supply.
The power supply has a built-in dimming circuit which will dim the lights to 10% output with 1V applied to the circuit, 20% with 2V, 30% with 3V and so on up to full power at 10V.
Based on my tests, it seems that the voltage reduction is not linear. I was expecting analogWrite(3,255) to be ~ 100%, analogWrite(3,128) to be ~ 50%, and analogWrite(3,64) to be ~ 25% and so on, as demonstrated here: https://www.arduino.cc/en/Tutorial/PWM
Also not sure why ports D5 and D6 differ so much from D3?
Can you run the troubleshooting script and upload the log on the forums by following the guide here: https://www.youtube.com/watch?v=ZMadpIEYq5o. Can you also update your script. I’ll try running it here and see what output I get.
Hey paolo,
Sorry for taking this long to reply back.
I just tested this on my setup here and it looks pretty good. I tried this program:
import time
import grovepi
led = 3
val=0
for val in range (0,255,10):
grovepi.analogWrite(led,val)
print ("%d,%.2f") %(val, 5.0*val/255)
raw_input()
which basically print the value and waits for input so that I can check on a multi-meter. And this is what I got:
I think my power supply was not beefy so that might be the reason for the displacement, but I was able to get low voltage too. Can you try this at your end and see if that helps.
I followed your suggestions and unfortunately I’m still getting the same result.
I installed the latest Dexter Industries Jessie, updated the O/S, merged the repo, and flashed the latest GrovePi firmware.
As you can see in the picture, I have my Pi2 (Model B) with the GrovePi+ and mosfet hooked up to my multimeter. In the background you can see my terminal window with the most recent command grovepi.analogWrite(3,10) and the multimeter showing 2.22 volts.
I’ve even tried an older Pi, and another multimeter with the same results.
I tried on D5/D6 and the results are even worse in terms of how low I could get the voltage to go. I found D3 to be the best. The widget is the Grove MOSFET.
After experimenting some more I finally got the expected voltages. Not sure how this makes sense, but if there are any kind of wires attached to the input (unpowered) and output sides, the output voltages were in line with what you were getting and what I was expecting - between 0 and 5V
The moment I removed the wires from the terminals, the results went back to 2 to 5V.
So it appears to work as expected only if there are wires in the terminals. Same on all 5 of the MOSFETS I tested. Is that strange or what?