Most recent activity
I am looking for information on if Espruino handles I2C clock stretching. I am running the Espruino wifi in master I2C mode at 100kHz and reading/writing to a slave that occasionally will stretch the clock. One workaround would be to run at slower clock but I wonder if I can run at 100kHz and handle clock stretching.
It is really dangerous for someone with such lack of knowledge in electrical safety to be messing around with mains voltage, especially if there are "signal" wires coming out of the contraption, and these wires are accessible so someone can touch them.
The type of relay boards (and relays) in the picture were never designed with electrical safety in mind and certainly would not pass mandatory electrical safety test requirements if they were part of a product that was marketed. That these relay boards can be bought on the internet is no guarantee that they are safe to use in mains voltage applications.
I found a good web page that explains the 18650 protection.
It is good to know that even with built in circuit board, the voltage limitation remains. the MOSFET used to disconnect the cell is a low voltage one, about 20V rating. so it is better to use an external circuit board that monitors all cells and contains one MOSFET disconnect switch instead of one per cell. (actually the MOSFET is a double MOSFET that makes it able to block current in both directions. a MOSFET always has a body diode that conducts current from source to drain even if gate-source voltage is zero).
the 18650 cells are still in heavy use, for example the Tesla battery uses them. when working with your own battery pack designs, make sure you use cells that have a metal tab spotwelded to the terminals, never try to solder wires directly to the cells!
I worked with very large batteries, some configurations up to 700Vdc and many hundreds Amperes, all using 18650 cells. the type of cell was LiFePO4 which is a lot safer but has only 3.2V nominal voltage instead of 3.7V. as the Dreamliner designers found out, this cell type is a lot safer. (I heard that after some terrible battery fires, their Li-Ion battery had to be enclosed in a fireproof container that vented the smoke and fire to the outside of the plane. this would not have been necessary if the cells were LiFePO4 type. they may burst and the fumes can catch fire, but the destruction usually is contained to one cell, not the entire battery pack).
I did not know that you can actually buy 18650 cells that has built in electronics for protection. The technological development must have sneaked up on me again. 8-)
When I was working with battery electronics ten years ago, the 18650 was a popular choice for battery packs because production machinery was available for this type of cell, it was cheap so it was used in huge quantities even in large batteries. Every cell had (has) a small PTC disc inside, at the positive terminal. When there is overcurrent this PTC resistor heats up and becomes resistive, and this limits the current. For high power cells that allow more han 5A current, the PTC disc had to be replaced by a metal disc, to avoid tripping the overcurrent protection of the PTC disc. The next line of defense was the connections to the cell, they would fuse open. If overpressure built up, the positive cap usually would rip open and that disconnected the cell but unfortunately the spark then ignited the fumes. One weakness of the PTC disc was that it only has 20V rating so when 18650 cells is used in battery packs you have to be aware that when one PTC trips, the entire pack voltage appears across that PTC disc. this can cause arcing inside the cell and is a hazard, so all bettery packs need electronics with overcurrent protection etc. and many other safety functions such as cell balancing and disconnect MOSFET to protect against deep discharge and cell overvoltage.
It will not help to measure the battery voltage, it is too steady and does not indicate how much juice is left. you need to measure the discharge current and integrate. Search for "Coulomb counter". There are ICs that are made for this purpose. Another search term is "battery fuel gauge" and "battery state-of-charge". I think there is a breakout board for LTC4150, for example.
the VBAT pin does not have a stable voltage, so the way I would do it is to use a second ADC input and two resistors. if for example you connect two resistors (with the same value) in series, from VBAT to GND, you get VBAT/2. Measure this signal (you get a reading from 0 to 1) and subtract the current sensor signal reading from this reading. Divide the result by 0.0303 and you get a reading in Amperes. This will give good accuracy even if the VBAT voltage drifts.
Because the sensor can give out a signal that is higher than the 3.3V rating of the analog input pins of the Espruino you have to make sure you connect the current sensor to the load in a way that as the load increases, the output signal decreases. That way, you will apply VBAT/2 (about 2.1...2.5V) and lower to the analog pin. There should not be any risk that you exceed the maximum voltage for the analog input, unless the current flows in reverse for some reason.
You may have to read the datasheet for the ACS712. you should feed it with 5V and the output will be half of the supply voltage at no load, and as you apply a dc load you should expect the reading to change by 0.1V per Ampere (may vary depending on the version of the part).
a change of 0.1V equals a change in reading of 0.1/3.3 = 0.0303, if your Espruino adc has 3.3V max range.
Because the output signal has an offset that equals half of the supply voltage (5V) you need a stable 5V supply to get any accuracy.
I studied the reference manual and got the impression that in Master mode the I2C supports clock stretching, while it can be turned off in Slave mode. There was many pages of information, too much to read through and understand, but the main question I had was if clock stretching is supported when the part is in Master mode on I2C. and that answer seems to be Yes.
I will try the software I2C as soon as I get time. It seems to include clock stretching. I just wanted to make sure, as I found the Raspberry Pi is not able to handle clock stretching, at least as far as I have read online.