1

Topic: Как обратиться к порту SoftwareSerial

Я делаю проект с соединение через BlueTooth, использую SoftwareSerial.
Мне нужно проверить кое-какие настройки на BT-модуле.
Но как достучаться до BT-модуля в документации как-то не описано. В примерах тоже этого нет.
Я полазил по файлам библиотеки, там вроде используется переменная serial, по похоже она не public, и ее не видно снаружи.
Как можно обратиться к порту, который создается внутри RemoteXY?

2

Re: Как обратиться к порту SoftwareSerial

remotexy->serial->write ("Hello world");

3

Re: Как обратиться к порту SoftwareSerial

У меня аналогичный вопрос, но только по Hardware serial:  В моем проекте используется Hardware serial и при отключенном соединении Remorexy с Андроидом, я хочу использовать этот порт для приема и отправки других данных из платы (Ардуино Нано). Но порт постоянно занят структурой Remotexy и получить с него какие либо данные не возможно.
Подскажите, как получить доступ к ком порту ?

4 (edited by turbos1000 2017-10-13 12:05:12)

Re: Как обратиться к порту SoftwareSerial

Вот так вот не работает:

incomingByte = remotexy->  serial->read ();
if(incomingByte == 32){D4_Out;delay(99);}
 
  

Как принять данные ? При отсутствии подключения к Андроид, мне нужно принимать и отправлять следующее:

