Espruino Pico and SD cards

Posted on
of 2
/ 2
  • Which one's the actual recording? Or did you not post that up yet?

  • -> the raw audio files posted are what I aim to play

    -> I didn't record what I get yet ;/
    => I'll try your suggestion as well ( & record what I get then )

    -> yup, I'll just edit the File IO page on your github repo => quicker & simpler ;)

  • haha, you ROCK ! ^^

    the following worked on the buzzer

    var PICOSPK=B4;
    var wave = require("fs").readFile("G01.raw");
    var w = new Waveform(wave.length);
    //analogWrite(PICOSPK, 0.5); 
    analogWrite(PICOSPK, 0.5, { freq: 40000 } );

    Also, it seems I can't use B4 nor B7 for my bigge speaker when connected to USB/serial & using SDcard on SPI1 ;p

    1 Attachment

  • since I gotta solder an additional wire, the next video ( with PICOSPK as output, aka 8 ohms 0.25W speaker ) 'll arrive a little after the above one ;)

    btw: I stumbled upon your "single button combination lock" -> I gotta say you made my day": with few modifs, it 'd be prety much what I needed for what I currently intend to do with the Pico pictured previously ;P

    Nb: I also think about adding an ESP8266 to have WiFI capabilities, but I don't have any shim at my disposal :/
    => if I'm correct, I can have both Wifi & SDcard, right ? ( the Pico is soo little .. )

  • All right, I added a quick doc on how to hack an SD card adapter in the FileIO page
    -> I may add as well additional pics taken WHEN soldering ( may help some viewers think twice before tanning the MISO pad on the SD card adapter .. )

    -> I'll post back recordings of streaming off the SD & playing with the said-speaker as soon as done adding wires ;)

  • all right, both seems to work, even if the volume of the speaker is not loud ;p

    nb: as B3 is also SPI1SCK, I guess it's not a good idea to have my buzzer on that pin, right ?
    ( although it seems to work, I bet it may cause side-effect, for the least .. )

    ps:didn't know wiring a speaker to a buzzer 'd result in audio being played twice / Espruino OOM
    ps2: didn't know either my buzzer 'd sing when close to a soldering iron ;p

    anyway, I post my current code below, it needs a few additions ( starting with "single button combination lock"-like input, which 'd trigger the rest, aka the playing audio & triggering a relay .. )

    any personal hint on driving an 8 ohms speaker with a Pico using the smallest possible components while having a loud sound ? ( B0 stuff ? )

    -> this being said, I'll be back [ right ] after reading the said-combination-lock tut'

    see ya ++

    1 Attachment

  • code

    1 Attachment

  • Great, glad it's working! Thanks for the pull request - I'll try and get it in soon.

    Yep, you can do WiFi and SD card no problem, as long as you're not trying to use the same pins for 2 different things...

    As long as you're not using the same pin for anything else, it's fine to use it for the speaker - but with something like an 8 Ohm speaker you should really drive it with something else as the Pico will be struggling to put out that much power!

    So you saw the Pico FET tutorial? That would be a good one to use if you don't need the battery capability.

    For best results, add a 100 Ohm resistor between the BatIn pin and GND, and a 10uF capacitor between BatIn and the speaker (then connect the other side of the speaker to GND).

    You could always look at buying an amplifier module - they're actually really cheap, and you just wire up power and GND. Then ideally you'd just add a capacitor and a resistor down to GND, and you could use any signal pin without the FET.

  • Hi there !

    -> last message here:
    I consider starting a new thread aimed at my project/its needs, not to polute too much the current one & later easier to rework for a tut ;p
    Still, some of the following is relevant to the SD card question(s) ( particularly for the 2nd link posted in "the good stuff" )

    This being said, onto the good stuff, as well as few important questions I have left after re-re-reading the Pico documentation ;)

    -- the good stuff --

    -- the questions left / thoughts on previous answers --

    1. for the WiFi + SDCard, we agree, I just have to solder precisely enough to use USART2 ;)

    2. for B3/SPI1SCK, I thought it could have side-effects as it's the clock line of the SDCard in my setup .. and I must admit I'm wondering how to have 3 different SPI devices connected if some pins have both SPIMISO & SPIMOSI or other "combo" ?

    3. I did stumble upon the Pico-FET tut when looking for how to play PCM/PWM audio on the Espruino, and now that I have read it entirely + Pico#Power, I have yet more questions ..

    4. I did not look long/good enough to find an example for the "deep sleep" functionality, a hint ?

    5. Is it possible the "reset" the Espruino without losing all previously saved stuff ( aka power off then power on, to trigger onInit(), .. ) ?

    6. If it's not possible, I guess a cap + a transistor & a pin to short it to Gnd 'll do the trick ?

    7. In the same vein, is it possible to save stuff to flash without re-initiating ( aka, 'save()' specific stuff / entire stuff without then triggering 'onInit()' ) ?

    8. Am I right to think 'save()' re-init but doesn't reboot ?

    9. For B0/FET: when you talk about "monitoring the battery charge via software", have you an example of how to do so ?

    10. Still for B0/FET: we can have our own battery charging circuit* before VUSB
      with B0/FET shorted & no software-based battery charge monitoring, right ?

    11. I've seen some 555-based circuit that 'd charge a battery when it's below a certain threshold ( not that I implemented one yet :| )

    -- main subject/goal --
    ( see images attached )
    After stumbling upon a post on HaD, on hacking intercoms, I wondered if mine was also hackable, in which case I couldn't not pack-a-punch it :P !
    Thing is, my configuration seems different than other intercoms, & not all infos I need were provided, so I wrote myself a quick doc' :)
    Now, while I can successfully trigger the opening of the ground floor door when ringing the intercom, I still have some guesses on some parts of the circuit:

    • using an external 5V power source is possible, but really not handy considering I have no socket near my appartement door. Using the 12V power source from the door opener ( "AP" ) seems a good solution, but I have to keep the Pico running while a relay shorts said-"AP" to Gnd, to open the ground floor door. In your opinion, will the circuit work as expected ( schematic n°1 ) ? any hint on some secure values for the components involved ( here, the cap & resistor ) ?

    • to get the Ringer not to kill a pin, I'm currently using the schematic n°2 to clamp a maximum voltage from the [3..10]V that's coming from the Ringer to an acceptable digital 1 ( aka, at least 2.5V). While it seems to work, I'm a beginner in using zeners, and after looking at the Pico#Power diagram, I wondered if a Schotty could be used instead ?

    • to be able to output some sound to the ground floor speaker, I may need to "rebias" ( right ? ) the circuit of the original mike ( that's off when "P2" is not pressed ). Here, while I don't know exactly how this part of the hack is done, I bet the transistors used in the schematic n°4 are used to vary the voltage on an already "middle"-d voltage ( when "P2" is pressed/simulated ) or also adjust the voltage to half the original one & wire that to the mic + ?

    • the schematic n°3 pictures both the circuit explained in Pico-FET & the one you advised: is the second correct ?

    • last but not least, when you talk about "cheap audio modules", are you including single transistor amps circuits, LM386 & Cie or more advanced ICs ? these could run from any pin, without the need to short B0/FET, as for the said-"audio modules" I guess ?

    • [ I can't help it ;P ] do you know if it'd be theorically possible to use a mike & speaker as not-ultrasound "disturbance sensor" echo/ping ( using FFT ? ) ? ( aka know if anything stands in front of / near a mike/speaker combo that'd face a wall at like ~2.5 meters )
      ( yes, goal 'd be to sense when someone is/stays before the intercom for some amount of time & play a not-creepy mario sound to help her waiting ^^ )

    Thanks in advance for your help, as always useful,
    Looking forward to reading from you on this, & hoping the repo's code 'll be of any use ;)


    ps: as you'll notice in the pics, the relay is quite bulky for the available space: I plan to switch it with a a MOC3041M + BT138 or just a TIP120 if it's fine, but I'm less familiar with TIP120 & the said stuff than my little NPN/PNP PN2222/2N3904/2N3906 :/
    => "time 'll help" ;D
    ps2: the video shows the current state of the project running on an Arduino: it hasn't been tested yet on the Espruino & I don't wanna fry it ;p

  • pot-pourri ;p

    Nb: I keep getting "413 Request Entity Too Large - nginx" ..

    1 Attachment

  • next batch

    3 Attachments

    • IMG_8903.JPG
    • IMG_8901.JPG
    • IMG_8898.JPG
  • last batch !

    2 Attachments

    • IMG_8919.JPG
    • IMG_8922.JPG
  • sorry for the rotated photos: didn't took the time to rotate them ..

    3 Attachments

    • FullSizeRender(2).jpg
    • FullSizeRender(1).jpg
    • FullSizeRender.jpg
  • Wow - sorry, I'm in a bit of a rush today so can't look through this properly.

    It'd be well worth posting separate questions in future though, as I doubt other people will be able to find the info they need in here ;)

    I'm wondering how to have 3 different SPI devices connected

    They can all share SCK/MOSI/MISO - it's just that each needs its own CS pin.

    "deep sleep" functionality, a hint ?

    setDeepSleep(1)? You only have to call it once, and that's good enough.

    Is it possible the "reset" the Espruino without losing all previously saved stuff

    Not sure I understand, you just use save()? Or you can call load() to do a soft-reset to the previously saved state?

    is it possible to save stuff to flash without re-initiating

    No, save() has to re-initialise. But you can use the Flash module to write directly to flash memory - you just have to use an area of Flash memory that isn't used for anything else. On the Pico there's an 'undocumented' page after 384kB.

    Am I right to think 'save()' re-init but doesn't reboot ?

    Yes, it's not a full reboot - but it still changes the pin states back to inputs and then starts again.

    For B0/FET: when you talk about "monitoring the battery charge via software", have you an example of how to do so ?

    There were some posts here, but you just need two equal resistors to divide the voltage down to a level suitable for Espruino, then you use analogRead(thePinYouConnected)*3.3*2

    Still for B0/FET: we can have our own battery charging circuit* before VUSB with B0/FET shorted & no software-based battery charge monitoring, right ?

    Yes, if you don't use the battery input for a battery you can use it as you want. It's just that the FET input for the battery means you don't get a voltage drop - and otherwise you'd have to add a diode if you planned to use a battery and USB.

    I've seen some 555-based circuit that 'd charge a battery when it's below a certain threshold ( not that I implemented one yet :| )

    For LiPo batteries I'd strongly recommend you just buy a charger chip- they're cheap, easy, and won't blow your battery up :)


    Yes, to me it looks like that'd work. Keeping the Pico running via a capacitor would work fine, and using a zener to limit the voltage to 3.6v would work fine too.

    HOWEVER: While you can put 12v on the Pico's 5V/VCC/VUSB pins and it won't cause problems, the B0 FET will only work when the Pico is powered from 5v or less. Any more and the FET will be constantly on.

    It would be significantly easier to use a separate amplifier in that case.

    Audio amp

    I don't really know - pretty much anything would work I imagine. The PAM8403 boards on eBay look good?

  • Hi there ! :D

    .. talking about rushes .. I've managed to extract myself from one ;p ..

    -> First of all, sorry for the late answer, & thanks for the great answer ;)

    -> The "bypass original mic audio" works FINE ! ^^
    I ordered 2 PAM8403 boards ( considering the price ;p ), to have them handy, but using a BC547B worked flawlessly, with a pretty good quality & being actually pretty loud ;)

    -> I 'll be testing the replacement for the relay this evening ( MOC3022M + BT138 )

    -> "For the sake of clarity & Cie", I'm about to create a thread in Projects explaining the project, its current status & the bits that are left to be done, as well as links to the code

    -> Also, the test-code I wrote quickly to get an array of audio files from SD to randomly play from 'd surely benefit from refactoring to fit in wih the rest ( more on the Project thread ;p )

    This being said, last few hours of work & I'll be back uploading stuff here ( .. )

    => Also, I am working on some other handy stuff on which I'll be giving updates soon if it can be handy to one of us* :)­alculator

    • no moz-.. prefixing for the moment, and is fine on tablets but 'got to re-implm the touch handling to be less "overkill" ( used a lib for quick POC ;p )

    This being said, keep up the good work ++

    ps: 'stumbled upon the memory page stuff you were talking about -> neat, can't wait to test that ^^

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

Espruino Pico and SD cards

Posted by Avatar for DrAzzy @DrAzzy