Hi, i am trying to debug an issue i have with the HTCC-AB01 and the ADS1115 ADC - and sending the data via lorawan. The code works fine until it reaches a count of 169 then it stops working - i used both my own code and the standard wasn code with the same result. If i use the code with fixed data (no ADS) it works fine and if i used the code with ADS no lorawan it works fine as well. I tried to debug but it seems to hand after count of 169 at the ads.begin() command under static void prepareTxFrame( uint8_t port )
#include “LoRaWan_APP.h”
#include “Arduino.h”
#include “Wire.h”
#include “Adafruit_ADS1X15.h”
/*
- set LoraWan_RGB to Active,the RGB active in loraWan
- RGB red means sending;
- RGB purple means joined done;
- RGB blue means RxWindow1;
- RGB yellow means RxWindow2;
- RGB green means received done;
*/
/* OTAA para*/
uint8_t devEui[] = { 0x18, 0xd8, 0x24, 0x3c, 0x81, 0xac, 0xa8, 0xaf };
uint8_t appEui[] = { 0x70, 0xb3, 0xd5, 0x7e, 0xd0, 0x02, 0xa0, 0xe1 };
uint8_t appKey[] = { 0x69, 0x91, 0xdb, 0x20, 0x4d, 0x05, 0xff, 0xbc, 0xff, 0x7e, 0x6d, 0x19, 0x62, 0x3c, 0x14, 0x22 };
/* ABP para*/
uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
uint32_t devAddr = ( uint32_t )0x007e6ae1;
/LoraWan channelsmask, default channels 8-15 + 65/
//uint16_t userChannelsMask[6]= { 0xFF00, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000};
uint16_t userChannelsMask[6]={ 0xFF00,0x0000,0x0000,0x0000,0x0002,0x0000 };
/LoraWan region, select in arduino IDE tools/
LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
/LoraWan Class, Class A and Class C are supported/
DeviceClass_t loraWanClass = LORAWAN_CLASS;
/the application data transmission duty cycle. value in [ms]./
uint32_t appTxDutyCycle = 15000;
/OTAA or ABP/
bool overTheAirActivation = LORAWAN_NETMODE;
/ADR enable/
bool loraWanAdr = LORAWAN_ADR;
/* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
bool keepNet = LORAWAN_NET_RESERVE;
/* Indicates if the node is sending confirmed or unconfirmed messages */
bool isTxConfirmed = LORAWAN_UPLINKMODE;
/* Application port /
uint8_t appPort = 2;
/!
- Number of trials to transmit the frame, if the LoRaMAC layer did not
- receive an acknowledgment. The MAC performs a datarate adaptation,
- according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
- to the following table:
- Transmission nb | Data Rate
- ----------------|-----------
- 1 (first) | DR
- 2 | DR
- 3 | max(DR-1,0)
- 4 | max(DR-1,0)
- 5 | max(DR-2,0)
- 6 | max(DR-2,0)
- 7 | max(DR-3,0)
- 8 | max(DR-3,0)
- Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
- the datarate, in case the LoRaMAC layer did not receive an acknowledgment
*/
uint8_t confirmedNbTrials = 4;
uint16_t baseline;
int count = 0;
int maxtry = 50;
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
/*!
\brief Prepares the payload of the frame
*/
static void prepareTxFrame( uint8_t port )
{
/*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in “commissioning.h”.
*appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
*if enabled AT, don’t modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
*if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
*for example, if use REGION_CN470,
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in “RegionCN470.h”.
*/
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
delay(500);
Serial.println(“before ads.begin”);
ads.begin();
Serial.println(“after ads.begin”);
delay(500);
/*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in “commissioning.h”.
*appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
*if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
*for example, if use REGION_CN470,
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in “RegionCN470.h”.
*/
appDataSize = 0;
int16_t adc0, adc1, adc2, adc3;
/* Be sure to update this value based on the IC and the gain settings! /
//float multiplier = 3.0F; / ADS1015 @ +/- 6.144V gain (12-bit results) /
float multiplier = 0.1875F; / ADS1115 @ +/- 6.144V gain (16-bit results) */
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
int modnr = 0;
appData[appDataSize++] = modnr;
appData[appDataSize++] = 9;
appData[appDataSize++] = ((int)adc0) >> 8;
appData[appDataSize++] = (int)adc0;
appData[appDataSize++] = ((int)adc1) >> 8;
appData[appDataSize++] = (int)adc1;
appData[appDataSize++] = ((int)adc2) >> 8;
appData[appDataSize++] = (int)adc2;
appData[appDataSize++] = ((int)adc3) >> 8;
appData[appDataSize++] = (int)adc3;
Serial.print(" ADC0: “); Serial.print(adc0);
Serial.print(” ADC1: “); Serial.print(adc1);
Serial.print(” ADC3: “); Serial.print(adc2);
Serial.print(” ADC3: “); Serial.println(adc3);
Serial.print(” AIN0: “); Serial.print(adc0 * multiplier);
Serial.print(” AIN1: “); Serial.print(adc1 * multiplier);
Serial.print(” AIN2: “); Serial.print(adc2 * multiplier);
Serial.print(” AIN3: "); Serial.println(adc3 * multiplier);
Serial.print("Count: “); Serial.print(count);
Serial.println(” ");
Serial.println(“before wire.end”);
Wire.end();
Serial.println(“after wire.end”);
count++;
delay(500);
//read battery voltage
uint16_t BatteryVoltage = getBatteryVoltage();
appData[appDataSize++] = (uint8_t)(BatteryVoltage >> 8);
appData[appDataSize++] = (uint8_t)BatteryVoltage;
Serial.print("BatteryVoltage: ");
Serial.println(BatteryVoltage);
Serial.println("Trigger: ");
//if(count > 169)
// {
// CySoftwareReset();
// ads1115.setup() };
// Serial.println(“ads reset”);
// else
// {
// Serial.println(“count less then 165”);
delay(500);
}
void setup() {
Serial.begin(115200);
// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
#if(AT_SUPPORT)
enableAt();
#endif
deviceState = DEVICE_STATE_INIT;
LoRaWAN.ifskipjoin();
}
void loop()
{
switch( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass,loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
break;
}
case DEVICE_STATE_JOIN:
{
LoRaWAN.join();
break;
}
case DEVICE_STATE_SEND:
{
prepareTxFrame( appPort );
LoRaWAN.send();
deviceState = DEVICE_STATE_CYCLE;
break;
}
case DEVICE_STATE_CYCLE:
{
// Schedule next packet transmission
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();
break;
}
default:
{
deviceState = DEVICE_STATE_INIT;
break;
}
}
}