Hi
Finally I have had time to solder my project, Temp_hum, and started to create the code for it. But I struggle with some bascis
Code for the sensor:
#define MY_NODE_ID 37
// Enable debug prints
#define MY_DEBUG
// #define MY_DEBUG_VERBOSE_NRF5_ESB
#define MY_BAUD_RATE 115200
// Enable and select radio type attached
//#define MY_RADIO_RF24
//#define MY_RADIO_RFM69
//#define MY_RS485
#define MY_RADIO_NRF5_ESB
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define CHILD_ID_VOLT 2
#define IS_NRF52
// #define IS_NRF51
#define SHORT_WAIT 100
// Sleep time between sensor updates (in milliseconds)
static const uint64_t UPDATE_INTERVAL = 6000;
static bool metric = true;
float batteryPcnt;
float oldBatteryPcnt;
#include <MySensors.h>
#include <SI7021.h>
static SI7021 sensor;
void disableNfc()
{ //only applied to nRF52
#ifdef IS_NRF52
//Make pins 9 and 10 usable as GPIO pins.
NRF_NFCT->TASKS_DISABLE = 1; //disable NFC
NRF_NVMC->CONFIG = 1; // Write enable the UICR
NRF_UICR->NFCPINS = 0; //Make pins 9 and 10 usable as GPIO pins.
NRF_NVMC->CONFIG = 0; // Put the UICR back into read-only mode.
#endif
}
void turnOffRadio()
{
NRF_RADIO->TASKS_DISABLE = 1;
while (!(NRF_RADIO->EVENTS_DISABLED))
{
} //until radio is confirmed disabled
}
void turnOffAdc()
{
#ifndef IS_NRF52
if (NRF_SAADC->ENABLE)
{ //if enabled, then disable the SAADC
NRF_SAADC->TASKS_STOP = 1;
while (NRF_SAADC->EVENTS_STOPPED)
{
} //wait until stopping of SAADC is confirmed
NRF_SAADC->ENABLE = 0; //disable the SAADC
while (NRF_SAADC->ENABLE)
{
} //wait until the disable is confirmed
}
#endif
}
void turnOffUarte0()
{
#ifndef IS_NRF52
NRF_UARTE0->TASKS_STOPRX = 1;
NRF_UARTE0->TASKS_STOPTX = 1;
NRF_UARTE0->TASKS_SUSPEND = 1;
NRF_UARTE0->ENABLE = 0; //disable UART0
while (NRF_UARTE0->ENABLE != 0)
{
}; //wait until UART0 is confirmed disabled.
#endif
#ifdef IS_NRF51
NRF_UART0->TASKS_STOPRX = 1;
NRF_UART0->TASKS_STOPTX = 1;
NRF_UART0->TASKS_SUSPEND = 1;
NRF_UART0->ENABLE = 0; //disable UART0
while (NRF_UART0->ENABLE != 0)
{
}; //wait until UART0 is confirmed disabled.
#endif
}
void turnOffHighFrequencyClock()
{
NRF_CLOCK->TASKS_HFCLKSTOP = 1;
while ((NRF_CLOCK->HFCLKSTAT) & 0x0100)
{
} //wait as long as HF clock is still running.
}
void mySleepPrepare()
{ //turn-off energy drains prior to sleep
turnOffHighFrequencyClock();
turnOffRadio();
//turnOffUarte0();
}
void presentation()
{
Serial.println("Presentation");
// Send the sketch info to the gateway
sendSketchInfo("TemperatureAndHumidity", "1.2");
// Present sensors as children to gateway
present(CHILD_ID_HUM, S_HUM, "Humidity");
delay(SHORT_WAIT);
present(CHILD_ID_TEMP, S_TEMP, "Temperature");
delay(SHORT_WAIT);
present(CHILD_ID_VOLT, S_MULTIMETER, "Battery");
metric = getControllerConfig().isMetric;
Serial.println("End presention");
}
void setup()
{
Serial.println("Setup");
hwInit();
disableNfc(); //remove unnecessary energy drains
turnOffAdc(); //remove unnecessary energy drains
while (not sensor.begin())
{
Serial.println(F("Sensor not detected!"));
wait(5000);
}
Serial.println("End Setup");
}
void mySleep(uint32_t ms)
{
mySleepPrepare(); //Take steps to reduce drains on battery current prior to sleeping
sleep(ms);
}
void loop()
{
// Read temperature & humidity from sensor.
const float temperature = float(metric ? sensor.getCelsiusHundredths() : sensor.getFahrenheitHundredths()) / 100.0;
const float humidity = float(sensor.getHumidityBasisPoints()) / 100.0;
#ifdef MY_DEBUG
Serial.print(F("Temp "));
Serial.print(temperature);
Serial.print(metric ? 'C' : 'F');
Serial.print(F("\tHum "));
Serial.println(humidity);
#endif
static MyMessage msgHum(CHILD_ID_HUM, V_HUM);
static MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
static MyMessage msgBattery(CHILD_ID_VOLT, V_VOLTAGE);
send(msgTemp.set(temperature, 2));
wait(SHORT_WAIT);
send(msgHum.set(humidity, 2));
float batteryVolt = getInternalVoltage();
batteryPcnt =(batteryVolt / 3.3) * 100;
if (batteryPcnt > 100)
{
batteryPcnt = 100;
}
#ifdef MY_DEBUG
Serial.print(F("Vbat "));
Serial.print(batteryVolt);
Serial.print(F(" Battery percent "));
Serial.println(batteryPcnt);
#endif
// Battery readout should only go down. So report only when new value is smaller than previous one.
if (batteryPcnt < oldBatteryPcnt)
{
wait(SHORT_WAIT);
send(msgBattery.set(batteryVolt, 3));
wait(SHORT_WAIT);
if (batteryPcnt < oldBatteryPcnt)
{
sendBatteryLevel(batteryPcnt);
oldBatteryPcnt = batteryPcnt;
}
// Sleep until next update to save energy
//
}
//delay(5000);
mySleep(UPDATE_INTERVAL);
}
float getInternalVoltage()
{
return ((float)hwCPUVoltage()) / 1000.0;
}
Have some problems.
First and biggest: The sensor will not wake,
2577 TSF:MSG:SEND,37-37-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:33.34
Vbat 3.29 Battery percent 99.67
2587 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
2591 TSF:TDI:TPD
8593 MCO:SLP:WUP=-1
8595 TSF:TRI:TPU
Temp 23.46C Hum 33.85
8626 TSF:MSG:SEND,37-37-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:23.46
8733 TSF:MSG:SEND,37-37-0-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:33.85
Vbat 3.29 Battery percent 99.67
8743 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
8748 TSF:TDI:TPD
(Some times I got stuck at:
5803 MCO:SLP:MS=6000,SMS=0,I1=255,M1=255,I2=255,M2=255
5807 TSF:TDI:TPD
11809 MCO:SLP:WUP=-1
11811 TSF:TRI:TPU
Temp 22.69C Hum 31.08
11842 TSF:MSG:SEND,37-37-0-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:22.69
)
Second when im trying to debug with
#define MY_DEBUG_VERBOSE_NRF5_ESB
the node will not pass presentation.
153 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=5
4158 TSF:MSG:SEND,37-37-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
4164 NRF5:SND:TO=0,LEN=8,PID=1,NOACK=0
4169 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
4174 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
4180 NRF5:RX:LEN=9,NOACK=0,PID=2,RSSI=-74,RX=0
4184 TSF:MSG:READ,0-0-37,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
4190 NRF5:RX:LEN=8,NOACK=0,PID=1,RSSI=-53,RX=0
4194 TSF:MSG:READ,0-0-37,s=255,c=3,t=6,pt=0,l=1,sg=0:M
Presentation
4200 NRF5:SND:TO=0,LEN=29,PID=2,NOACK=0
4206 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=5
4210 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=11,pt=0,l=22,sg=0,ft=0,st=OK:TemperatureAndHumidity
4218 NRF5:SND:TO=0,LEN=10,PID=3,NOACK=0
4223 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
4228 TSF:MSG:SEND,37-37-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.2
4234 NRF5:SND:TO=0,LEN=15,PID=0,NOACK=0
4239 NRF5:SND:END=1,ACK=1,RTRY=1,RSSI=-55,WAKE=4
4244 TSF:MSG:SEND,37-37-0-0,s=0,c=0,t=7,pt=0,l=8,sg=0,ft=0,st=OK:Humidity
Someone that can help me?