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)
I think (not in front of an EZ-B to test) that you need to use a Servo() command, not a PWM() to set the initial position.
Alan
Alan has it - and also, pwm(0) isn't a pwm
Pwm 0 = off Pwm 100 = on
Neither of those are actual pulsing any width lol
So just set something like servo(90) or servo(1) or servo(180) or servo(14) or servo(142)
The servoSpeed() command has a writeup entry in the ezscript manual. You can read it to understand what I'm saying.
DJ,
Please a little recognizement for the time i spent testing, troubleshooting (Digital scope), posting etc.
I know difference between PWM 0% and 100%, PWM is not PPM (Servo pulses), and PWM rates etc etc.
I followed your tutorial code (does not work) and than your obvious comments:
you never mentioned 0, 100
I got my lesson: "Wasted time".
I apologize for not getting this. Based on the documentation for ServoSpeed, what Alan, and DJ are saying would be:
So in my test code i have tried the following:
so the initial state is set by Servo(D4, 0). This turns it off. This seems to be required by the ServoSpeed() Documentation. I then set ServoSpeed(D4, 5) which is halfway between the max and min according to the documentation entry.
this is where I am unclear... Am I using PWM to set the values for on and off "PWM(D4, 0) and PWM(D4, 100)" then relying on the ServoSpeed() to determine how rapidly it moves through the range OFF and ON? I suspect the sleep() is there to eat time while ServoSpeed() is moving the voltage up or down depending on where in the loop it is. I tried using the PWM commands as above, as well as switch PWM() for Servo() and neither performed as I anticipated.
I could just off load to an arduino, but my space is limited in this project and would like to capitolize on the available ports on the IOTiny.
Thank you all for your help =)