if(RemoteXY.connect_flag ==0){       //  Процедура сброса ардуино,при загрузке скетча через блютус
incomingByte = remotexy->  serial->read ();
if(incomingByte == 32){D4_Out;delay(99);}
 

if(incomingByte == 32){D4_Out;delay_ms(99);}

if(incomingByte == 108){        //   "l" start signal from loger
  D7_In;
  D8_In;
  
if(i < 1){ 
  
  Serial.println();
  Serial.print("Bigturbo bar,Loud value TP,Intake press.Bar,Water injection,Exthaus pressure,VGT,Wat.temp,Cool.fan,Big turbo WG,Fan to cond.,Eng.RPM");
  Serial.println();
  }
i++;
if(i == 2){
 // time = millis()/100; 
  Serial.print(bigturbo_bar);                  // Bigturbo bar
  Serial.print(",");
  Serial.print(te);                  // Loud value TP%
  Serial.print(",");
  Serial.print(intake_bar);               // Intake press. Bar
  Serial.print(",");
  Serial.print(Wval1/fedr);          // Water inj
  Serial.print(",");
  Serial.print(exth_bar);                 // Exthaus pressure
  Serial.print(","); 
  Serial.print(PWMval2 / fedr);       // VGT
  Serial.print(",");
  Serial.print(et);                    // Water temp.
  Serial.print(",");
  Serial.print(FANval1);               // Cool.fan %
  Serial.print(",");
  Serial.print(Output_1 / fedr);       // Big turbo WG
  Serial.print(",");
  Serial.println(fan_con);             // Cond.fan_con
 //Serial.print(sensorValue2);          // Large turbo sensor adc
 //Serial.print(",");
 //Serial.print();
   Serial.println();
   if (millis() > 11000){  // wait for RPMs average to get stable
   Serial.print(eng_rpm);}
   Serial.print(",");
}
if(i == 35){i = 1;}                    //  30 - Speed of transfer data updting 
}

  

Подскажите пожалуйста, как корректно это оформить, что бы принимать и отправлять данные через, или в обход структуры Remotexy ?

5

Re: Как обратиться к порту SoftwareSerial

Что бы RemoteXY перестала использовать порт - читать его и писать в него - перестаньте вызывать процедуру RemoteXY_Handler () в каждом цикле loop.
Однако вы должны понимать, что если в этот момент приложение попытается законнектится к устройству - будет ошибка.

6

Re: Как обратиться к порту SoftwareSerial

remotexy wrote:

Что бы RemoteXY перестала использовать порт - читать его и писать в него - перестаньте вызывать процедуру RemoteXY_Handler () в каждом цикле loop.
Однако вы должны понимать, что если в этот момент приложение попытается законнектится к устройству - будет ошибка.

А есть какое то заглавное сообщение от приложения на Андроид, прочитав которое в ком порте, программа бы смогла активировать процедуру RemoteXY_Handler ?

7 (edited by turbos1000 2017-10-13 19:20:07)

Re: Как обратиться к порту SoftwareSerial

Попробовал реализовать вот так:

//////////////////////////////////////////////////////////      Small turbo ssettings   //////////////////////////////////////////////////////////////////////////////
//
// Position of the geometry small turbo at exhaust pressure. Values from -100 to 100%.
// Large values - increase the valve signal and increase the boost pressure. 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int rpm [] =   {  90, 88, 86, 85, 75, 73, 68, 63, 58, 53, 48, 43, 38, 33, 32, 31, 30, 30, 30, 29, 28, 27, 24, 21, 19, 16, 13, 10,  8,  7,  6,  5,  4,  3,  2,  1,};
//Exh/intake press.0 bar                       1                               2                           3                       4                           5 bar
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Correction of the VGT position small turbo at large turbo pressure. Values from -100 to 100%.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int rpm_2[] =   {  25, 24, 23, 22, 20, 18, 16, 14, 12, 10,  8,  6,  4,  2,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,};
//Large turbo press.0 bar                                   1                                       2                                       3                  3,5 bar                              4                       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////    VGT correction at trottle   -100% to 100%
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int vgt_at_tps[]={  0,-11,-12,-13,-14,-15,-14,-12,-10, -8, -6, -4,  -2,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  4,  7, 10, 13, 15, 16, 17, 15, 17, 17, 17,};
//Trottle pos.      0%                         20%                          40%                         60%                         80%                        100%
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const byte averageFactor_ext = 20;  // Exthaus pressure sensor average factor  (0 = not smooth)
const byte averageFactor     =  4;  // Intake manifold and big turbo pressure sensor average factor (0 = not smooth)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define REMOTEXY_MODE__HARDSERIAL
       
//#include <SoftwareSerial.h> 
#include <CyberLib.h>
#include <RemoteXY.h> 
#include <PID_v1.h>


/* connection settings */          // Use BT module HC-06 Transmission speed of BT module 57600
#define REMOTEXY_SERIAL Serial 
#define REMOTEXY_SERIAL_SPEED 57600 


// конфигурация интерфейса   
#pragma pack(push, 1) 
uint8_t RemoteXY_CONF[] = 
  { 255,9,0,73,0,7,3,6,0,4,
  3,2,0,37,14,26,2,3,7,13,
  50,32,25,8,3,2,3,1,1,30,
  32,16,8,1,2,115,97,118,101,0,
  1,1,82,18,12,9,2,2,62,0,
  3,5,0,22,9,40,2,2,1,1,
  30,18,12,9,2,2,60,0,67,6,
  33,6,32,15,3,3,4,67,6,70,
  6,30,15,3,3,4,67,6,70,27,
  30,13,3,3,4,67,6,87,57,13,
  5,3,3,4,67,6,65,57,13,5,
  3,3,4,67,6,65,48,13,5,3,
  3,5,67,5,31,3,62,9,3,2,
  17,67,5,47,18,30,8,3,2,8,
  67,6,87,48,13,5,3,3,4,67,
  5,50,48,25,7,3,2,5,67,6,
  42,48,13,5,3,3,5,67,6,33,
  27,32,13,3,3,5,67,6,42,57,
  13,5,3,3,4,129,0,34,2,29,
  4,8,3,98,105,103,32,116,117,114,
  98,111,32,98,111,111,115,116,0,129,
  0,70,23,11,4,8,3,101,120,104,
  97,117,115,116,32,112,114,101,115,115,
  117,114,101,0,129,0,87,45,16,3,
  8,3,99,111,111,108,46,102,97,110,
  32,37,0,129,0,70,2,27,4,8,
  3,98,111,111,115,116,32,40,105,110,
  116,97,107,101,41,0,129,0,33,18,
  5,3,8,3,98,97,114,0,129,0,
  70,18,5,3,8,3,98,97,114,0,
  129,0,70,37,5,3,8,3,98,97,
  114,0,130,1,31,1,36,21,0,3,
  130,1,68,1,34,21,0,3,130,1,
  68,22,34,19,0,3,129,0,86,54,
  16,3,8,3,119,97,116,101,114,32,
  105,110,106,46,37,0,129,0,43,23,
  11,4,8,3,116,114,111,116,116,108,
  101,0,129,0,37,45,19,3,8,3,
  98,105,103,32,116,117,114,98,111,32,
  87,71,37,0,129,0,37,54,19,3,
  8,3,115,109,46,116,117,114,98,111,
  32,87,71,37,0,130,1,31,22,36,
  19,0,3,129,0,64,45,11,3,8,
  3,109,97,120,32,98,111,111,115,116,
  0,129,0,62,54,18,3,8,3,101,
  110,103,46,32,116,101,109,112,46,67,
  0,130,1,31,43,71,19,0,3,131,
  0,3,8,23,8,2,2,115,101,116,
  116,105,110,103,115,0,131,1,3,0,
  23,8,2,3,103,97,117,103,101,0,
  129,0,16,54,5,4,8,3,76,111,
  32,58,40,0,129,0,16,41,5,4,
  8,3,72,105,32,58,41,0,129,0,
  0,33,18,4,8,3,98,111,111,115,
  116,32,109,111,100,101,0,129,0,50,
  13,21,4,0,2,115,116,111,114,101,
  100,32,100,97,116,97,0,129,0,50,
  27,21,4,0,2,105,110,112,117,116,
  32,102,114,97,109,101,0,129,0,10,
  24,17,4,8,2,98,105,103,32,116,
  117,114,98,111,0,129,0,10,32,17,
  4,8,2,115,109,46,116,117,114,98,
  111,0,129,0,10,40,15,4,8,2,
  99,111,111,108,46,102,97,110,0,129,
  0,10,48,17,4,8,2,102,117,110,
  99,116,105,111,110,0,130,1,46,17,
  32,10,9,2,130,1,48,31,27,10,
  11,2,130,1,30,2,64,11,9,2,
  129,0,10,56,17,4,8,2,115,101,
  110,115,46,99,97,108,105,98,0,130,
  1,29,1,66,56,0,2,130,1,49,
  31,27,10,1,2,130,1,46,17,32,
  10,9,2,130,1,30,2,64,11,9,
  2,129,0,50,43,24,4,0,2,115,
  101,110,115,46,97,100,99,47,118,97,
  108,0,130,1,49,47,27,9,9,2,
  129,0,10,59,7,4,0,2,97,100,
  99,0,129,0,33,37,3,3,8,3,
  37,0 }; 
   
// структура определяет все переменные вашего интерфейса управления  
struct { 

    // input variable
  uint8_t select_1; // =0 если переключатель в положении A, =1 если в положении B, =2 если в положении C, ... 
  float data_input;
  uint8_t safe_but; // =1 если кнопка нажата, иначе =0 
  uint8_t men_butt_2; // =1 если кнопка нажата, иначе =0 
  uint8_t select_menu; // =0 если переключатель в положении A, =1 если в положении B, =2 если в положении C, ... 
  uint8_t menu_but_1; // =1 если кнопка нажата, иначе =0 

    // output variable
  char text[4];  // =строка UTF8 оканчивающаяся нулем 
  char text_3[4];  // =строка UTF8 оканчивающаяся нулем 
  char text_4[4];  // =строка UTF8 оканчивающаяся нулем 
  char text_6[4];  // =строка UTF8 оканчивающаяся нулем 
  char text_10[4];  // =строка UTF8 оканчивающаяся нулем 
  char text_11[5];  // =строка UTF8 оканчивающаяся нулем 
  char menu_text[17];  // =строка UTF8 оканчивающаяся нулем 
  char data_text[8];  // =строка UTF8 оканчивающаяся нулем 
  char text_1[4];  // =строка UTF8 оканчивающаяся нулем 
  char adc[5];  // =строка UTF8 оканчивающаяся нулем 
  char text_7[5];  // =строка UTF8 оканчивающаяся нулем 
  char text_2[5];  // =строка UTF8 оканчивающаяся нулем 
  char text_5[4];  // =строка UTF8 оканчивающаяся нулем 

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0 

} RemoteXY; 
#pragma pack(pop) 

///////////////////////////////////////////// 
//           END RemoteXY include          // 
///////////////////////////////////////////// 
/*the first measured value is the first point */           //Calibration of the large turbine pressure sensor (in Bar)
#define SENS_3_VAL 100    ///// ADC = Volt * 204.8                    
#define SENS_3_TMP 0.0    ////  BAR ////////////
/*the second measured value is the second point */ 
#define SENS_4_VAL 808    ///// ADC = Volt * 204.8
#define SENS_4_TMP 6.0    ////  BAR ////////////
//______________________________
/*the first measured value is the first point */
#define SEN_1_VAL 37    ///// ADC = Volt * 204.8                   //Calibrating the Intake Manifold Pressure Sensor (Bar)
#define SEN_1_TMP 0.0   ////  BAR /////////////
/* the second measured value is the second point */ 
#define SEN_2_VAL 987   ///// ADC = Volt * 204.8
#define SEN_2_TMP 5.0   ////  BAR /////////////

//__________________________________________________________________________________________________________________________________________________
#define   A0  // Analog Input of the integrated pressure sensor in the intake manifold. Sensor pinout: 1-signal, 2-mass, 3- + 5v
#define   A1  // Analog input of the request for the activation of the air conditioning fan (output from the engine ECU)       
 
                       
#define   A4  // Analog input of the engine temperature sensor.    
#define   A5  // Analog input of the large turbine pressure sensor. 
#define   A6  // Analog input engine load (accelerator pedal sensor)
#define   A7  // Аналоговый вход Exhaust pressure sensor
  //      pin D0      // BT
  //      pin D1      // BT
  //      pin D2      // Output for hardware reset, when loading firmware via bluetooth channel (connected with reset)    
#define FANout 3      // PWM Cooling fan output (outputs 3, 11 245.10Hz)
 //         D4           
#define   Wout 5      // Exit to water/methanol injection pump                      
                      //
  //       pin D7     // BT
  //       pin D8     // BT
#define  PWMout 9     // PWM output for a small turbo solenoid.
#define PWM2out 10    // PWM Large turbine solenoid output. (outputs 9, 10 = 30.64Hz) 
                      // (PWM 245.10Гц)
                      //
                      // 
byte i,
incomingByte,
 flag_but_1,
 sens_sel,
 flag_but;                      
int sensorValue,
i2,
 sensorValue1,
 sensorValue2,
 sensorValue3,
 sensorValue4,
 sensorValue5,
 sensorValue6,
 
 FANval1,
 FANval2,
 PWMval2,
 PWMval3,
 PWMval4,
 PWMval,
 Mval1,
 rpmact,
 rpmact_2,
 rpmact_3,
 rpmact_4,
 Wval1,
 W_start_d,
 menu_but_flag,
 set_time,
 select_1_val,
 wglimmax,       // Upper limiter of the WG position of the large turbine
 wglimmin,       // Lower limit position of the WG of the large turbine
 speed_reg,      // Velocity of the large turbo regulator
 oldsensorValue,
 oldsensorValue_ext,
 oldsensorValue1,
 oldsensorValue2,
 oldrpmact,
 oldrpmact_2,
 oldrpmact_4,
 oldrpmact_3;
 double Setpoint_11,Setpoint_1,Input_1,Output_1,
 Input_flag, 
 fedr = 2.53;             //  Variable uncle Fyodor (son of Uncle Magnet and brother of Conus ..) To calculate interest from PWM and back /       
 float boost_tps_st,
 boost_tps_f,
 con_set_1,
 con_set_2,
 fan_set_1,
 fan_set_2,
 wat_set_1,
 wat_set_2,
 wat_t_adc_2,
 wat_t_adc_1,
 wat_t_temp_1,
 wat_t_temp_2,
 ext_press_1,
 ext_press_2,
 ext_adc_1,
 ext_adc_2,
 TPS_adc_1,
 TPS_adc_2,
 TPSval_1,
 TPSval_2,
 Kp_1,
 Ki_1,
 Kd_1,
 half,           // Boost Level (Low)
 full,           // Boost level (high)
 min_reg,        // Pressure to turn on the boost regulator for a large turbo
 max_boost;

PID myPID_1(&Input_1, &Output_1, &Setpoint_11, Kp_1, Ki_1, Kd_1, DIRECT);

// read RPM and calculate average every then readings.
const int numreadings = 10;
int readings[numreadings];
unsigned long average = 0;
int index = 0;
unsigned long total; 

volatile int rpmcount = 0;
unsigned long eng_rpm = 0;
unsigned long lastmillis = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {RemoteXY_Init ();
  
  D3_Out;          // Fan
  D5_Out;          // Water
  D9_Out;          // WG
  D10_Out;         // WG
  
menu_but_flag =1;
Ki_1 = (ReadEEPROM_Byte(2)*0.1);
Kp_1= (ReadEEPROM_Byte(1)*0.1);
Kd_1= (ReadEEPROM_Byte(43)*0.1);
half= (ReadEEPROM_Byte(0)*0.1);
full= (ReadEEPROM_Byte(3)*0.1);
min_reg= (ReadEEPROM_Byte(7)*0.1);
wglimmax= (ReadEEPROM_Byte(4));
wglimmin= (ReadEEPROM_Byte(8));
RemoteXY.select_1=(ReadEEPROM_Byte(5));
// Примечание; ячейка памяти 11 умерла.. :(
speed_reg= (ReadEEPROM_Byte(12) );


sens_sel = (ReadEEPROM_Byte(21) );
fan_set_1= (ReadEEPROM_Byte(22) );
fan_set_2= (ReadEEPROM_Byte(23) );
con_set_1= (ReadEEPROM_Byte(24)*4);
con_set_2= (ReadEEPROM_Byte(25)*4);
max_boost= (ReadEEPROM_Byte(26)* 0.1);
wat_set_1= (ReadEEPROM_Byte(27)* 0.1);
wat_set_2= (ReadEEPROM_Byte(28)* 0.1);
W_start_d= (ReadEEPROM_Byte(6));
wat_t_adc_1= (ReadEEPROM_Byte(29)*4);
wat_t_adc_2= (ReadEEPROM_Byte(30)*4);
wat_t_temp_1= (ReadEEPROM_Byte(31));
wat_t_temp_2= (ReadEEPROM_Byte(32));
ext_adc_1= (ReadEEPROM_Byte(33) * 4);
ext_press_1= (ReadEEPROM_Byte(34) /20.0);
ext_adc_2= (ReadEEPROM_Byte(35) * 4);
ext_press_2= (ReadEEPROM_Byte(36) /20.0);
TPS_adc_1= (ReadEEPROM_Byte(37) * 4);
TPSval_1= (ReadEEPROM_Byte(38));
TPS_adc_2= (ReadEEPROM_Byte(39) * 4);
TPSval_2= (ReadEEPROM_Byte(40));
boost_tps_st= (ReadEEPROM_Byte(41));
boost_tps_f= (ReadEEPROM_Byte(42));

select_1_val = RemoteXY.select_1;  

  attachInterrupt(0, rpm_engine, FALLING);
 myPID_1.SetMode(AUTOMATIC);
 myPID_1.SetSampleTime(set_time);  
i = 0;          
i2 = 0;
UART_Init(57600);   // Arduino Speeds == 57600   
TCCR1B = TCCR1B & 0b11111000 | 0x05;
TCCR2B = TCCR2B & 0b11111000 | 0x06;
}

void rpm_engine(){ /* this code will be executed every time the interrupt 0 (pin2) gets low.*/
  rpmcount++;
}

void loop() {
  
  if(i2 > 2){RemoteXY_Handler ();  
    
  if(i2==30000){i2 = 0;}}
i2++;
if (millis() - lastmillis >= 10){  /*Uptade every one 1/100 second*/
 
 detachInterrupt(0);    //Disable interrupt when calculating
 total = 0;  
 readings[index] = rpmcount * 60;  /* Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use rpmcount * 30.*/
 
 for (int x=0; x<=9; x++){
   total = total + readings[x];
 }
 
 average = total / numreadings;
 eng_rpm = average;
 eng_rpm = constrain(eng_rpm,0,7000);
 rpmcount = 0; // Restart the RPM counter
 index++;
 if(index >= numreadings){
  index=0; 
 } 

 lastmillis = millis(); // Uptade lasmillis
  attachInterrupt(0, rpm_engine, FALLING); //enable interrupt
  }
 

   ///////////////////////////////////////////////////////////////////////////////////////////////////////
                 
 oldsensorValue1 = sensorValue1;        //  Intake manifold pressure 
 sensorValue1 = A0_Read;
 if (averageFactor > 0){        // averaging readings to eliminate "jumps"
 sensorValue1 = (oldsensorValue1 * (averageFactor - 1) + sensorValue1) / averageFactor;  //<new mean> = (<old average> * 19 + <current value>) / 20 
 }
 sensorValue5 = A1_Read;        //  Air conditioning request     
         
 sensorValue4 = A4_Read;        //  Temp.
 
 oldsensorValue2 = sensorValue2;
 sensorValue2 = A5_Read;        //  Pressure of a large turbo 
 if (averageFactor > 0)  {      // averaging readings to eliminate "jumps"
 sensorValue2 = (oldsensorValue2 * (averageFactor - 1) + sensorValue2) / averageFactor; // <new mean> = (<old average> * 19 + <current value>) / 20
  }  
 sensorValue3 = A6_Read;        //  Trottle
 
 oldsensorValue_ext = sensorValue;
 sensorValue =  A7_Read;        //  Exthaus pressure
 if (averageFactor_ext > 0)  {      // averaging readings to eliminate "jumps"
 sensorValue = (oldsensorValue_ext * (averageFactor_ext - 1) + sensorValue) / averageFactor_ext; // <new mean> = (<old average> * 19 + <current value>) / 20
  }  


   
          double exth_bar = ext_press_1 + (ext_press_2 - ext_press_1) /  
           (ext_adc_2 - ext_adc_1) * (sensorValue- ext_adc_1);                    // Exthaus pressure
           exth_bar = constrain(exth_bar , 0 , 10);


           double bigturbo_bar = SENS_3_TMP + (SENS_4_TMP - SENS_3_TMP) /  
           (SENS_4_VAL - SENS_3_VAL) * (sensorValue2 - SENS_3_VAL);               // Pressure of a large turbo 
           bigturbo_bar = constrain(bigturbo_bar , 0 , 5);

         
           double intake_bar = SEN_1_TMP + (SEN_2_TMP - SEN_1_TMP) /  
           (SEN_2_VAL - SEN_1_VAL) * (sensorValue1- SEN_1_VAL);                   // Intake manifold pressure
            
           double te = TPSval_1 + (TPSval_2 - TPSval_1) /                 
             (TPS_adc_2 - TPS_adc_1) * (sensorValue3- TPS_adc_1);                  // Trottle
              te =  constrain(te , 0 , 99); 
              
           double et = wat_t_temp_1 + (wat_t_temp_2 - wat_t_temp_1) /           
            (wat_t_adc_2 - wat_t_adc_1) * (sensorValue4- wat_t_adc_1);              // Temp
                
         double fan_act = 100/(fan_set_2-fan_set_1)*(et - fan_set_1);               // Fan
         fan_act= constrain(fan_act , 0 , 100);

         double fan_con = 100/(con_set_2-con_set_1)*(sensorValue5 - con_set_1);     // Cond
         fan_con= constrain(fan_con , 0 , 100);

         double wat_act = 100/(wat_set_2-wat_set_1)*(intake_bar - wat_set_1);       //  Water/methanol  injection
         wat_act = constrain(wat_act,(0),(100));

         /////////////////////////////////////////////////////////////////////////////////////////////////////
                  //Menu 1 (Large turbo)
                                  
  if(RemoteXY.men_butt_2 == 1 && flag_but == 0){++menu_but_flag; flag_but = 1;}           // Circle menu
  if(RemoteXY.men_butt_2 == 0){flag_but = 0;}
  
  if(RemoteXY.menu_but_1 ==1 &&flag_but_1 ==0){menu_but_flag = menu_but_flag -1; flag_but_1 =1;}
  if(RemoteXY.menu_but_1 ==0){flag_but_1 =0;}
  menu_but_flag = constrain(menu_but_flag, 0 , 20);
  
  if(RemoteXY.select_menu==0)   {dtostrf(0, 0, 0, RemoteXY.adc); if(menu_but_flag >9){menu_but_flag = 1;}    // Limits the menu in the menu circle 1 (Large turbo)
  if(menu_but_flag ==0){menu_but_flag =9;}
  
  if (menu_but_flag ==1){sprintf(RemoteXY.menu_text, "PID K.p ");dtostrf(Kp_1, 0, 1, RemoteXY.data_text);  
  if (RemoteXY.safe_but!=0){Kp_1 = RemoteXY.data_input; Kp_1 = constrain(Kp_1, 0.0 , 25.4); WriteEEPROM_Byte(1, Kp_1 * 10);}} 
  if (menu_but_flag ==2){sprintf(RemoteXY.menu_text, "PID K.i ");dtostrf(Ki_1, 0, 1, RemoteXY.data_text);  
  if (RemoteXY.safe_but!=0){Ki_1 = RemoteXY.data_input; Ki_1 = constrain(Ki_1, 0.0 , 25.4);WriteEEPROM_Byte(2, Ki_1 * 10);}}
  if (menu_but_flag ==3){sprintf(RemoteXY.menu_text, "PID K.d ");dtostrf(Kd_1, 0, 1, RemoteXY.data_text);  
  if (RemoteXY.safe_but!=0){Kd_1 = RemoteXY.data_input; Kd_1 = constrain(Kd_1, 0.0 , 25.4);WriteEEPROM_Byte(43, Kd_1 * 10);}}
  if (menu_but_flag ==4){sprintf(RemoteXY.menu_text, "WG lim.max ");dtostrf((wglimmax/fedr), 0, 0, RemoteXY.data_text );
  if (RemoteXY.safe_but!=0){wglimmax = RemoteXY.data_input*fedr; wglimmax = constrain(wglimmax, 0 , 254); WriteEEPROM_Byte(4, wglimmax );}}  
  if (menu_but_flag ==5){sprintf  (RemoteXY.menu_text, "WG lim.min ");dtostrf((wglimmin/fedr), 0, 0, RemoteXY.data_text );  
  if (RemoteXY.safe_but!=0){wglimmin = RemoteXY.data_input*fedr; wglimmin = constrain(wglimmin, 0 , 254);  WriteEEPROM_Byte(8, wglimmin );}}
  if (menu_but_flag ==6){sprintf  (RemoteXY.menu_text, "min reg.(bar)");dtostrf(min_reg, 0, 1, RemoteXY.data_text ); 
  if (RemoteXY.safe_but!=0){min_reg = RemoteXY.data_input; min_reg = constrain(min_reg, 0.0 , 6.0);  WriteEEPROM_Byte(7, min_reg *10);}}
  if (menu_but_flag ==7){sprintf  (RemoteXY.menu_text, "Lo boost (bar)");dtostrf(half, 0, 1, RemoteXY.data_text );dtostrf(Setpoint_11, 0, 1, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){half = RemoteXY.data_input; half = constrain(half, 0.0 , 6.0);  WriteEEPROM_Byte(0, half *10);}}
  if (menu_but_flag ==8){sprintf  (RemoteXY.menu_text, "Hi boost (bar)");dtostrf(full, 0, 1, RemoteXY.data_text );dtostrf(Setpoint_11, 0, 1, RemoteXY.adc); 
  if (RemoteXY.safe_but!=0){full = RemoteXY.data_input; full = constrain(full, 0.0 , 6.0);WriteEEPROM_Byte(3, full *10);}}  
  if (menu_but_flag ==9){sprintf  (RemoteXY.menu_text, "speed reg.(ms)");dtostrf(speed_reg,0, 0, RemoteXY.data_text );  
  if (RemoteXY.safe_but!=0){speed_reg = RemoteXY.data_input; speed_reg = constrain(speed_reg, 5 , 150);  WriteEEPROM_Byte(12, speed_reg);}}}
///////////////////////////////////////////////////////////////////////////////////////
                                           // Menu 2 (small turbo)
                                           
  if(RemoteXY.select_menu==1)    {sprintf  (RemoteXY.menu_text, "pres.s.ex-0 in-1");dtostrf(sens_sel, 0, 0, RemoteXY.data_text );  
  if (RemoteXY.safe_but!=0){sens_sel = RemoteXY.data_input; sens_sel = constrain(sens_sel, 0 , 1);  WriteEEPROM_Byte(21, sens_sel);}}
///////////////////////////////////////////////////////////////////////////////////////
                // Menu 2 (Fan)
                
  if(RemoteXY.select_menu==2)   {if (menu_but_flag >4){menu_but_flag = 1;}    // Limits the menu in a circle
  if(menu_but_flag ==0){menu_but_flag =4;} 
  
  if (menu_but_flag==1){sprintf(RemoteXY.menu_text, "fan.start gr.C");dtostrf(fan_set_1, 0, 0, RemoteXY.data_text);dtostrf(et, 0, 0, RemoteXY.adc); 
  if (RemoteXY.safe_but!=0){fan_set_1 = RemoteXY.data_input; fan_set_1 = constrain(fan_set_1, 0 , 140);  WriteEEPROM_Byte(22, fan_set_1);}} 
  if (menu_but_flag==2){sprintf(RemoteXY.menu_text, "fan.full gr.C");dtostrf(fan_set_2, 0, 0, RemoteXY.data_text);dtostrf(et, 0, 0, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){fan_set_2 = RemoteXY.data_input; fan_set_2 = constrain(fan_set_2, 0 , 140);  WriteEEPROM_Byte(23, fan_set_2);}}
  if (menu_but_flag==3){sprintf(RemoteXY.menu_text, "con.start adc");dtostrf(con_set_1, 0, 0, RemoteXY.data_text);dtostrf(sensorValue5, 0, 0, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){con_set_1 = RemoteXY.data_input; con_set_1 = constrain(con_set_1, 0 , 1020);  WriteEEPROM_Byte(24, con_set_1 /4);}}
  if (menu_but_flag==4){sprintf(RemoteXY.menu_text, "con.full adc");dtostrf(con_set_2, 0, 0, RemoteXY.data_text);dtostrf(sensorValue5, 0, 0, RemoteXY.adc);
  if (RemoteXY.safe_but!=0){con_set_2 = RemoteXY.data_input; con_set_2 = constrain(con_set_2, 0 , 1020);   WriteEEPROM_Byte(25, con_set_2 /4);}}}
  
////////////////////////////////////////////////////////////////////////////////////////////
                   //function
 if(RemoteXY.select_menu==3)   {if (menu_but_flag >6){menu_but_flag = 1;}    // Limits the menu in a circle
  if(menu_but_flag ==0){menu_but_flag =6;} 
  
  if (menu_but_flag==1){sprintf(RemoteXY.menu_text, "W.inj.start bar");dtostrf(wat_set_1, 0, 1, RemoteXY.data_text);dtostrf(Wval1, 0, 0, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){wat_set_1 = RemoteXY.data_input; wat_set_1 = constrain(wat_set_1, 0.0 , 6.0);  WriteEEPROM_Byte(27, wat_set_1*10);}} 
  if (menu_but_flag==2){sprintf(RemoteXY.menu_text, "W.inj.full bar");dtostrf(wat_set_2, 0, 1, RemoteXY.data_text);dtostrf(Wval1, 0, 0, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){wat_set_2 = RemoteXY.data_input; wat_set_2 = constrain(wat_set_2, 0.0 ,9.0);  WriteEEPROM_Byte(28,wat_set_2*10);}}
  if (menu_but_flag==3){sprintf(RemoteXY.menu_text, "W.inj.start duty");dtostrf(W_start_d, 0, 0, RemoteXY.data_text);dtostrf(Wval1, 0, 0, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){W_start_d = RemoteXY.data_input; W_start_d = constrain(W_start_d, 0 ,100);  WriteEEPROM_Byte(6,W_start_d);}}
  if (menu_but_flag==4){sprintf(RemoteXY.menu_text, "boost/TPS start");dtostrf(boost_tps_st, 0, 0, RemoteXY.data_text);dtostrf(te, 0, 0, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){boost_tps_st = RemoteXY.data_input;boost_tps_st = constrain(boost_tps_st, 0,99);  WriteEEPROM_Byte(41, boost_tps_st);}} 
  if (menu_but_flag==5){sprintf(RemoteXY.menu_text, "boost/TPS full");dtostrf(boost_tps_f, 0, 0, RemoteXY.data_text);dtostrf(Setpoint_11, 0, 1, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){boost_tps_f = RemoteXY.data_input; boost_tps_f = constrain(boost_tps_f,0,99);  WriteEEPROM_Byte(42,boost_tps_f);}}
  if (menu_but_flag==6){sprintf  (RemoteXY.menu_text, "max boost reset");dtostrf(max_boost, 0, 1, RemoteXY.data_text );dtostrf(intake_bar, 0, 1, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){max_boost = 0;WriteEEPROM_Byte(26,max_boost);}}}
  if (intake_bar >= max_boost){max_boost = intake_bar;WriteEEPROM_Byte(26,max_boost*10);}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                     //Sensor Calibrations
 if(RemoteXY.select_menu==4)   {if (menu_but_flag >12){menu_but_flag = 1;}    // Limits the menu in a circle
  if(menu_but_flag ==0){menu_but_flag =12;} 
  if (menu_but_flag==1){sprintf(RemoteXY.menu_text, "wat.tem.volt 1");dtostrf((wat_t_adc_1/204.8), 0, 2, RemoteXY.data_text);dtostrf((sensorValue4/204.8), 0, 2, RemoteXY.adc); 
  if (RemoteXY.safe_but!=0){wat_t_adc_1 = RemoteXY.data_input*204.8; WriteEEPROM_Byte(29, wat_t_adc_1/4);}} 
  if (menu_but_flag==2){sprintf(RemoteXY.menu_text, "wat.temp 1");dtostrf(wat_t_temp_1, 0, 0, RemoteXY.data_text);dtostrf(et, 0, 0, RemoteXY.adc);    
  if (RemoteXY.safe_but!=0){wat_t_temp_1 = RemoteXY.data_input; WriteEEPROM_Byte(31,wat_t_temp_1);}}
  if (menu_but_flag==3){sprintf(RemoteXY.menu_text, "wat.tem.volt 2");dtostrf((wat_t_adc_2/204.8), 0, 2, RemoteXY.data_text);dtostrf((sensorValue4/204.8), 0, 2, RemoteXY.adc);    
  if (RemoteXY.safe_but!=0){wat_t_adc_2 = RemoteXY.data_input*204.8; WriteEEPROM_Byte(30,wat_t_adc_2/4);}} 
  if (menu_but_flag==4){sprintf(RemoteXY.menu_text, "wat.temp 2");dtostrf(wat_t_temp_2, 0, 0, RemoteXY.data_text);dtostrf(et, 0, 0, RemoteXY.adc);    
  if (RemoteXY.safe_but!=0){wat_t_temp_2 = RemoteXY.data_input;  WriteEEPROM_Byte(32,wat_t_temp_2);}}
  if (menu_but_flag==5){sprintf(RemoteXY.menu_text, "ext.pres.volt 1");dtostrf((ext_adc_1/204.8), 0, 2, RemoteXY.data_text);dtostrf((sensorValue/204.8), 0, 2, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){ext_adc_1 = RemoteXY.data_input*204.8; WriteEEPROM_Byte(33, ext_adc_1/4);}} 
  if (menu_but_flag==6){sprintf(RemoteXY.menu_text, "ext.pres.bar 1");dtostrf(ext_press_1, 0, 1, RemoteXY.data_text);dtostrf(exth_bar, 0, 1, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){ext_press_1 = RemoteXY.data_input; WriteEEPROM_Byte(34,ext_press_1*20);}}
  if (menu_but_flag==7){sprintf(RemoteXY.menu_text, "ext.pres.volt 2");dtostrf((ext_adc_2/204.8), 0, 2, RemoteXY.data_text);dtostrf((sensorValue/204.8), 0, 2, RemoteXY.adc);    
  if (RemoteXY.safe_but!=0){ext_adc_2 = RemoteXY.data_input*204.8; WriteEEPROM_Byte(35,ext_adc_2/4);}}
  if (menu_but_flag==8){sprintf(RemoteXY.menu_text, "ext.pres.bar 2");dtostrf(ext_press_2, 0, 1, RemoteXY.data_text);dtostrf(exth_bar, 0, 1, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){ext_press_2 = RemoteXY.data_input; WriteEEPROM_Byte(36,ext_press_2*20);}}
  if (menu_but_flag==9){sprintf(RemoteXY.menu_text, "TPS.adc 1");dtostrf(TPS_adc_1, 0, 0, RemoteXY.data_text);dtostrf(sensorValue3, 0, 0, RemoteXY.adc);  
  if (RemoteXY.safe_but!=0){TPS_adc_1 = RemoteXY.data_input; WriteEEPROM_Byte(37, TPS_adc_1/4);}} 
  if (menu_but_flag==10){sprintf(RemoteXY.menu_text, "TPS.pos.1");dtostrf(TPSval_1, 0, 0, RemoteXY.data_text);dtostrf(te, 0, 0, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){TPSval_1 = RemoteXY.data_input; WriteEEPROM_Byte(38,TPSval_1);}}
  if (menu_but_flag==11){sprintf(RemoteXY.menu_text, "TPS.adc 2");dtostrf(TPS_adc_2, 0, 0, RemoteXY.data_text);dtostrf(sensorValue3, 0, 0, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){TPS_adc_2 = RemoteXY.data_input;  WriteEEPROM_Byte(39,TPS_adc_2/4);}}
  if (menu_but_flag==12){sprintf(RemoteXY.menu_text, "TPS.pos.2");dtostrf(TPSval_2, 0, 0, RemoteXY.data_text);dtostrf(te, 0, 0, RemoteXY.adc);   
  if (RemoteXY.safe_but!=0){TPSval_2 = RemoteXY.data_input;  WriteEEPROM_Byte(40,TPSval_2);}}}                    
////////////////////////////////////////////////////////////////////////////////////////////
//                                                Charge level switch.
  if (select_1_val != RemoteXY.select_1){ WriteEEPROM_Byte(5,RemoteXY.select_1);   
  select_1_val = RemoteXY.select_1; } 
/////////////////////////////////////////////////////////////////////////////////////////// 

  dtostrf(bigturbo_bar, 0, 1, RemoteXY.text);         // Pressure of a large turbine
 
  dtostrf(intake_bar, 0, 1, RemoteXY.text_3);            // Intake manifold pressure

  dtostrf(FANval1, 0, 0, RemoteXY.text_1);          // Fan output 0-100%
  
  dtostrf(exth_bar, 0, 1, RemoteXY.text_4);              // exthaus pressure

  dtostrf((Wval1/fedr), 0, 0, RemoteXY.text_6);      // Water/methanol injection

  dtostrf(max_boost, 0, 1, RemoteXY.text_11);         // Maximum reached boost value

  dtostrf(et, 0, 0, RemoteXY.text_10);                // Temp.

  dtostrf((Output_1 / fedr), 0, 0, RemoteXY.text_7);   // Big turbo WG

  dtostrf((PWMval2 / fedr), 0, 0, RemoteXY.text_5);   // Small turbo WG

  dtostrf(te, 0, 1, RemoteXY.text_2);                  // Trottle  

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                              Fan                                        
  if (fan_act > fan_con){FANval1 = fan_act;}
  else{FANval1 = fan_con;}
  FANval2 = FANval1 * 2;
  FANval2 = constrain(FANval2,15,240);
  analogWrite (FANout, FANval2);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                              Water/methanol injection
  if(wat_act < (W_start_d-5)){Wval1=0;}
  if(wat_act > W_start_d){Wval1 = wat_act * fedr;}
  analogWrite (Wout, Wval1);
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //intake_bar = 1.9;  // Test                                                 //Big turbo!
// bigturbo_bar = 0.5;  // Test
 
 if (select_1_val !=0){ Setpoint_1 = half;}
 else{Setpoint_1 = full;} 
 Setpoint_11 = Setpoint_1/(boost_tps_f-boost_tps_st)*(te = constrain(te,2,99)- boost_tps_st);     
 Setpoint_11 = constrain(Setpoint_11,(min_reg),(Setpoint_1));
 set_time = speed_reg;                      
 PID myPID_1(&Input_1, &Output_1, &Setpoint_11, Kp_1, Ki_1, Kd_1, DIRECT);
 myPID_1.SetMode(AUTOMATIC);
 myPID_1.SetSampleTime(set_time);
 myPID_1.SetTunings(Kp_1, Ki_1, Kd_1);
 Input_1 = intake_bar;
 myPID_1.Compute();
 Output_1 = constrain(Output_1,wglimmin,wglimmax);
 if (intake_bar < min_reg){ Output_1 = wglimmax;
 if (intake_bar < min_reg-0.1){ Output_1 = 0;}}
 analogWrite(PWM2out, Output_1);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  //exth_bar = 1.0;  // Test                                                        // Smoll turbina
  //te  = 10;
 
  if(sens_sel!=0){Input_flag = intake_bar;}
  else{Input_flag = exth_bar;}
 
  rpmact = Input_flag *100;                             ///// Position by pressure in intake or in the exhaust
 rpmact = map(rpmact, 0 , 500, 0 , 35);
 PWMval = rpm[rpmact]; 

  rpmact_2 = bigturbo_bar * 100;                           
  rpmact_2 = map(rpmact_2, 0 , 340, 0 , 35);            /////  Position by big turbo pressure
  PWMval3 =  rpm_2[rpmact_2]; 
  
  rpmact_4 = te ;                                       //// Correction of trottle position   
  rpmact_4 = map(rpmact_4, 0 , 100, 0 , 35);  
  PWMval4 =  vgt_at_tps[rpmact_4]; 
 
   
  PWMval2 = (PWMval + PWMval3+ PWMval4 ) * fedr;
  PWMval2 =  constrain(PWMval2 , 0 , 250);
  analogWrite (PWMout, PWMval2);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(RemoteXY.connect_flag ==0){       //  Процедура сброса ардуино,при загрузке скетча через блютус
if(UART_ReadByte(incomingByte)) 
if  (incomingByte == 32){D4_Out;delay(99);
}
if(incomingByte == 108){        //   "l" start signal from loger

if(i < 1){ 
  
  Serial.println();
  Serial.print("Bigturbo bar,Loud value TP,Intake press.Bar,Water injection,Exthaus pressure,VGT,Wat.temp,Cool.fan,Big turbo WG,Fan to cond.,Eng.RPM");
  Serial.println();
  }
i++;
if(i == 2){
  
  Serial.print(bigturbo_bar);                  // Bigturbo bar
  Serial.print(",");
  Serial.print(te);                  // Loud value TP%
  Serial.print(",");
  Serial.print(intake_bar);               // Intake press. Bar
  Serial.print(",");
  Serial.print(Wval1/fedr);          // Water inj
  Serial.print(",");
  Serial.print(exth_bar);                 // Exthaus pressure
  Serial.print(","); 
  Serial.print(PWMval2 / fedr);       // VGT
  Serial.print(",");
  Serial.print(et);                    // Water temp.
  Serial.print(",");
  Serial.print(FANval1);               // Cool.fan %
  Serial.print(",");
  Serial.print(Output_1 / fedr);       // Big turbo WG
  Serial.print(",");
  Serial.println(fan_con);             // Cond.fan_con
 //Serial.print(sensorValue2);          // Large turbo sensor adc
 //Serial.print(",");
 //Serial.print();
   Serial.println();
   if (millis() > 11000){  // wait for RPMs average to get stable
   Serial.print(eng_rpm);}
   Serial.print(",");
}
if(i == 35){i = 1;}                    //  30 - Speed of transfer data updting 
}

  
} 
else{i2 = 2;} 
}

Приложение на Андроид выдает ошибку:https://lh3.googleusercontent.com/RxATfpJWmhIg81tpQ1gAxvC3wAb_K4nmDq709bPVF2zKpOgE4JWHkic3r0gBvNB5t4rl-t4Yt2xHE4Eb7__u2Os_fMLLSM5gJWx5OxqqSSnnwUtQsc-IxF_qakH7nqgsw-f1GRb-D7TY3Y_FXevkVl7faLGHQAwuGV-RZo2QF77Xwvg8GOH63h3bMjRTvAiET1OeuEFievoMv00ZdQ8XqaSQP02kpocSAupiaax5xUze55y3zUdO-t9W4QlfywnODHDJO6aPnrtZ_M-V00ZRItcSRsnzVTxVyM1Q0kRWX2OKuqZD3M4sd2MJzv9qxxf4zfMbtlXtqex2fpOF_557xt24TgnOHTKaU9-hcHNOw99sE_SedgBZYEXtqd_DN_k9sfrUp7NSKJW3IFkhKJQsVwra0_vzZZI2JMldGRwWeReoF4WdPSGBmkCYjnkQDcU6HrRdjQAiuMwFLMamepng9PmdFd4rFZipsXtQc-P5kK8aAPIe3GBOg-VrPI-Cc4frjGly-2K5yFthcM2xAlwQ2TMcx-wLOdgtIFOaS8RzH4ivnGuxFyBPlL6zlKa2aJYQcAqMDT0YFbiDPOITsBQQMInu9TaUt80Pg42USMHaRz0=w353-h588-no

8

Re: Как обратиться к порту SoftwareSerial

Так как это можно решить ??? Понятное дело, что структуре Remotexy, очень хочется единолично пользоваться всеми ресурсами платы, такими как ком порт на пример, 24 часа и семь дней в неделю..)) Но пользователей такой расклад категорически не устраивает!  Хотелось бы что бы было как то все по человечески и в меру.. Если ресурс не задействован, то зачем так жестко блокировать ком порт ??
Я пытаюсь разгадать этот ребус уже несколько дней но дело пока не сдвинулось с мертвой точки..

9

Re: Как обратиться к порту SoftwareSerial

Почему бы разработчикам просто не назвать имя переменной из структуры Remotexy, в которой хранятся считанные из ком порта данные ? Надеюсь это бы решило мою проблему.

10

Re: Как обратиться к порту SoftwareSerial

Как запустить RemoteXY_Handler в loop второй раз ?
Если в loop, хотя бы единожды была вызвана функция опроса ком порта, на пример UART_ReadByte, то восстановить работу структуры Remotexy уже не получается.

11

Re: Как обратиться к порту SoftwareSerial

Да, порт используется RemoteXY 24 часа и семь дней в неделю. Иначе вы не сможете подключиться к вашему устройству 24 часа и семь дней в неделю.
Выход - внедрить вашу задачу в код библиотеки RemoteXY. Все другие варианты ущербны. Как это сделать - лучше всего расскажет код библиотеки, он открыт и доступен для изучения. К сожалению нет возможности объяснять как это все там работает.