@Omemanti
I think the AM2320 has got an "One-wire mode", at least if you look at the datasheet. I have not tried it though.
I also had great difficulties in getting the AM2320 to work with I2C until I realised late last night that I had forgotten to include the pull-up resistors, 4k7 each from SDC and SDA to Vcc. All other I2C sensors I have used have had them included on the breakout board but this sensor does not have them built in the sensor body.
Now it works like a charm, one measurement of temp and hum every 2 minutes.
There are a few arduino-libraries for AM2320 floating around. I use this: (https://github.com/thakshak/AM2320)
Here is my sketch:
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
*
* Temperature and humidity measurement using the AM2320 with I2C interface
* Battery voltage also monitored using internal reference
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_NODE_ID 23
#define BATTERY_SENSE_PIN A0 // Input pin for battery sense
#define VMIN 1.0 // (Min input voltage to regulator according to datasheet or guessing. (?) )
#define VMAX 3.22 // (Known or desired voltage of full batteries. If not, set to Vlim.)
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <SPI.h>
#include <AM2320.h>
#include <Wire.h>
#include <MySensors.h>
#define DEBUG_PRINT 0 // Print temperature and humidity measurements on serial i/f. 1 = Yes 0 = No
unsigned long SLEEP_TIME = 120000; // Sleep time between reads (in milliseconds)
bool receivedConfig = false;
bool metric = true;
float temp, hum;
// Create an AM2320 instance
AM2320 th;
// Initialize AM temperature message
MyMessage msgt(CHILD_ID_TEMP,V_TEMP);
// Initialize AM humidity message
MyMessage msgh(CHILD_ID_HUM,V_HUM);
void before()
{
// use the 1.1 V internal reference
#if defined(__AVR_ATmega2560__)
analogReference(INTERNAL1V1);
#else
analogReference(INTERNAL);
#endif
}
void setup()
{
Serial.begin(115200);
Wire.begin();
}
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Temp. Hum Sensor", "1.4");
// Present temp/humidity sensor to controller
present(CHILD_ID_TEMP, S_TEMP);
present(CHILD_ID_HUM, S_HUM);
}
void loop()
{
//Get temperature and humidity from AM2320
switch(th.Read()) {
case 2:
Serial.println("CRC failed");
break;
case 1:
Serial.println("Sensor offline");
break;
case 0:
temp = th.t;
send(msgt.set(temp, 1));
hum = th.h;
send(msgh.set(hum, 0));
if (DEBUG_PRINT == 1) {
Serial.print("humidity: ");
Serial.print(th.h);
Serial.print("%, temperature: ");
Serial.print(th.t);
Serial.println("*C");
}
break;
}
sleep (200);
// get the battery voltage
int batValue = analogRead(BATTERY_SENSE_PIN); // Battery monitoring reading
float Vbat = batValue * 0.003363;
int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
sendBatteryLevel(batteryPcnt);
sleep(SLEEP_TIME);
}```