Back to Home

Electric demon and carbon dioxide

electric imp · imp · co2 · gas sensor

Electric demon and carbon dioxide

    The other day, two curious devices arrived from America: the micro imp computer electric imp and the optical sensor for the level of carbon dioxide in the air K30. Each of them is curious in its own way, I will tell a little about each of them and about their combination.



    Electric imp



    Impe is a kind of enraged in German folklore. As well as an abbreviation for Interface Message Processor, one of the predecessor projects of the Internet . The creators of the system recognize both predecessors. In life, this thing turned out to be a pretty compliant, well-documented platform for developing embedded applications.

    An article-review of Internet announcements can be found in the article on the hub , I will try to talk about the specifics and subtleties that became clear during the work.


    How it works



    Grandma feeds imps, source: Wikipedia

    The system consists of three parts:

    1. Imp . Everyone saw him in the pictures, this is the same SD card with LEDs inside and a photodiode at the “upper” (opposite to the contacts) end through which the configuration of the wifi network is written into it. I will repeat the main characteristics of the "SD-shki" filling:
       


    CPU: Cortex M3 32 bit
    Wifi: b / g / n (!), WEP, WPA, WPA2, WPS, WPS-PIN.
    I / O:6 legs that can be configured for GPIO or built-in RS-232, I2C, SPI, PWM and ADC. There is a built-in pulse counter and interrupt processing for events on the first leg. The purpose of the legs can be changed during the execution of the program.

    The supply voltage is 3.3V, the maximum is 3.6V, the logic is not 5V tolerant. There is a voltage regulator on my scarf with a connector, so it can be powered with any voltage, but the signals should be 3.3V.

    Imp performance is a separate, curious topic. ARM promises for the Cortex-M3 12.5 DMIPS / mW, whatever that means. In the coming days I want to measure the performance of the processor and the wifi imp with some tests, I will be grateful to the readers who will tell me where to look for generally accepted speed tests for embedded platforms. Well, or just advise how to do it better.

    Programmed imp in squirrelthat I can’t say anything bad about. This is such a "script C". Those. syntax - from C, dynamic types, automatic memory management - from scripts. The interpreter and bytecode compiler are 7K lines in C ++. The interpreter can be downloaded as a source for linux or installed from macport on a poppy. Classes related to imp itself are described in the development wiki

    2. Impee, “imputable” . This is the connector into which imp is inserted. Each connector has an identifiable chip identifier ( ATSHA204), which is involved in encrypting traffic from imp to the Scheduler. In the scheduler, it is impee, not imp, that are displayed in the form of rectangles. And your code, or as they call it, “firmware”, is downloaded when impee is turned on with any imp inserted. That is, imps can be freely rearranged if the saved wifi configuration allows them to connect to the network. Immediately after switching on and establishing a connection, the firmware that is associated with this impee in the Scheduler will be poured into the inserted imp. After uploading the firmware, the Internet connection may be disconnected, the imp will continue to work, but, accordingly, there will be no connection with the outside world. There is no firmware download from the local network and they will not do it.

    3. Planner. This is the same cloud service that all electric imp-a reviews mention. Free for development imps, but I haven’t seen others on sale yet.
    It performs two independent functions: creating and editing firmware for imps and combining imps and wimps (virtual imps). Virtual imps at the moment are modules executed on the electricimp.com server, written by the electric importers themselves. It is not yet possible to upload your code as a virtual imp. Now there are exactly 10 WIMPs, of which almost useful - three: sending and receiving HTTP requests, as well as publishing data on the cosm.com service.



    Imp programming


    The sequence of starting a running IPM looks like this.

    1. Impa need commission, put into operation. To do this, you need to insert it into the connector (impee), flashes (blink up) to transfer the configuration of the wifi network to it. Live it looks something like this:


    2. After that, a new blue rectangle corresponding to impee will appear in the Scheduler. In the menu, you can select the firmware intended for this device.

    3. The firmware must be written and debugged. This can be done directly in the corresponding scheduler interface. It is divided into two parts, the code is written in the upper part, error messages and the operation logs of the imp are displayed in the lower part.
    My code for imp-a , which receives and publishes data from the CO2 sensor on cosm.com, as well as a screenshot of the editor in the explorer with the imp-a output log. Please note that in the code there are no procedures related to communicating with cosm. This communication takes place via the output interface, to which the virtual imp (vimp) is connected in the scheduler, in the screenshot above it is light green.

    CO2 sensor



        

    It is interesting to measure the CO2 level in a room for three reasons.

    Firstly, this gas in high concentrations is not useful in itself. Weak excess leads to a feeling of stale head and stale air. A significant increase in CO2 level (up to 0.2 - 0.5%) leads to heart palpitations, loss of concentration and mild nausea. Levels greater than 0.5% are considered toxic, more than 4% are life-threatening.

    Secondly, in ventilation systems, CO2 sensors are used as a “canary in the mine”. It turns out that, as a rule, elevated CO2 levels are accompanied by elevated levels of other air pollutants, such as phenols and natural gases. Those. CO2 sensor can be considered as a common "air quality sensor".

    Thirdly, CO2 is conveniently measured by the optical method (NDIR), which gives exceptionally good temporal, temperature and selective (i.e. insensitivity to other impurities) stability.

    The K30 sensor is the cheapest ($ 65) CO2 level meter based on the nondispersive infrared sensor (NDIR, en.wikipedia.org/wiki/Nondispersive_infrared_sensor ). We can say that the NDIR sensor is a spectrometer that measures the absorption of light of a single wavelength depending on the concentration of the measured gas. For CO2, an infrared LED with a wavelength of 4 micrometers is used.

    In addition to the analog output, the sensor can communicate with the outside world via I2C and RS-232 protocols. I could not connect to it via i2c, neither imp, nor arduino uno. At the same time, I took the code for the arduins from the manufacturer’s datasheets, but failed to receive a single byte (and it seems even to send successfully, which is absolutely surprising) from the sensor. I do not have a logical analyzer, so I did not get an accurate diagnosis, but most of all it seemed to be a mismatch between the implementations of the i2c protocol by the sensor and the controllers. The documentation of the i2c imp interface is also lying - the write method returned -2, although it should have -1 for an unsuccessful send, in general I decided to turn to the good old RS232.

    Unfortunately, it is necessary to communicate with the sensor via the heavy industrial protocol ModBus. Fortunately, the datasheet provides a magic string of bytes that must be sent in order to read the CO2 measurement data. So I did not go deep into industrial protocols, sent a magic line and received a normal answer!

    Now the level of carbon dioxide in the room where my imp is and the sensor can be found here . Now the sensor is periodically in the "gut out" state and disconnected from the cosmos, but I hope when you read this article it will be online.

    conclusions


    I really liked electric imp for its originality and thoughtfulness of the concept, as well as its lack of connectivity. Its cloud part, including the documentation, still bears traces of rapid revision, but I hope that the guys will go and we can use imps where it is appropriate and convenient: in home automation, robots and monitoring systems.

    The K30 carbon dioxide sensor is convenient and reliable when communicating with it via the RS-232 interface. I2C requires debugging, I'm not the only one who has encountered this problem.

    Read Next