-
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. -
The bare wire is the electrical connection to the shield. You should connect it to signal GND at one end (the Espruino) and leave it unconnected at the other end.
To reduce noise on the analog inputs you could add an RC low pass filter. A resistor in series with the wire and a ceramic capacitor from the analog input to signal GND.
To filter out noise and get more stable readings I use to collect a series of at least five readings, throw out the two highest and the two lowest readings and use the remaining reading (the median value). There will always be the jitter caused by the 12 bit ADC, but you can reduce it by taking for example eight readings, throwing out the two highest and two lowest values and calculating the average of the remaining four values.. -
I can connect to Espruino through the HC-05 when I use my Win 7 PC and also from my Android tablet. It is just with the Edison that I am having a problem learning 'how to', so I was hoping someone with more knowledge already had the answer. there is an in depth Bluetooth user guide for Edison, but it is written for programmers. " Take this file and include the necessary changes from this other file and blabla it should work".
By the way, my trouble with using the web IDE over Bluetooth definitely is appearing when I do not throttle the communication speed in the IDE settings. it seems to work fine when I check this box "Throttle Send". except in some cases I cannot get a working connection at all, even when using the Toshiba Bluetooth stack. I get the impression that Bluetooth compatibility is quite a mess, and software and drivers can be full with bugs. -
I think DrAzzy is doing a good job of explaining how to read the data sheet. And there is also lots of good detailed information if you google "how to read MOSFET data sheet". if we just look at this particular MOSFET that I mentioned (ZXMN2F30FH), I can show how I go about finding out how much current it can handle:
first, find out how much power dissipation it can handle. to do this, I have to decide how hot I want to run the transistor. I usually set +125C as maximum. then I decide on the hottest ambient temperature. let us say +40C. 125-40=85C. then I find the figure for thermal resistance from junction to ambient, 131K/W. so the maximum power dissipation it can handle is 40/131=0.3W. then I estimate the resistance Rds(on) at 3.3V. for this transistor I have values for 2.5V and 4.5V, and I decide that the resistance at 3.3V will probably be close to the average of these two values, so I say that at room temp and 3.3V gate voltage the resistance is (0.065+0.045)/2=0.055 ohm. but at 125C the resistance will be higher. Fig 4 tells me that it is about 1.3 times higher at 125C than at 25C, so I will use 0.072 ohm for the resistance value. Now that I know R and P it is possible to calculate the maximum current I that the transistor can handle. it is sqrt(P/R) or 2.0A.this is the procedure that I normally use for quickly figuring out how much steady state load current I can safely run through a specific MOSFET.
2A is a lot less than 4.9A, is it not?
if the MOSFET is switching on and off there will be additional power loss especially is it is driven from a GPIO pin, so it may be necessary to use a gate driver between the GPIO pin and the MOSFET gate - especially if the MOSFET is larger than this SOT23 size device we have been discussing. -
-
-
if we look at the datasheet I linked to, Vgs(th) is the threshold voltage at which the MOSFET starts to conduct current (0.00025A). This threshold is between 0.6V and 1.5V, at room temperature. This is good information in the way that if we have 1.5V on the gate we should be able to run at least 0.00025A in the MOSFET and can expect that the drain voltage will be 1.5V or below. But most of the time our loads are larger than 0.00025A, are they not?
Now, the threshold voltage is not useful information if we want to control a real life load. If the load is for example 2A we will need a lot more gate voltage if we want the transistor to turn on. If we look at figure 3 we could be fooled to expect that we only need 2V gate voltage. But don't forget that this curve is showing only typical behavior and with 5V across the MOSFET. totally useless information, because 2A * 5V = 10W. the MOSFET would expire in a puff of smoke if we tried that.
The only section in the data sheet that gives us any solid promise is the Rds(on) value at 2.5V gate voltage. If we apply 2.5V at the gate and the load current is 2A we know that the resistance will be max 0.065 ohm, if the transistor is at room temperature, because the data sheet says so. the power dissipation then is 0.065 * 2^2 = 0.26W, and we can be sure that the transistor can handle this heat dissipation. the temperature rise will be about 34 degrees.
With bipolar transistors (npn or pnp) the common mistake is to look at the DC current gain value and forget that this is specified at a relatively high voltage drop. for switching loads we have to look at the saturation voltage, and read the values of base current and collector current and the saturation voltage, to get an understanding of what the transistor can do. in most cases an ordinary bipolar transistor is not suited for driving amperes of load current, because the required base current is so high that it is unpractical to drive from a GPIO pin. it can be very difficult to figure out how much current is going into the base with a certain base resistor, because the GPIO output voltage will sag as the pin current increases. and it is many times not well specified what current will be available from the pin. and in the same microcontroller, the drive characteristics for GPIO pins can be different. -
The Web IDE has a hard time connecting to the Espruino. Most of the time when I connect to the > Espruino in the console I would receive Connect and nothing more instead of the
console outputting the double =undefined. When that happens, I noticed
when I click the upload code button I would get the upload status bar
but the code doesn't actually upload.I have been struggling with similar issues when I am trying to connect through HC-05 Bluetooth from a Win 7 (64bit) machine with a USB Bluetooth dongle. there will be two COM ports created and they behave exactly as described above. If I manage to create a third COM port with outgoing connection it usually works fine. But not always. It can happen that I manage to create a third COM port that is outgoing but it does not work. I am thinking that the problem is related to the Bluetooth drivers on my Win 7 not really working with the HC-05, but I have no clue. I am following this discussion in hope of finding a clue to my Bluetooth connection issue.
I use Blutetooth settings to Add Device, HC-05 appears, then I get to type in the four digit code, I open the Web IDE and there are two COM ports, both incoming. I can connect but all I get is
Connected
then after a while I get
Disconnected -
you are on the right track. Vce(sat) indicates what voltage drop to expect across collector-emitter with (in this case) 10mA collector current and 1mA base current.
(http://diodes.com/datasheets/ZXMN2F30FH.pdf)
if you want to control a transistor with a GPIO pin, have a look at n-channel MOSFETs such as ZXMN2F30FH. there are dozens of part names to choose between. Look for parts that have Rds(on) specified at 2.5V. this one will have maximum 0.065 ohm resistance with 2.5V gate voltage. beginners make the mistake of looking at the spec for gate threshold voltage, but that is specified at very low current level. this MOSFET will start to turn on at typically 0.9V, but to drive high current you need more gate voltage. a 3.3V GPIO can drive this MOSFET with drain currents over 4A. -
update:
I have kept the web IDE throttled and only once have I experienced the problem since then. the problem appeared when I was downloading code to the Espruino. garbled text appeared in the left pane of the IDE. I repeated the download without any more problems.I am wondering if perhaps my wireless mouse that was only inches away from the HC-05 may have been part of the problem. the desktop computer with the bluetooth dongle is about 1m away from the HC-05.
-
-
With the Espruino board, I am using a serial display and I am also using the SD card. The serial display only requires TX pin on the Espruino, the RX pin is unused. Right now I am using C10 (UART4 TX) for the display and I have left C11 (UART4 RX) unconnected.
I am wondering if I can instead use UART5 TX for the display even when I have the SD card in use? In the list of pins not on connectors I see D2 being used for SD card and it also has UART5 RX, which I assume means that if I do not use the SD card then I could use UART5.
But what if I use the SD card, can I use the UART5 TX pin for the serial display with no problems? The communication with the display is only one direction. This would allow me an extra serial port. (I am running out of pins). -
I tried enabling and disabling throttling in the IDE settings and the conclusion is that the problem only appears when I do not have throttling enabled. I will keep using the bluetooth connection for a while with throttling enabled and see how it goes.
the problem was that I received garbage when downloading code into the espruino, or I got only part of the code. sometimes garbage would be printed on the computer screen (left window in the IDE) while I was downloading.
sometimes I would not be able to communicate using bluetooth at all, even if it connected. finally the espruino was so messed up it did not respond at all. I had to reflash with the latest espruino version (I already had the latest version, but this was the only way to restore contact, using bluetooth or USB cable).
after reflashing over USB, unplugging and then powering from external 5V it as possible to again communicate, also with bluethooth connection. now the IDE will stay throttled until I find out if this is the solution. the thing is that I just replaced the bluetooth dongle (again) it could be part of the solution. I have to try other dongles when I get time.
thanks for the help! -
the enclosure is a PPLX box from http://www.pactecenclosures.com. somebody at work was giving away unused boxes so I got a few for free. the NHD‐0420D3Z‐NSW‐BBW‐V3 display fits after I milled away part of the standoffs that hold the screws for the lid, I just used a drillpress with a router bit. when cutting the opening I make it only large enough that the display can be inserted with some force, then it requires no mounting screws.
The idea with bar graphs is definitely interesting. I am measuring four analog signals (V and A on input and output) and also two temperature signals and for diagnostics half a dozen other signals.
I am having trouble with the HC-05 bluetooth connection, it does not seem to be reliable enough for downloading or reflashing. perhaps it is a noise related issue, but I have tried many different bluetooth dongles on my pc and come to the conclusion that bluetooth drivers on Windows 7 64 bit is a mess. this is the one problem I must solve before the control box can be used as intended. it is out of the question to connect a USB cable to the Espruino. I really need the bluetooth connection to work. or perhaps I should go for wifi. I would like to include a relatively large operators manual on the SD card and also make it possible to upgrade the data on the card. -
a circuit board will certainly help if I build more than a few of these gadgets, I spent long evenings with this home project, soldering all the wires. the control box contains the Espruino board in addition to the status LEDs, rotary encoder, some buttons and a 4x20 serial display. the box is used in bench testing and for showing the different functions of a power circuit that sits on a 6x6 inch demo board (not shown).
Espruino allows me to easily interact with the system while the power converter is running. I can adjust set points and functions using the box, or connect over Bluetooth to monitor a a number of analog signals and take control during test sequences controlled by my PC.
I use the SD card to store setups and probably will add a way to upgrade and modify the software over email or internet, so that customers can evaluate the power converter after customizing it for their special requirements. -
Update: My project is moving along. I am using Espruino boards for my test setup. One project is now at the stage where I am building circuit boards that contains a power converter that handles input and output voltages up to 80V. the power stage is able to control power flow in both directions and can be paralleled for high power applications.
the circuit will interface to an external micro controller, and that is where I am using Espruino boards. more details to follow.
Thanks Gordon,
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.
Thank you!