Idea: Espruino PLC

Posted on
  • Over the last year, I have been thinking about home automation on a higher level then Sonoff (limited lifetime) or 433mhz (limited possibilities) or even wifi (stability issues). Serious automation is usually done with a PLC (Programmable Logic Controller). These come with a price-tag: a Wago PLC with software license easily sets you back € 600. Cheaper options include a Railduino or Controllino, but as the name suggests, these have to be programmed with the Arduino IDE. I guess I just miss the ease of an Espruino PLC :) How cool would it be to program a PLC with something like this:

    var ledDriver = plc.add('analogOut', A1);
    var ledDimmer = plc.add('rotary', { pinA: D1, pinB: D2, pinSw: D3, function () {
        ledDriver.setVoltage( E.clip(this.position, 0, 10) );
    });
    

    The PLC should have an ethernet-port (not wifi) to interface with (for example) Home Assistant, spitting out JSON over a websocket when the plc-class runs an event (like spinning the rotary, in the example above). And the other way around: the plc-class should be accessable over the websocket by feeding it JSON.

    For future expansions, I would opt for a module based system: a main CPU in a plastic case with a small number of inputs and outputs (analog and digital), and optional modules for specific purposes (4 x input, 4 x output, 0-10v output...). The modules would connect to eachother with a USB-like connector system.

    Gordon, any chance of an Espruino PLC happening? Or even a native ethernet Espruino? I would buy (both!) ;-) Untill that time, it seems that an Espruino Original could do pretty much everything I want it to, when combined with a WIZ550io. Does that still require the special build, even though the CC3000-support was removed from Espruino (and the lack of memory should no longer be an issue)?

    Any thoughts on this would be appreciated!

  • Fri 2019.12.27

    Okay, I'll bite @Thijsmans, but I'll need to be educated on why the current breakout boards are not already the heart of a PLC, sans the necessary connector (and possible drivers) hardware.

    https://www.espruino.com/MDBT42Q
    (would provide smart phone programability)

    Instructions for Espruino and WIZ550io here:

    https://www.espruino.com/WIZnet

    The sample code snippet provided is pretty much how all the current tutorials could be wrapped, to provide that simplicity, should they not be at that level already.

    A $10 plastic case, along with $2 connectors and the desired $4 digital or analog amplifier boards if necessary would keep the entire project well under $100.

    What is preventing the goal you seek?

  • @Thijsmans

    the removal of the CC3000 support was for space reason... Espruino grew since the beginnings quite a lot... an the CC3000 is at its life end by TI's declarations... and mine is collecting dust... (at leat the box it is in). Whether WIZ550io is included in every build... I don't know... but adding it - and dropping something else you are not interested in - should be not that a big thing. Take a look at @JumJum's online build support...

    I see your point of reliability on communication. As much as wired is a good thing, it can also be a bad thing... being wired with WiFi / BLE kicking in as backup could be an option...

  • @Robin

    but I'll need to be educated on why the current breakout boards are
    not already the heart of a PLC.

    They could most certainly be the heart of a PLC. I guess the problem is that I've got an idea, but not a detailed and solid plan. Neither do I have extensive knowledge about electronics ;-) Especially the modular setup looks complicated... Found this thread about serial communication between Pico's, which could be useful.

    @allObjects thanks for the tip!

  • @Thijsmans

    They could most certainly be the heart of a PLC.

    And they are - not just the heart - but the complete PLC. The question is how you program them.

    From your comments I conclude that you expect a higher level of - or more dedicated - sway of programming.

    Looking at what JS already brings to the table and the interrupt driven implementation in Espruino as Hardware, Firmware and Software components / modules, it is already way towering over practically any other (general purpose) micro controller on the market -and even PLCs. And when you would have to pay usage license for what @Gordon and the community have put together, € 600 can be considered 'change'. Said so, does not mean I do not understand what you try to say or the point you make is not taken.

    Developing a next layer / level of programming with a PLC language that is interpreted by a PLCL interpreter is kind of an answer but it breaks the resource budget - memory, cycles, power consumption - these micro controller platforms have to offer and are targeting... Even a Raspberry Pi may reach its limits thinking of something like that.

    A system the way you have an idea of I can see implemented the following way:

    • Satellite / Orbiting Espruinos have a basic infrastructure implemented - including LAN and as backup up WLAN/Wifi or BLE and MQTT and the capability of OTW / OTA update - and run with some dedicated modules sets of sensors. Power supply is POE w/ some local backup to survive a few hours (w/ support of power consuming mode of a satellite).
    • A decent Raspberry Pi (4?) is running the Center / Sun and is equipped with enough memory and storage and connectivity to handle collector / hub / control / monitor / gateway functions.

    Doing something like that non-commercially is quite an exercise... I don't say it is not feasible, but it is a lot of work... and while you settle for a set of sensors, satellite and center configuration and the implementation, these components evolve and settlement becomes pretty quickly outdated.

    This should not discourage you at all to begin with something... You can even run Espruino on the Raspberry Pi (I do though not know about communication support). Start to create a PLC as JS 'class' / prototype that you extend over time with what you need and implement. You come up with some JSON that describes your control definitions that you can send to the PLCs running on each of the satellites of MQTT. Said that, the PLC has core functions to understand receiving such descriptions / configurations, put/update them in place, and start and stop their operation. This is in addition to the operational functions that move control to and data from the PLC control entities and sensors.

  • Well, you could do a hacky PLC right now using a Pixl.js with an Ethernet shield and relay shield? Just not DIN-mount.

    WIZnet support is built into some devices and builds, but can be added pretty easily to others. It still uses a lot of memory so I'm afraid it's not in all the time.

    I am actually looking at doing a small PLC type Bluetooth device (8 IO channels, 1A per channel, 3-18v voltage) that was originally planned to KickStart along with Bangle.js (I just ran out of time!). It wouldn't have Ethernet, but would have IO that could easily be connected to a WIZnet device, and I guess a shield could be made to make that process nice and easy if it was popular :)

  • Just not DIN-mount.

    If you start with a Pixl, Just google arduino DIN-mount. :)
    If you put an arduino shield on the bottom, it should be good to go for a home user.

  • Thanks for all thoughts! I have done some thinking about hardware and code. About the hardware:

    • the Railduino and Controllino setup makes me somewhat uncomfortable. The devices are directly connected to 230 Volts. Through relays, but still... I prefer using seperate DIN-rail mounted relays like Wago, Finder, Siemens... Is this why your channels are 3-18v as well, @Gordon ?

    • These use 12V/24V for inputs (pretty standard, PLC-wise), which a GPIO does not supply. I'll go for Darlington-transistors switching a 12V-line.

    • No matter the board, the number of GPIO's is always a limitation for a PLC. I'll use shift registers for outputs (to drive the Darlington-transistors).

    • I've been looking into i2c-port expanders, but in my experience, these work too slow for high speed inputs like rotary encoders.

    • For inputs I'll use opto-couplers, to prevent blowing up the microcontroller with 12V :)

    • I'm planning on doing 0-10V outputs for dimmable LED-drivers, I guess using an op-amp is the way (not familiar with those yet).

    As for as the actual javascript, I'm using several classes (* = not started yet, waiting for parts):

    • PLC (container);
    • PLC_Display_128x64 (oled);
    • PLC_Input_Digital*;
    • PLC_Output_Digital*;
    • PLC_Output_Analog*;
    • PLC_Bridge (which creates an input and output, and simply mirrors output on input).

    The 128x64 oled was a tad too small, a 320x240 LCD is in the mail. By using a seperate class with standard functions (mainly .bootscreen() and .update() ), changing the screen should be fairly easy. Hell, you could connect different screens at the same time, if you want to.

    About the modular setup, mentioned before... Let's see how a single unit works out first ;)

  • Is this why your channels are 3-18v as well

    Partially, yes. At the low end it's so they can run off a LiPo, and at the high end I wanted to ensure you could run it in a car/boat/caravan/etc as well. Car battery + solar is a really easy way to get loads of power for various outdoor applications, and you can get a bunch of high power relays that run off 12v too.

    But yeah, if it's possible to keep mains voltages away from the same PCB as the microcontroller it's just easier all around... Plus if I made something that handled mains, there's no way it could also run off a LiPo battery and be useful. The other way around you can always use a power supply and relays pretty easily.

  • And just FYI, I know this is an Espruino forum, but there's an actual Arduino PLC now, I have one and it's awesome. https://www.automationdirect.com/open-so­urce/home I have the CPU, IO, and Ethernet shield with it.

  • Seems to be quite an old thread... Did anyone make sort of a PLC running on Espruino?

  • Just to mention:

    I just discovered this really cool open PLC project which provides an IDE and runtime environnment for PLC applications. What I found really interesting is its ability to extend inputs/outputs on various targets through modbus. One can use arduinos, ESP8266, ESP32, raspberry pis, ... to create a distributed PLC system. I think at some point it would be of interest to provide compatibility between Espruino and this project, just because Espruino hardwares are really good devices and can provide useful features like sensing (with puck.js) or displaying (pixl.js) that could help people building home automation applications.

    Of course Modbus is the key for interactions right now but maybe at some point if it could be extended to BLE as well it would make sense.
    If I figure out a proper way of doing this I will post it here, for those who are interested in home automation or PLCs.

  • That looks neat. I seem to recall I had some code for Espruino that did Modbus (there's not much to it - it's just Serial + ensuring you de-assert a pin when you're done transmitting if I recall).

    But personally, I never had a chance to do a PLC. It might have sold a few but I never had enough requests that it seemed it'd be worth the development effort. Probably the best bet now is find an ESP8266/ESP32 PLC device and run Espruino on that. It looks like Shelly have an ESP32 one at least

  • Sure, my idea was not to create a PLC out of Espruino, but rather to expand a PLC system (such as one made with Open PLC Project) with distibuted sensors/actuators which could be Espruino devices.

    At some point I will probably try to write a module capable of exposing ressources through a Modbus RTU client. This way, one could bind physical ressources (sensors, actuators) with the Modbus registers for a remote access.

    To be eventually continued...

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

Idea: Espruino PLC

Posted by Avatar for Thijsmans @Thijsmans

Actions