General area when it fits no where else

Moderator: Mmiscool

User avatar
By Barnabybear
#47169
Or possibly I am missing something here maybe analouge write is possible without the use of more hardware?

Hi, lets forget about your project for the moment. As you correctly state ESP8266s don't have any DAC so all GPIOs are digital outputs. This would be pretty limiting, so the clever chappies allowed us to use PWM to simulate an analogue output and gave us a simple way to do this analogWrite().
analogWrite(pin, value) enables software PWM on the given pin. PWM may be used on pins 0 to 16. Call analogWrite(pin, 0) to disable PWM on the pin. value may be in range from 0 to PWMRANGE, which is equal to 1023 by default. PWM range may be changed by calling analogWriteRange(new_range).
PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.

Extract from: https://github.com/esp8266/Arduino/blob ... ference.md

I thought analogWrite() was 0 to 255 by default but I'm often wrong.

So back to your project:
If you look at the sample code for the dimmer they link on thier website it uses analogWrite() as the source for PWM.
Code: Select all/* Arduino smooth dimming code for controlling the AC Dimmer Board via PWM */

const int analogOutPin = 9; // Analog output pin that the AC Dimmer Board is connected to
                               //   (Digital Pin 9)
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
//pinMode(analogOutPin, OUTPUT);
  // initialize serial communications at 9600 baud:
  Serial.begin(9600);
}

void loop() {

while (outputValue < 100){
  delay(10);
  analogWrite(analogOutPin, outputValue);
  sendSerialMessage();
  outputValue++;
}

while (outputValue > 1){
  delay(10);
  analogWrite(analogOutPin, outputValue);
  sendSerialMessage();
  outputValue--;
}

}

void sendSerialMessage(){
    Serial.print("Dimmer set to: ");
    Serial.print(outputValue);
    Serial.println("%");
}

From: https://github.com/AdvancedNewbie/BlueD ... UpDown.ino

I appreciate this is all a bit confusing but I don’t think you will need any more parts just some changes to your code. Swap out the PWM section you have at the moment and Use analogWrite() instead, even the wiring should be correct.
User avatar
By schufti
#47179 yes, if the module accepts pure analog input, using the pwm-api in the esp-fw through analogWrite() seems the best solution, if necessary with simple RC filtering. The pwm-api should not be influenced by internal "multi-tasking".
Any attempt to synchronise with zc by interupts will hardly be successful because of indeterministic delays.
User avatar
By trackerj
#47236 MPDMv4 Module is a Voltage Controlled AC MAINS Dimmer.

Just apply on the VCNT pin a Analog voltage between 0-2.8V (Vcal value) and that's it.

You can take a look also at theSoftware example and the Youtube videowhere I hope is quite well explained how is works.

And below the ESPBasic code example used for testing:

Code: Select allcls
let pinNo = 5
let Brightness = 890
print "Control PIN"
textbox pinNo
print " Brightness"
textbox Brightness
button " Set Brightness " [SetBrightness]
button " Exit " [TestExit]
wait

[SetBrightness]
pwo pinNo Brightness
wait

[TestExit]
end


A, and by the way, the PWM implementation in ESPBasic looks way better that the one the NodeMCU LUA.
User avatar
By forlotto
#47265
Barnabybear wrote:
Or possibly I am missing something here maybe analouge write is possible without the use of more hardware?

Hi, lets forget about your project for the moment. As you correctly state ESP8266s don't have any DAC so all GPIOs are digital outputs. This would be pretty limiting, so the clever chappies allowed us to use PWM to simulate an analogue output and gave us a simple way to do this analogWrite().
analogWrite(pin, value) enables software PWM on the given pin. PWM may be used on pins 0 to 16. Call analogWrite(pin, 0) to disable PWM on the pin. value may be in range from 0 to PWMRANGE, which is equal to 1023 by default. PWM range may be changed by calling analogWriteRange(new_range).
PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.

Extract from: https://github.com/esp8266/Arduino/blob ... ference.md

I thought analogWrite() was 0 to 255 by default but I'm often wrong.

So back to your project:
If you look at the sample code for the dimmer they link on thier website it uses analogWrite() as the source for PWM.
Code: Select all/* Arduino smooth dimming code for controlling the AC Dimmer Board via PWM */

const int analogOutPin = 9; // Analog output pin that the AC Dimmer Board is connected to
                               //   (Digital Pin 9)
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {
//pinMode(analogOutPin, OUTPUT);
  // initialize serial communications at 9600 baud:
  Serial.begin(9600);
}

void loop() {

while (outputValue < 100){
  delay(10);
  analogWrite(analogOutPin, outputValue);
  sendSerialMessage();
  outputValue++;
}

while (outputValue > 1){
  delay(10);
  analogWrite(analogOutPin, outputValue);
  sendSerialMessage();
  outputValue--;
}

}

void sendSerialMessage(){
    Serial.print("Dimmer set to: ");
    Serial.print(outputValue);
    Serial.println("%");
}

From: https://github.com/AdvancedNewbie/BlueD ... UpDown.ino

I appreciate this is all a bit confusing but I don’t think you will need any more parts just some changes to your code. Swap out the PWM section you have at the moment and Use analogWrite() instead, even the wiring should be correct.


Was not entirely sure how the code work but it is already mapped via analogue write according to mmiscool...

Internally the pwo command maps to this arduino function
https://www.arduino.cc/en/Reference/AnalogWrite

It allows for pwm output.

io(pwo,d4,500) for example.

internal source code is
Code: Select all
else if (PinCommand == F("pwo")) analogWrite(pin, PinValue);

- See more at: viewtopic.php?f=43&t=9939&p=47214#p47214


Thank all you guys for going out of your way on this but I believe I will simply wait at this point got 10ft ceilings and no ladder kinda tired of playing around in a little black box while holding a flashlight on my tip toes on my kitchen chair lol!

I'm going to wait for the new boards to come in so I can do some testing at ground level so I don't have to mess with one of my primary sources of lighting to figure out the issue errr lazy I know lol but bench testing is so much better when trying to trouble shoot something lol !

Thanks to all though you have all been a great help I have plenty of angles and ideas to hit this with when the time comes but I will say:

"Have an idea keep them coming I will add it to my list of things to check."