APC220 two-way communication

I even checked that I collected data from one Arduino Uno, sent it through one apc220, and collected sensor data from the other apc220. But I want to give commands to Arduino with sensors. But this doesn't work...

This is Arduino Uno code for sending sensor data.


#include <SoftwareSerial.h>
#include "Wire.h"
#include "Adafruit_BMP085.h"


Adafruit_BMP085 bmp;


#define DISABLED_PIN 255


float baselinePressure;


#define DATA_N 13 
unsigned long prevTime = 0; 
const unsigned long interval = 750; 
char cmd = '0';




SoftwareSerial APC(3, 5); // RX and TX
SoftwareSerial IMU(2, DISABLED_PIN); // RX and TX
SoftwareSerial NANO(DISABLED_PIN, 6); // RX and TX
SoftwareSerial TVC_NANO(DISABLED_PIN, 7); // RX and TX
////////////////////////////////////////////////////////////////////
/////////////////////// EBIMU FUNCTION /////////////////////////////
#define SBUF_SIZE 256


//int file_num = 1;
char sbuf[SBUF_SIZE];
signed int sbuf_cnt=0;


int EBimuAsciiParser(float *item, int number_of_item)
{
  int n,i;
  int rbytes;
  char *addr;
  int result = 0;
 
  rbytes = IMU.available();
  for(n=0;n<rbytes;n++)
  {
    sbuf[sbuf_cnt] = IMU.read();
    if(sbuf[sbuf_cnt]==0x0a)
       {
           addr = strtok(sbuf,",");
           for(i=0;i<number_of_item;i++)
           {
              item[i] = atof(addr);
              addr = strtok(NULL,",");
           }


           result = 1;


         // Serial.print("\n\r");
         // for(i=0;i<number_of_item;i++)  {  Serial.print(item[i]);  Serial.print(" "); }
       }
     else if(sbuf[sbuf_cnt]=='*')
       {   sbuf_cnt=-1;
       }


     sbuf_cnt++;
     if(sbuf_cnt>=SBUF_SIZE) sbuf_cnt=0;
  }
 
  return result;
}
/////////////////////// EBIMU FUNCTION /////////////////////////////
////////////////////////////////////////////////////////////////////


void setup()
{
  Serial.begin(9600);
  APC.begin(9600); // start serial to APC
  IMU.begin(9600); // start serial to IMU
  NANO.begin(9600);
  bmp.begin(); // start i2c


  baselinePressure = bmp.readPressure(); 
}


 
void loop()
{
  unsigned long curTime = millis(); 
  float imu_dt[DATA_N];
  String dt = "";
 
  //Safety sequence=======================
 
  if(APC.available()){
    cmd = (char)APC.read();
  }
 


  if(EBimuAsciiParser(imu_dt, DATA_N))
  {
    //myFile = SD.open("data"+String(file_num)+".txt", FILE_WRITE);
 
   
    dt = ("/*"+String(imu_dt[2])+","+String(imu_dt[1])+","+String(imu_dt[0])+\
    ","+String(imu_dt[6])+","+String(imu_dt[7])+","+String(imu_dt[8])+\
    ",5,35.8898,128.6107,"+String(bmp.readAltitude(baselinePressure))+","+cmd+"*/");


    delay(40);
    Serial.println(dt);  
    APC.println(dt);
    if(curTime - prevTime >= interval){
      prevTime = curTime;
      NANO.println(dt);  //nano 
    }
 
  }
 
}

This is the receiving Arduino Uno code.


#include <SoftwareSerial.h>
 
SoftwareSerial APC(3, 4); // RX and TX

void setup()
{
  APC.begin(9600); // start serial to APC
  Serial.begin(9600);
}

void loop()
{


  if(Serial.available()){
    APC.print((char)Serial.read());
  }


  if(APC.available()) {
    Serial.print((char)APC.read());
  }


}

I want to have the receiving side send commands to the sending side, but it doesn't seem to work.

How many instances does Software Serial support? Have you checked the documentation?

Which model of Arduino is this running on?

It is an Arduino Uno. ah..

Thanks for answering one of my questions.

4 software serial ports? 2 are often problematic. Did you read the SoftwareSerial reference?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.