Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By flywire
#61606
vdubadub wrote:... Okay easy fix! ...

So your line 20 and 28 need to be changed just a little
line 20 should read io(po, pinNo, pinStat)
line 28 should read io(pwo, pinNo, pinStat)

... I find ... fixing these examples myself ...

Yes that worked. In terms of fixing the examples I couldn't disagree more - examples should work. This is really important when people are learning new concepts and it is good to see lots of examples in the Esp8266 Basic Code Reference. I agree that changing the examples takes learning to the next level.

I'm running the examples to see what I can do with a stock standard LoLin NodeMcu V3 Dev Board with Esp8266 Basic loaded. The examples at https://www.esp8266basic.com/examples.html seem to be bug free so I wouldn't recommend this topic on the forum.

Thanks to everyone, I really like the addition of the slider on the PCM example - if only I knew what PCM was hey?

I don't understand why servo angle doesn't go from 0 to 360. I thought I could probably dim the led on Pin 2 with servo similar to the PCM command. Anyway, I'm still having problems trying to use the servo command to flip the board. ;)
User avatar
By Electroguard
#61612
if only I knew what PCM was hey?

Seeing as the example was about using Pulse Width Modulation, I assume you are asking about PWM rather than PCM.

Consider that a string of pulses is a series of digital ONs and OFFs or HI's and LO's.
The OFFs are empty SPACES, the ONs are full voltage MARKS.
No ONs gives nothing (no volts), all marks gives everything (max volts).
A mixture of MARKS and SPACES can be averaged according to the MARK/SPACE RATIO to give an averaged voltage somewhere between min and max.
Pulse Width Modulation intentionally gives an equivalent of a variable analog voltage from a string of digital pulses by varying the ON to OFF mark/space ratio, resulting in an average output somewhere between max and min.

*EDIT*
If you did mean PCM, for your purposes you could consider Pulse Code Modulation as being the opposite to PWM, whereby an analog signal (typically audio) is converted into a stream of digital word values which digitally represents the frequently sampled analog signal.
Last edited by Electroguard on Fri Jan 27, 2017 11:22 am, edited 1 time in total.
User avatar
By heckler
#61621
if only I knew what PCM was hey?


Electroguards explanation was good and here is another way to describe PWM.

Think of the words "Pulse Width Modulation' So imagine a string of repeating pulses (a signal that repeatedly goes from 0 to 3.3v (or 5 or whatever your systems "high" is))

Now imagine changing (Modulating) the duration (Width) that the pulse stays High. From zero to 100 percent. 50% would be a square wave. 10% would be a pulse train that is mostly low and only high 10% of the time. 90% would be a pulse train that is mostly high and only low 10% of the time.

The more the signal is high the brighter your LED will be (assuming high is LED on).

You are"Modulating" the amount of time that the pulse train is high.

hope this helps.

If you have access to an Oscilloscope then it will immediately become obvious. Sometimes an O-scope is an essential troubleshooting / learning tool.

regards
dwight
Last edited by heckler on Fri Jan 27, 2017 1:21 pm, edited 1 time in total.
User avatar
By heckler
#61626
io(SERVO,{PIN},{VALUE}):
Will set the angle of a servo connected to the the pin.
Angle must be between 0 and 180.
alternative as function
io(servo,{pin},{value})


I don't understand why servo angle doesn't go from 0 to 360. I thought I could probably dim the led on Pin 2 with servo similar to the PCM command. Anyway, I'm still having problems trying to use the servo command to flip the board. ;) - See more at: posting.php?mode=reply&f=40&t=4849#sthash.w62lbEBx.dpuf


Also don't forget that controlling a servo is a special case where the servo is expecting a pulse roughly every 20ms (google servo pwm) So you may want to use the IO(servo,value) command instead of IO(PWM)
The IO(pwm)

The IO(PWM) command is running at around 1Khz whereas the IO(SERVO) command will run at the needed 50Hz which is what a servo needs

If you are just controlling the brightness of an LED the either pwm or servo will work but if you are actually controlling a servo then you need to use the servo command which slows down the pulse train so that the servo gets a new pulse every 20ms.

clear as mud? :D
good luck
dwight