Using Aduino due, using two i2c, one SPI, and three serial communications
Each has received the values of internal ADC / external ADC / RTC / SD Card / LoRa / GPS module.
The individual experiments have been successfully completed, and work is being integrated as follows.
But if you attach more than 3 modules above and communicate, the work will be stopped.
I don't know why the work of Arduino Due stops at all.
The code is as follows.
#include <DueTimer.h>
#include <Wire.h>
#include <ADS1115.h>
#include <SPI.h>
#include <SD.h>
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 36;
String dataName;
File dataFile;
/* I/O INIT */
#define SENSOR_00 A0
#define SENSOR_01 A1
#define SENSOR_02 A2
#define SENSOR_03 A3
/* RTC */
#define DS3231_I2C_ADDRESS 104
byte seconds, minutes, hours;
char weekDay[4];
byte tMSB, tLSB;
float temp3231;
/* ADC */
unsigned int ADC_Value00 = 0;
unsigned int ADC_Value01 = 0;
unsigned int ADC_Value02 = 0;
unsigned int ADC_Value03 = 0;
ADS1115 ads1;
ADS1115 ads2;
int16_t adc0, adc1, adc2, adc3,adc4, adc5, adc6, adc7;
String ADS1115_str = "";
/* GPS */
String FINAL_GPS_VALUE ="";
bool GPS_VALUE_EMPTY = true;
const byte numChars = 40;
char receivedChars[numChars];
boolean newData = false;
/* LoRa */
bool LoRaParameter_info = true;
String receivedCharsLoRa;
boolean newDataLoRa = false;
int count_NO = 0;
void setup() {
/* Serial */
Serial.begin(115200); // Monitoring
Serial1.begin(9600); // GPS
Serial2.begin(9600); // LoRa
/* Timer */
Timer3.attachInterrupt(ADC_CAL_START).start(1000000);
Timer4.attachInterrupt(SENSOR_DISPLAY).start(2000000);
/* ADC */
analogReadResolution(12);
pinMode(SENSOR_00, INPUT);
pinMode(SENSOR_01, INPUT);
pinMode(SENSOR_02, INPUT);
pinMode(SENSOR_03, INPUT);
/* ADS1115 */
ads1.getAddr_ADS1115(ADS1115_DEFAULT_ADDRESS);
ads2.getAddr_ADS1115(ADS1115_VDD_ADDRESS);
ads1.setGain(GAIN_TWOTHIRDS);
ads2.setGain(GAIN_TWOTHIRDS);
ads1.setMode(MODE_CONTIN);
ads2.setMode(MODE_CONTIN);
ads1.setRate(RATE_860);
ads2.setRate(RATE_860);
ads1.setOSMode(OSMODE_SINGLE);
ads2.setOSMode(OSMODE_SINGLE);
ads1.begin(); //ADS1115 - 1 start
ads2.begin(); //ADS1115 - 2 start
Wire1.begin(); //RTC 시작
}
void SDCARD_INIT(){
pinMode(SS, OUTPUT);
dataName = "datalog.txt";
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
while (1) ;
}
Serial.println("card initialized.");
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (! dataFile) {
Serial.println("error opening datalog.txt");
while (1) ;
}
}
void loop() {
if(LoRaParameter_info){
LoRaCommunication();
delay(500);
}
watchConsole();
get3231Date();
GPS_INFO_DISPLAY();
/*
ADS1115_DISPLAY();
delay(500);
SDCARD_DATA_LOG();*/
} // loop
void LoRaCommunication(){
static boolean recvInProgress = false;
static byte ndx = 0;
String startMarker = "$";
String endMarker = ">";
String rc;
Serial2.println("$Rpar=");
while (Serial2.available() > 0 && newDataLoRa == false) {
rc = Serial2.readString();
if (recvInProgress == true) {
if (rc.indexOf(endMarker) == 0) {
receivedCharsLoRa = rc;
}
else {
recvInProgress = false;
newDataLoRa = true;
}
}
else if (rc.indexOf(startMarker) != 0) {
recvInProgress = true;
}
}
if ((newDataLoRa == true) ) {
String BufferTbd3 = "$Tbupc=170:";
LoRaParameter_info = false;
Serial.println(receivedCharsLoRa);
Serial2.println(BufferTbd3 + receivedCharsLoRa);
newDataLoRa = false;
}
}
void ADC_CAL_START(){
NTCsensor_Collect_10data();
Voltage5_Collect_10data();
Voltage3_Collect_10data();
Door_Collect_10data();
}
void GPS_INFO_DISPLAY(){
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '
Can anybody help me?;
char endMarker = '\n';
char rc;
while (Serial1.available() > 0 && newData == false) {
rc = Serial1.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0';
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
if ((newData == true) ) {
if(receivedChars[3] == 'M'){
FINAL_GPS_VALUE = "";
for(int i = 0 ; i < 40 ; i++){
FINAL_GPS_VALUE += receivedChars[i];
}
} //delay(100);
newData = false;
}
}
void ADS1115_DISPLAY(){
byte error1, error2;
int8_t address1, address2;
address1 = ads1.ads_i2cAddress;
address2 = ads2.ads_i2cAddress;
Wire.beginTransmission(address1);
Wire.beginTransmission(address2);
error1 = Wire.endTransmission();
error2 = Wire.endTransmission();
if (error1 == 0 )
{
adc0 = ads1.Measure_SingleEnded(0);
adc1 = ads1.Measure_SingleEnded(1);
adc2 = ads1.Measure_SingleEnded(2);
adc3 = ads1.Measure_SingleEnded(3);
adc4 = ads2.Measure_SingleEnded(0);
adc5 = ads2.Measure_SingleEnded(1);
adc6 = ads2.Measure_SingleEnded(2);
adc7 = ads2.Measure_SingleEnded(3);
ADS1115_str = "";
ADS1115_str += "AIN0: ";
ADS1115_str += adc0;
ADS1115_str += ", AIN1: ";
ADS1115_str += adc1;
ADS1115_str += ", AIN2: ";
ADS1115_str += adc2;
ADS1115_str += ", AIN3: ";
ADS1115_str += adc3;
ADS1115_str += ", AIN4: ";
ADS1115_str += adc4;
ADS1115_str += ", AIN5: ";
ADS1115_str += adc5;
ADS1115_str += ", AIN6: ";
ADS1115_str += adc6;
ADS1115_str += ", AIN7: ";
ADS1115_str += adc7;
}
else
{
Serial.println("ADS1115 Disconnected!");
}
//delay(1000);
}
void SDCARD_DATA_LOG(){
String dataString = "";
for (int analogPin = 0; analogPin < 3; analogPin++) {
dataString += analogPin;
}
dataFile.println(dataString);
Serial.println(dataString);
dataFile.flush();
}
void SENSOR_DISPLAY(){
/*
String RTC_display = "";
RTC_display += (int)hours;
RTC_display += ":";
RTC_display += (int)minutes;
RTC_display += ":";
RTC_display += (int)seconds;
RTC_display += "\r\n";
*/
String Sensor_display = "";
//Sensor_display += RTC_display;
Sensor_display += "3.3V : ";
Sensor_display += ADC_Value01;
Sensor_display += "5V : ";
Sensor_display += ADC_Value00;
Sensor_display += ", NTC : ";
Sensor_display += ADC_Value02;
Sensor_display += ", Door : ";
Sensor_display += ADC_Value03;
Sensor_display += "\r\n";
Sensor_display += "GPS : ";
Sensor_display += FINAL_GPS_VALUE;
Sensor_display += "\r\n";
Sensor_display += "ADS1115 : ";
Sensor_display += ADS1115_str;
Sensor_display += "\r\n";
Serial.println(Sensor_display);
}
void Voltage5_Collect_10data(){
ADC_Value00 = analogRead(SENSOR_00);
}
void Voltage3_Collect_10data(){
ADC_Value01 = analogRead(SENSOR_01);
}
void NTCsensor_Collect_10data(){
ADC_Value02 = analogRead(SENSOR_02);
}
void Door_Collect_10data(){
ADC_Value03 = analogRead(SENSOR_03);
}
/* RTC /
byte decToBcd(byte val)
{
return ( (val/1016) + (val%10) );
}
void watchConsole()
{
if (Serial.available()) {
if (Serial.read() == 84) {
get3231Date();
Serial.println(" ");
}
}
}
void get3231Date()
{
Wire1.beginTransmission(DS3231_I2C_ADDRESS);
Wire1.write(0x00); // start at register 0
Wire1.endTransmission();
Wire1.requestFrom(DS3231_I2C_ADDRESS, 7);
if(Wire1.available()) {
seconds = Wire1.read(); // get seconds
minutes = Wire1.read(); // get minutes
hours = Wire1.read(); // get hours
seconds = (((seconds & B11110000)>>4)*10 + (seconds & B00001111));
minutes = (((minutes & B11110000)>>4)*10 + (minutes & B00001111));
hours = (((hours & B00110000)>>4)*10 + (hours & B00001111));
}
else {
}
switch (day) {
case 1:
strcpy(weekDay, "Sun");
break;
}
}
Can anybody help me?