• Hi,

    I have designed a circuit based on ESP32 and now I am learning Espruino: I am mainly a HW guy and bored of C programming for uC... I decided to learn a high level languaje. Obviusly zero previous experience in JS.

    My first impressions are really good: quite easy to deploy a webserver for example. But on the other hand I have found some difficulties around how get the control of some peripherals. I hope someone can give a me hint on:

    1. I only find timers examples for delays (SetInterval()). Is there any way use a timer as counter rather than "SetTime" to 0 and "GetTime" when something happens?. Moreover, on this way I can use only one of the 5 HW timers at the same time... :-(.
    2. How can I access to the RTC ? How can I configure external clock ?. I would like to "place" precisse alarms instead of calibrate the clock from time to time.
    3. Really there is no way to change the WiFi DNS name when connected as client? Then.... what is the usual procedure to identify several clients from the server?


  • Espruino doesn't generally expose hardware at that level (it differs too much from platform to platform to come up with a useful API). However you can look at the chip's datasheet and can then use peek32 and poke32 to mess around with the actual hardware and configure it exactly as you want.

    On ESP32 that might be harder though since you're working under an RTOS, which will definitely want control of some of the peripherals.

    Really there is no way to change the WiFi DNS name when connected as client?

    There is on the Espruino WiFi board and ESP8266 (Wifi.setHostName()) - I just don't believe it has been implemented for ESP32 yet.

  • Thanks Gordon,

    I see, I see... peek and poke seem to be very powerful since you can access the SFRs the only issue, I have been exploring for 3 hours, is that the reference manual (my opinion) is poor documented: bit fields are not enough explained, names of registers and bit fields are not clear (they change on different paragraphs), there are no examples, etc. So it is quite difficult to configure the peripherals. I have done this kind of before with other processors in Linux (mainly Freescale i.MX) but those RM have >5K pages and all is clearly documented. I guess the best way is understand how to configure the peripherals is to study the esp-idf framework: much more work than reading a RM :-(.

    I will keep testing.

  • I should add that other chips are much better documented. For instance if you used an official Espruino WiFi there's a tutorial on using the F4 peripherals here: http://www.espruino.com/STM32+Peripheral­s

    And there's a library to handle some basic tasks on the nRF52 used in Puck.js and Pixl.js as well: http://www.espruino.com/NRF52LL

  • There's is an mDns library in the esp32 esp-idf library - however it's not been implemented as at the time there was some discussion around using a pure JavaScript module that could then be used across all platforms.

    Is this to know what ip to connect to? You can add the MAC address to your router and dish out a static fixed ip on your network as a work around.

    As Gordon mentioned, the timers are abstracted in JavaScript. How precise do you want your alarms to be? If they are the only thing running, then the event will get fire and run pretty close to the time.... what is you want to do?

  • @Gordon, I understand where @MaNu82 comes from. I personally would like to have some resources accessible on and thru the JS level, for example to use a timer in a simple way. It may then inhibit other appliances, such as usart, i2c,... but would be nice. How to implement without complicating the use of Espruino can be a challenge, I could imagine, especially when it should be flexible.

    For a timer used straight forward to, for example, count external events, the Espruino JS should not be involved in the actual counting. JS should only be involved for setup and watch over/under/cycle runs, and also set a time interval the timer would actually count and a trigger when time is up (to a higher precision than with existing JS setTimeout() / setInterval() can do (I assume that these are not as accurate as a native implemented version of them).

  • @allObjects that's exactly what you can do with http://www.espruino.com/STM32+Peripheral­s and http://www.espruino.com/NRF52LL. Someone is welcome to contribute modules/examples for ESP32/ESP8266 as well if they want to.

    My point is really that you're using the hardware to do what you want and JS isn't involved - so execution speed isn't an issue. That means you might as well just use a JavaScript module to set everything up because you then have all the flexibility of JS - and everyone can easily contribute fixes/tweaks to the module.

  • Thanks to all,

    well, I asked just in case and trying to learn but none of the issues seem to be 100% crucial, I mean I have already programmed most of the code really quickly so and now that I know how powerful is JS I am not going back to C. Regarding to the issues:

    1. Finally I can make all the "regular" timming work only using SetTime & GetTime.
    2. I would like to use the internal RTC so I will try to do the config in C, test it and copy/paste registers. If doesn't work I will consider to place an external RTC or just measure the offset and calibrate a non precisse timer.
    3. As Wilberforce said DNS names are not the only way to identify nodes so I guess I will find another way: MAC, broadcasting, or something else.


  • Great!

    Using an external RTC isn't such a bad idea if you need accurate timing - it's unlikely the ESP32 will be able to remember time after a power-cycle, but a cheapish external dallas RTC will come with battery backup.

  • Gordon,

    in fact my system is permanetely AC powered (I don't need battery backup) and will take the time from internet from time to time so... placing an RTC instead of callibrating a time is just an issue about sloth :P.

    Most probably I will use the timer since 1$ for the XTAL was acceptable but extra 2$ is almost the cost of the ESP32...


  • Hi again,

    I just discovered this link:


    Does it work for ESP32 port? Wouldn't solve a lot of uncompatibility issues? For example, I also tested "deep sleep" and resets the uP...


  • Well.... I just read my previous "tought" and was a bit stupid :-(, might be can help a bit but w/o all the C libraries included it doesn't make much sense...


  • As you say it's not going to be much use as you'd probably need access to the whole EspressIF SDK.

    But Inline C isn't implemented on ESP32 or ESP8266 - it only works for the boards that I sell since it's using my servers (and adding support for a new architecture would be pretty painful as well).

  • Ahhhh ok. With "that I sell" you mean that you are part of the staff who created Espruino (or simply you)? Congrats! :-)


  • Yes, it's just me developing and running it day to day. The ESP8266/ESP32 ports are done by some very dedicated individuals for free though :)

  • Great Gordon!. I would very proud of myself if I were you :-). Unfortunately I can't help in the project at software level since I am not an expert. However I will be happy to help in HW issues if you ever need it (I have +10y in HW development with designs from microcontrollers to microprocessors).


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

Newbie questions: timers as counters, RTC access and DNS alternatives.

Posted by Avatar for MaNu82 @MaNu82