How to use AM2320?

Posted on
  • Hi guys,

    in a project based on Arduino I used the AM2320 with the following library:
    https://github.com/hibikiledo/AM2320

    I couldn't find any informations how to use it with espruino.
    Can you help me with that?

    Thanks in advance

  • Hi,
    the AM2320 can handle I2C and single-bus.

    Check chapter 8.3 Single bus communication (ONE-WIRE) how to wire this sensor and then try to use module DHT22/AM230x/RHT0x Temperature and RH Sensor

  • Hi @MaBe,

    thank you for your response. I will try that.

  • "single bus" is NOT the same as OneWire!!!

    OneWire is a specific protocol used almost exclusively by Dallas Semiconductor products. The slave devices all have a unique serial number, there's a way to parasite power so you don't need a separate power wire, etc. The Aosong temperature/humidity sensors do not use OneWire, they use their own single wire protocol; calling it a bus is misuse of that term, IMO, as well - "bus" sort of implies that more than two devices can be connected to it - but with no provision for addressing, the single wire protocol that the Aosong sensors use can only ever have two devices connected to it - the sensor, and the controller it talks to (I mean, I guess you could have multiple controllers connected to it, but I still don't think this counts!).

    But yeah, it looks like you can talk to that as if it's an AM2302 (aka DHT22) if you ground the SCL pin. An I2C module for those would be nice though - reading the single wire protocol in javascript doesn't play to Espruino's strengths.... Like, it works, but behind the scenes it's generating IIRC 80 callbacks within just a few milliseconds. An I2C module for it wouldn't be hard to write either...

  • To use AM232x with I2C, it requires a specific "wake up" command which requires a command to be sent, followed by a 800 us to 3 ms delay, then a stop signal. (See section 8.2.4 of https://www.isweek.com/Uploads/20180528/5b0bbbc09cff2.pdf )
    This doesn't appear to be possible using the I2C Espruino module, as granular functions (like beginTransmission, endTransmission in other platforms) are rolled into the 2 functions writeTo, readFrom.
    Admittedly, this sort of granular control with delays isn't exactly Javascript's (or Espruino's) forte.
    I'm unsure if this interaction is considered standard (e.g. https://github.com/espruino/Espruino/issues/390 introduced a "Repeated Start" capability), but perhaps it could be added as a capability.

    Alternatively, you could always bit bang the entire I2C conversation manually. (e.g. http://forum.espruino.com/conversations/286138/?offset=25 ).

    It's probably easier to fall back to the "single-bus" mode (which is wired differently as mentioned above).

    I'm trying to use Espruino with an AM2322 and I ran into this complication.

  • Wow, that's a bit frustrating. It could be that you can do:

    i2c.writeTo({address:addr, stop:false}, WAKEUP_CMD);
    getTime();getTime();getTime();getTime();
    i2c.writeTo(addr, "");
    

    I'm not sure, but that might be good enough to send the command followed by a stop. You could use setTimeout but as you note, because of the tight timing it might be better to just pad it out with a few commands to get a good enough delay.

    But as being as there is already a library to handle AM230x comms in it's single-bus mode it's probably more sensible to just use that

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

How to use AM2320?

Posted by Avatar for iwae @iwae

Actions