Bluetooth + CC3000 + Battery

Posted on
  • I've got the Bluetooth HC-05 module soldered on, and the CC3000 connected. When I try and power the espruino board with a 9v battery, things appear to be fine initially but after about 5 seconds all the lights go off. The espruino shows a very dim light.

    I can power this off USB via mains. And push code over BT to the board. The battery I'm trying to connect is 9V and fairly new. Without the CC3000 connected I can connect and send code over BT with using the battery alone.

    Do I need more power than the battery can offer for BT and CC3000?

  • Hi Ollie,

    the Espruino has a linear Voltage regulator (MIC5205) so since the electronics need 3.3V as power supply, the excess is converted to heat in the voltage regulator. Assuming your whole setup takes about 200mA current, for a 9V battery this means 5.7V * 0.2A = 1140mW = 1.14W of heat is being generated by the voltage regulator (9V - 3.3V = 5.7 V).
    Since it's mounted on the PCB without really a heat sink, I am guessing it gets really hot and goes into thermal shutdown (The MIC5205 has an internal thermal protection, see the datasheet: There are also some more detailed thermal calculations on pages 8/9 of the datasheet).

    At least that is my guess as to what is happening. The other scenario is that your battery is already too weak to supply the current for the Espruino + BT + CC300 module, but you could easily measure that by checking the battery voltage when you have everything connected.

    I would probably use a rechargeable battery (LiPo) or 3 NiMh cells to power the Espruino. A 9V battery has inherently a pretty low energy density. You could also use a high-efficiency switching regulator circuit to power the Espruino if you really have to use 9V batteries.
    Hope that helps,

  • The 3.3v regulator on the Espruino is rated at 150mA. We don't even need to do the thermal calculations - if you try to pull much more than that, the bottom drops out of the output.

    Per Adafruit CC3000 page, peak power consumption of the CC3k is a whopping 350mA.

    That's why tells us to use VBat to power the CC3000 through it's Vin pin - the Espruino can't supply enough power at 3.3v.

    The 3V3 pin of the Adafruit CC3k module should not be connected.

    So, if you're powering the CC3000 board from the Espruino's 3.3v power source, that's your problem.

    With the 9v battery connected to VBat, and the CC3k module's VIN connected to Espruino's VBat, it should work, provided the 9v battery you're using is capable of supplying the load without falling below 4 volts or so. If it doesn't, I'd monitor the battery voltage and see what it's doing - I'd expect a 9v battery to be able to take that (in pulses); maybe the battery is bad?

    That said, I second Mike's pessimistic assessment of 9V batteries for this (or, frankly, almost any) application. A pack of AA's, some 18650 LiPo's (just remember, for chinese brands, divide the capacity spec by 3-5 to get the real capacity) or other sort of LiPo battery pack would serve you much better. Those rectangular 9v batteries are pretty crap - they're actually made with 6 tiny batteries (smaller than AAA) in series.

  • Thanks both. I have the CC3000 connected to VBAT. But from what you are both saying the battery is probably not up to it. I shall swap out for the Nimh cells mentioned.

    BTW it's terrific for a newbie to this stuff to receive two really detailed and educational replies. Thanks very much for taking the time guys.

    I'll report back.

  • I swapped out the battery for another brand new 9v battery tonight. Works fine, though for how long I woudn't know.

    I have a webserver I can program wirelessly over BT, it sits wirelessly on my network, and runs off a battery!?!

    It's serving a single image, and logging visits, and reading them back from SD card. LED1 also provides an indication it's being 'hit'.

    Espruino is very cool indeed! !

  • Problems about 2 hours into it. Updating wirelessly became hit and miss and device was restarting with 'out of memory' warnings.

    Now I have the image on a CDN, I'm not reading back the logs, and I'm back on USB power, (though I'm not sure the battery is at fault yet).

    Image of 23kb was served chunked as per the docs, but was there a better way to read the log data back into the page? I used var logs = fs.readFile(..) and output directly to the page using res.write(logs). The page then got served.

    Any best practices for using as a webserver?

  • I doubt the out of memory issues are related to the battery, unless the battery voltage was sagging enough that it was killing the CC3k without taking out the Espruino, causing it to get confused while piping the data and not properly free the memory.

    First thing I'd do is run it off USB and check process.memory() to check for memory leaks, and dump() to try to figure out where it's leaking from, if it's leaking from javascript.

  • Does the log keep getting bigger? readFile reads the whole file into a string, so if that ever got too big it would explain the out of memory errors.

    You can instead use E.openFile and pipe to serve up the file a bit at a time. I believe there are some examples on the CC3000 or Internet pages.

  • @Gordon The log was getting bigger yes, and I was using E.openFile for the image, but was using readFile for reading the log back into the page since I had issues trying to continue res.write output (to close the page html) after I'd piped the openFile output. Is this possible? If I did it again I'd pipe the logs and include them in the main page via iframe - I imagine that would work fine?

    @DrAzzy I can't see that process.memory() in the Reference section. Do you include that in a setInterval function and log to console to monitor over time? How do I interpret the returned info?

  • Ahh. I don't know for sure, but you may be able to get a callback when the piping is finished, and then send the final bit of text on that.

    Otherwise you can use the steam IO to manually send the file (rather than piping).

    Or... Did you consider working around it? You could use ajax to load the log from the html file, rather than including it directly.

  • You could do it in setInterval, or just do it manually.

    The relevant data in the object that process.memory() returns are the properties "usage" "free" and "total". The memory is measured in jsvars.

  • "Or... Did you consider working around it? You could use ajax to load the log from the html file, rather than including it directly"

    Ha! I should have, but I didn't. Thanks Gordon, that'll work!

  • @DrAzzy I have searched I promise. How do I relate the 48kb memory to jsvars. For example I have 1461 in the 'free' property. It dips every now and then to '1381' but always recovers to 1461. So no leaks(?) but I no idea how much free memory I have in kb based on that number?

    Edit: I guess a ratio 1461/1800 * 48?

  • v69 is 20 bytes per jsvar, v70 is 16.

    The remaining 12k is used for the interpreter itself and the stack.

    jsvars is the more useful measure of memory than bytes, though, because Espruino allocates memory in blocks no smaller than 1 jsvar (and most variables take 2).

  • If your memory usage sticks at the same number, you could be pretty sure that there are no leaks...

    I'd be pretty certain it was the readFile of the large file that was causing you problems. Sadly 48kB doesn't get you far when you start dealing with files :)

    There's a bit of info in about how the JsVars work. Because memory is stored in blocks, you don't get 100% usage as 4 bytes of each block end up getting used for housekeeping information.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Bluetooth + CC3000 + Battery

Posted by Avatar for Ollie @Ollie