jamarju / livolo-firmware

Livolo light switch firmware
21 stars 9 forks source link

Blue SMD is always on #2

Open adrian-elian opened 5 years ago

adrian-elian commented 5 years ago

I know that this project is for VL-C701X-2 VER: C0 (1-gang, 1-way, no RF, EU version) version but i'm raising this issues as i have a different board and i think that we can help people with different hardware types from Livolo, in the future as we can use this issue also as a guide. I tried to buy that version but it wasn't available so i got he VL-C601-2 (1-gang, 1 way).

The issue that i'm facing at the moment is that the Blue led is always On.

Question 1: How do i change what led is on and what led is off. I already took a look at the PCI 16f690 and i can see that the blue led is connected to Pin 13 (RB4/AN10/SDI/SDA). I will try to draw a circuit diagram and update this issue later.

Question 2: For my project i don't plan to use the 220v part at all, all i want is to have it powered up and communicating with either a nodeMCU (esp8266) or an arduino mini. My second question is, what and how should i detect from the switch that the state of the switch has changed. I tried to connect the RF Tx and Rx pins to the Arduino and opened up a serial port with a 57600 baudrate and Serial.read(); in the loop() method, but all i got were special characters (like a sqare, romb and other symbols that don't mean anything) and i couldn't read or understand anything from it. Show what should i expect to be delivered on the Serial ?

Update 1 : I have tried to reproduce the diagram of VL-C601-2 with as much detail as i could. I attached a picture of the diagram here(Please note that it might be incorrect and i might need a second look at the wires.).

For me it makes no sense on how the LED should operate, and furthermore how can i adapt your code to work with the 2 LEDs (i can power them from an Arduino if needed).

(However, i understand now why the Blue LED is always powered on when i power the board from the PICKIT3 using J5 RF connector) livolo-vl-c601-2-c0

Thanks.

jamarju commented 5 years ago

There seem to be a few changes in the schematic between VL-C701 and VL-C601, so you need to modify the firmware as it won't work as it is.

If you do RB4 = 1 the red LED should turn on (after setting TRISx properly). Note that in C701 it's RB6 who controls the LED (see util.h). Also you can't turn both leds on the way they are wired.

Another change I can spot is that your capacitive sensor uses RC1 as comparator 2's input, as opposed to C701, which uses RC3, so capsensor.c should be reviewed, too.

To get data out of the PIC you'll see in the source code that I had to bitbang RB4, which in C701 goes to the RF OUT pin and it's easier to solder to. Ideally you would use RB7 which is the hardware UART's TX. RB7 is used for the COM logic in 2-way Livolos which is unpopulated in the 1-way versions so there are some SMD pads you can solder to. Anyhow, since C601 uses RB4 to control the LEDs, you can't use my bitbang code as it is either. Try to find which pin goes to RF OUT, or just follow RB7's trace to see where it goes, that way you can use the hardware USART and get rid of the bitbang mess.

Also, I hate to say this after all the effort you're going through, but I eventually found it MUCH easier to talk to 2-way Livolos. They are only just a few € more expensive but they already have bidirectional communication logic built-in through the COM wire and it's much easier to deal with externally (Arduino, ESP8266, etc). I will update this repo with the schematics I'm working on as soon as I got something more or less solid.

adrian-elian commented 5 years ago

Thanks for the detailed response, I'm looking forward in seeing the schematics and your work so far. However i found another project (I can post the link if you'd like me to) where i can flash the PIC using the Pic Basic Pro (working with student edition as well) and it's just one PBP file to edit, which is simpler to manage. Also you can use it for all Livolo products, just editing the some pin numbers (what i had to do with my projects)

Additionally you get 2 way UART support by connecting the Arduino (or esp8266, etc)'s RX, TX to PIC16F1690 RX, TX, (pins 9 and 11 on the JP1 in my case) making it easy to control the switch remote (I'm not planning to use the switch using 220v but in a 24v environment.)

jamarju commented 5 years ago

Here is the schematic I'm working on. The principle of the 2-way Livolos is that you can connect their COMs together and their LIVEs together and they communicate over these two lines while only one of them does the actual switching of the load. COM line is normally 12VDC above LIVE (LIVE being the ground reference from the Livolos standpoint) and serve two purposes:

First, those 12 VDC are generated by the Livolo connected to the load and are used to power the other Livolos on the bus.

Second, by pulling COM's 12 V momentarily to 0 V, you can COMMUNICATE among them. There is a simple protocol to basically signal on/off status so that all the switches on the bus stay synchronized. The protocol works as follows: M (mark) means 0V during 20 ms, S (space) means 12V during 20 ms:

In the diagram below, left side is LIVOLO (COM and LINE), right side is an ARDUINO or another +5V controller (can be made to work with 3.3V devices by just adjusting the resistors).

COM_IN can be used to receive data from the bus. COM_OUT can be used to send data to the bus.

captura de pantalla 2018-11-19 a las 11 55 24

For example, to turn on the lights from Arduino, with pin 4 connected to COM_OUT, you'd simply do:

void turnOn() {
  digitalWrite(4, HIGH);
  delay(60);
  digitalWrite(4, LOW);
  delay(WAIT);
  st = ST_ON;
}

Of course, if you don't mind your Arduino GND being referenced to the mains LIVE, you can skip the optocouplers and simply use a transistor + 100 ohm resistor to pull COM down and simplify that a lot at the expense of being killed if you accidentally touch it.

jamarju commented 5 years ago

More random scribbling.

Same circuit with a small optimization. C3 is used to store energy to drive optocoupler U2 when COM is pulled down by either us (controller) or some Livolo on the bus. This capacitor is charged by the load-driving Livolo through a ~2.4K resistor, which means it charges VERY SLOWLY and this limits how fast we can switch the lights, so it's important to not waste its energy.

By turning Q2 off we (controller) can prevent C3 from discharging when we (controller) pull COM down since we don't really need COM_IN to reflect our own actions.

captura de pantalla 2018-11-19 a las 22 36 15
dzungpv commented 5 years ago

@jamarju I have the VL-C601-2 too and read your comment: "your capacitive sensor uses RC1 as comparator 2's input, as opposed to C701, which uses RC3" but i could not find any RC3 in code, i am new to Pic programmer. Could you give me a hint to change it?

dzungpv commented 5 years ago

I change those:

    // Configure C1 and C2 as a relaxation oscillator
    // See Microchip AN1101
    CM1CON0 = 0b00010101; 
    // C1ON     0------- disable (-> C1OUT=0) to save power
    // C1OUT    -r------ r/o
    // C1OE     --0----- no output on pin
    // C1POL    ---1---- inverse pol
    // unimpl   ----x--- 
    // C1R      -----1-- C1Vin+ = C1Vref
    // C1CH     ------11 C1Vin- = C12IN3-  // C2CH     ------01 C2Vin- = C12IN1-

    CM2CON0 = 0b00100101;
    // C2ON     0------- disable (-> C2OUT=0) to save power
    // C2OUT    -r------ r/o
    // C2OE     --1----- connected to pin
    // C2POL    ---0---- normal pol
    // unimpl   ----x--- 
    // C2R      -----1-- C2Vin+ = C2Vref
    // C2CH     ------11 C2Vin- = C12IN3- // C2CH     ------01 C2Vin- = C12IN1-

For the RC1 but it not work