Как включить GPRS shield если он выключен.

Тема в разделе "Arduino & Shields", создана пользователем BeeLove, 17 июл 2014.

  1. BeeLove

    BeeLove Нерд

    Пишу этот топик больше для себя, чтоб не забыть.
    Два дня боролся вот с каким вопросом:
    Задача: Надо проверить включен ли шиелд. Если не включен - включить. Если работает пройти дальше.

    Имеем работающий код:
    Код (Text):

    // Имеем arduino uno
    // к ней подключени GPRS shield
    // перемычки в шилде в положении HW
    // с arduino подан интерфейс rx tx перемычками с 2 на 0 ногу и с 3 на 1
    // Пин D9 управляет питанием шиелда

    // если при включении шиелд выключен - он включится.
    // если шиелд был включен - он останется включенным.

    #include <SoftwareSerial.h>
    SoftwareSerial GPRS(2, 3);
    unsigned char buffer[64]; // buffer array for data recieve over serial port
    int count=0;    // counter for buffer array
    void setup()
    {
      GPRS.begin(9600);              // the GPRS baud rate
      Serial.begin(9600);            // the Serial port of Arduino baud rate.
      Serial.write("Starting.....");
      pinMode(9,OUTPUT);

      GPRS.write("AT\r\n");// обязательная строка чтобы порт перешел в состояние available
      delay(500);

      // включаем питание
      if(!GPRS.available()){
        digitalWrite(9,HIGH);
        delay(1000);
        digitalWrite(9,LOW);
        Serial.write("POWER ON\r\n");
      }
      Serial.println("Go to LOOP");
    }



    void loop()
    {

      //Serial.println("LOOP");delay(1000);

      // Serial.write("Loop");
      if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
      {
        while(GPRS.available())          // reading data into char array
        {
          buffer[count++]=GPRS.read();    // writing data into array
          if(count == 64)break;
        }
        Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
        clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
        count = 0;                      // set counter of while loop to zero
      }
      if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
        GPRS.write(Serial.read());      // write it to the GPRS shield

    }


    //    Ф У Н К Ц И И

    void clearBufferArray()              // function to clear buffer array
    {
      for (int i=0; i<count;i++)
      {
        buffer[i]=NULL;
      }                  // clear all index of array with command NULL
    }
     
    Вопросы?
     
    ИгорьК нравится это.
  2. Airbus

    Airbus Радиохулиган Модератор

    Вопрос:// перемычки в шилде в положении HW нафига тогда блок #include <SoftwareSerial.h>
    SoftwareSerial GPRS(2, 3);?Вы какой USART используете программный или аппаратный?Или оба сразу?
    GPRS.begin(9600);// the GPRS baud rate Serial.begin(9600); // the Serial port of Arduino baud rate.
     
  3. BeeLove

    BeeLove Нерд

    Доброе утро.
    На шиелде порт работает на пинах 0, 1. На ардуино порт взаимодействующий с шиелдом на пинах 2, 3. Они соединены. #include <SoftwareSerial.h> используется для обеспечения работы указанного порта на ардуино. Или я конкретно туплю? В чем?