Asked — Edited

Led Fade

I am trying to get the PWM going to fade an LED on my IOTiny, but it doesnt seem to be working. I have an IOTiny with 2 servos and camera. I am trying to get an LED to fade on and then off (repeatedly). I will expand to a couple more LED's once I can get this sorted. I have tried the example set forward in tutorial: https://synthiam.com/Community/Tutorials/179/1 I also watched the video on the youtube channel: https://www.youtube.com/watch?v=kY8iJ84J4GE

I believe the code is setting a threshold to achieve (either 0 or 100) and using the servo Speed to determine how quickly it achieves this value. When I watch the applets running the code from a script applet, the PWM just jumps between 0 and 100 (with the 3000ms delay in between). It doesnt graduate.

I set up a script to run the PWMRandom on the port, and while I can see the value changing on the PWM applet, there is no difference at the LED. I measured the output with my analog voltmeter, and my digital meter and it seems to just output ~3v as soon as any positive change to the PWM setting occurs regardless of the value. I was expecting to see my analog meter gradually go up and down. The DMM is autoranging, and probably wouldnt pick up the change and report it effectively. I would anticipate if the value of the PWM applet is low, say 10% the LED would be dim. While 100 would be bright.

I also believe that the PWM applet would be quickly switching the voltage creating a duty cycle that would effectively lower/raise the voltage of the port.

I am powering the IOTiny with a 5v MeanWell power supply rated at 3AMPS. While the documentation states a preference for battery, and a 5Amp requirement, my meter indicates the system only draws 0.18A at idle and even with the camera it never went over 0.4A, so I believe I am within the functionality requirements of the device. To support that position the camera is setup to perform face tracking with servo control and it works fine.

Am I wrong in my understanding? Am i trying to implement PWM incorrectly?

The PWMRandom script is simply:


:Loop
PWMRandom( D4, 0, 60 ) 
goto(Loop)

where as the other script is simply the reference one:


# set the servo speed to 2
ServoSpeed(d4, 5)

:loop

# Set LED On
pwm(d4, 100)

# wait some time for the pwm to do its ramping thing
sleep(3000)

#set LED Off
pwm(d4, 0)

# wait some time for the pwm to do its ramping thing
sleep(3000)

goto(loop)


ARC Pro

Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.

#1  

I've never done this but I think you get the fade speed by setting the servospeed at different values, not the PWM. The brightness of the led would be determined by the PWM. My guess is that the led won't start showing a visible glow until there is a fast enough PWM pulse being fed it. Motors being fed with a pwm pulse wont start moving until the pwm is rather high. Even the smallest of my motors won't move unless ARC's PWM setting is above 15%. larger ones won't move until PWM is above 50% or more. I know we're talking a diode here but the concept is the same.

Are you running both these looping scripts at the same time? If so, don't. Running both on the same port may screw things up. You can set the random effect in just one looping script.

I'd still let the led go totally on with a 100% pwm and totally off with a 0% PWM. If you want random fade speed you can try the ServoSpeedRandom command but place it inside the loop. Example: ServoSpeedRandom(D4, 2, 20) . You may be disappointed because the random effect may be erratic or not even noticeable sometimes. You also need to set the sleep commands high enough to let the longest fade period happen so the led can get to full brightness.

Also try inserting 500ms sleep command after you set the servospeed just incase you're script is going too fast and not setting the servospeed before the led is switched on. You can decrease the timing if this works until it doesn't.

Also double check your wiring and to see you have everything attached to the correct ports that you have set up in ARC.


:loop

# set the servo speed to a random value
ServoSpeedRandom(D4, 2, 20) 

sleep(500)

# Set LED On
pwm(d4, 100)

# wait some time for the pwm to do its ramping thing
sleep(3000)

#set LED Off
pwm(d4, 0)

# wait some time for the pwm to do its ramping thing
sleep(3000)


goto(loop)

#2  

"you get the fade speed by setting the servospeed at different values" I think you are right there. ServoSpeed seems to be how quickly it changes the PWM value.

"Are you running both these looping scripts at the same time?" No, they are seperate examples to try and get this to fade at all.

I will try the random servo speed, but idealy i am just look for a simple pulse/fade on-off.

The wiring is correct. Cathode to GND, Anode to SIG (D4 in my case, though i have tried other ports such as D7). No resistor, because I think the signal peaks at 3.3v.

#3  

I use PWM only on mine (not servo speed).

Have you tested with a PWM object before trying scripting just to see that the LED responds?

I think the issue with your script may be the spaces between the commas and the values. ARC is very strict on correct formatting.

Here is a script that I use to have an LED change brightness along with sound being played (using the Sound servo V4 object)


$Soundv4Value = 0
:loop
waitforchange($Soundv4Value)
PWM(D11,$Soundv4Value)
goto(loop)

Alan

PRO
USA
#4  

Does not work for me.

I waited 10 seconds after each PWMs and no Fade (In or Out).


#start off
Set(D0, 0) 

#set the servo to slowest speed
ServoSpeed(D0, 10) 

:loop
# Set LED On
pwm(D0, 100)

# wait some time for the pwm to do its ramping thing (Fade In)
sleep(10000)

#set LED Off
pwm(D0, 0)

# wait some time for the pwm to do its ramping thing (Fade Out)
sleep(10000) 

goto(loop)

@DJ: Can you advise ?

PRO
USA
#5  

Fade In / Out (without ServoSpeed):


#start off
Set(D0, 0) 

:loop

#fade in
repeat($v, 0, 100, 5) 
  pwm(D0, $v)
  Sleep(200) 
endrepeat 

#fade out
repeat($v, 0, 100, 5) 
  pwm(D0, 100-$v)
  Sleep(200) 
endrepeat 

goto(loop)

Note: This is resource intensive.

#6  

I will try this as soon as I get home.

PRO
Synthiam
#7  

Use a faster servo speed rather than 10. You saw in the video how slow the 4 speed is, so you can imagine how slow 10 is - just use a faster value in your project.

Oh - and according to the documentation for the servoSpeed() command, you are required to initiate a pwm position first. So set a position before executing the command.

PRO
USA
#8  

@DJ: Still not working.

Code updated:

  1. to reflect the pwm initialization:
  2. faster value ServoSpeed

#according to the documentation for the servoSpeed() command
#you are required to initiate a pwm position first. 
pwm(D0, 0) 

# set the servo speed to 2
ServoSpeed(d0, 2)

:loop

# Set LED On
pwm(d0, 100)

# wait some time for the pwm to do its ramping thing
sleep(3000)

#set LED Off
pwm(d0, 0)

# wait some time for the pwm to do its ramping thing
sleep(3000)

goto(loop)

Digital captures:

User-inserted image

Detailed view:

User-inserted image

Notes: D0 (ServoSpeed) code D1 (Manual Fade In/Out) code