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.
/* 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.