Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 94
61  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 11:03:53 am
The longer I make the delay, the few more characters I can receive. obviously not the solution but maybe helps to find the solution?
Running at 38400

Code:
  int delay_t = 300;
    // Using an Arduino MEGA for test. Send it using Serial2
      Serial2.print(F("<INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT"));
      delay(delay_t);
      Serial2.print(F(",humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      delay(delay_t);
      Serial2.print(F("VALUES ("));
      Serial2.print(millis());
      Serial2.print(F(",2013-09-28 11:22:33,44.55,66.77,88.99,00.11,2.33,444.55,6.77,888.9)>"));


Code:
void serialEvent()
{
  // Read all serial data available, as fast as possible
  while(mySerial.available() > 0)
  {
    char inChar = mySerial.read();
    //Serial.write(inChar);
    if(inChar == SOP)
    {
      Serial.println("Starting");
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
      Serial.println("Ending");
       ended = true;
       break;
    }
    else
    {
     // Serial.println("Data");
      if(index < ARRAYSIZE-1)
      {
          // Ive tried with the printing disabled, but it only keeps writting "Starting".
        Serial.print("Saving: ");Serial.print(inChar); Serial.print(" index ");Serial.println(index);
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
      else { Serial.println("array overflow");}
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
              // Print the string
              for(int i=0; i<index; i++) Serial.print(inData[i]);
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Quote
Starting
Saving: I index 0
Saving: N index 1
Saving: S index 2
Saving: E index 3
Saving: R index 4
Saving: T index 5
Saving:   index 6
Saving: I index 7
Saving: N index 8
Saving: T index 9
Saving: O index 10
Saving:   index 11
Saving: d index 12
Saving: a index 13
Saving: t index 14
Saving: a index 15
Saving:   index 16
Saving: ( index 17
Saving: B index 18
Saving: , index 19
Saving: d index 20
Saving: a index 21
Saving: t index 22
Saving: e index 23
Saving: _ index 24
Saving: u index 25
Saving: p index 26
Saving: l index 27
Saving: o index 28
Saving: a index 29
Saving: d index 30
Saving: e index 31
Saving: d index 32
Saving: , index 33
Saving: t index 34
Saving: e index 35
Saving: m index 36
Saving: p index 37
Saving: _ index 38
Saving: b index 39
Saving: o index 40
Saving: x index 41
Saving: , index 42
Saving: t index 43
Saving: e index 44
Saving: m index 45
Saving: p index 46
Saving: _ index 47
Saving: a index 48
Saving: m index 49
Saving: b index 50
Saving: , index 51
Saving: t index 52
Saving: e index 53
Saving: m index 54
Saving: p index 55
Saving: D index 56
Saving: H index 57
Saving: T index 58
Saving: , index 59
Saving: h index 60
Saving: u index 61
Saving: m index 62
Saving: D index 63
Saving: H index 64
Saving: T index 65
Saving: , index 66
Saving: w index 67
Saving: e index 68
Saving: a index 69
Saving: t index 70
Saving: h index 71
Saving: e index 72
Saving: r index 73
Saving: _ index 74
Saving: s index 75
Saving: t index 76
Saving: a index 77
Saving: t index 78
Saving: u index 79
Saving: V index 80

Saving: A index 81
Saving: L index 82
Saving: U index 83
Saving: E index 84
Saving: S index 85
Saving:   index 86
Saving: ( index 87
Saving: 1 index 88
Saving: 5 index 89
Saving: 4 index 90
Saving: 1 index 91
Saving: 4 index 92
Saving: 5 index 93
62  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 10:26:34 am
Ive added this delay at the middle of the Sending and seems to help on not loosing data when using the SoftwareSerial basic example
Code:
     Serial2.print(F("<INSERT INTO data (B,date_uploaded,temp_box,"));
      Serial2.print(F("temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      delay(100);
      Serial2.print(F("VALUES ("));
      Serial2.print(millis());
      Serial2.print(F(",2013-09-28 11:22:33,44.55,66.77,88.99,00.11,2.33,444.55,6.77,888.9)>"));

At 57600 is still showing wierd characters. I have changed the speed at both arduinos, I even put the Serial debug all at 57600 including the serial monitor window


edit...
thanks Paul. I left it as...
Code:
     if(index < ARRAYSIZE-1)

The baudrate still getting me. until i dont fix this I presume its impossible to get the code working.

douh
Code:
while(Serial.available() > 0)
Code:
while(mySerial.available() > 0)


I cant get to receive a perfect line, therefore the code does not return anything. I see it always gets stuck around index 70 or 74 when receiving data. overflow???
63  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 09:48:34 am
Thanks a lot Paul for your time !

I guess I need to modify this line? why do this check? with this check nothing happens.
Code:
 if(index < 79)

I really like the idea of the "started" and "ended" flags. as well as the chained if condition. makes so much sense now to have it.

regarding the 9600 speed, I just thought it would be better to keep it slower than faster, but I understand I was wrong.

any idea why it might not be liking 57600 speed?
Code:
<©§©!*"ÊJy"…áÂ@˜¡–²X½¬UÁÑÞ´²²–:¹-®%½áXèe½¸¯¨-,‰•Õàˆ ª–´]+()…é•ÅèеWw•éëb’ )
Sender. Arduino MEGA. using Serial2 at 57600
Receiver. Arduino NANO. using softwareSerial at 57600 (basic example with arduino ide)
64  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 09:10:37 am
For now I prefer receiving a string correctely, saving it, and then receive the next one.

(I delete my previous message as I found a big error I was making)
Its starting to improve, but cant get full perfect reception yet...

Code:
//**********************************
    // Send Serial MYSQL
      unsigned long previousmillis_Send_Serial_MYSQL;
      unsigned long interval_Send_Serial_MYSQL = 5000;
//**********************************

    const int Status_LED = 13;
    
void setup()
{
  delay(5000);
  
  // start serial port at 9600 bps:
  Serial.begin(9600);     while (!Serial)  {    ; /* wait for serial port to connect. Needed for Leonardo only */  }
  Serial2.begin(9600);    while (!Serial2) {    ; /* wait for serial port to connect. Needed for Leonardo only */  }
  
  Serial.println();Serial.println();Serial.println(F("STARTING MASTER SYSTEM TESTBENCH SIMULATOR"));
  Serial.print(F("MYSQL data send every: "));  Serial.println(interval_Send_Serial_MYSQL);
  //*****************************
  
  // Visual indication that the Arduino MASTER SYSTEM is resetting...
  for(int i=0; i < 100; i++) { digitalWrite(Status_LED, !digitalRead(Status_LED)); delay(100); }  //delay(10000);
  
  delay(5000);
}





void loop()
{
  digitalWrite(Status_LED, HIGH);   // set the LED on
  
  Send_Serial_MYSQL();
  
  delay(500);                        // Delay to simulate other tasks performed by the main system

  digitalWrite(Status_LED, LOW);    // set the LED off
  delay(100);                        // Delay to show system is active
}



void Send_Serial_MYSQL()
{
  //************************************************************************************************
  if (millis() - previousmillis_Send_Serial_MYSQL > interval_Send_Serial_MYSQL)
  {
      previousmillis_Send_Serial_MYSQL = millis();
      
    // Using an Arduino MEGA for test. Send it using Serial2
      Serial2.print(F("!INSERT INTO data (B,date_uploaded,temp_box,"));
      Serial2.print(F("temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      Serial2.print(F("VALUES ("));
      Serial2.print(millis());
      Serial2.print(F(",2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00,458.19,1.99,133.9)$"));

    // Show it also in the Serial monitor
      Serial.print(F("!INSERT INTO data (B,date_uploaded,temp_box,"));
      Serial.print(F("temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      Serial.print(F("VALUES ("));
      Serial.print(millis());
      Serial.print(F(",2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00,458.19,1.99,133.9)$"));
      Serial.println();
  }
  //************************************************************************************************
}

Receiver
Code:

  char foo;    // http://arduino.cc/forum/index.php?topic=84412.0

#include <SoftwareSerial.h>
    SoftwareSerial mySerial(7, 8); // RX, TX

//**************************** SERIAL *******************************************
    boolean stringComplete    = false;   // whether the string is complete
     //Character array used to convert recieved serial characters to floats.
       const int ARRAYSIZE = 300;
          char cArray[ARRAYSIZE];
          int ic=0;
//**************************** SERIAL *******************************************

  unsigned long previousmillis_lastSDwrite;
  unsigned long interval_SDwrite = 20000;
  
    const int Status_LED = 8;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);   while (!Serial) {    ; /* wait for serial port to connect. Needed for Leonardo only  */  }
  
  delay(5000);
  Serial.println();Serial.println(F("STARTING LOGGING and WATCHDOG PROGRAM"));
  delay(5000);

  pinMode(Status_LED,        OUTPUT);

  //********************
  mySerial.begin(9600);
}



void loop()
{
  //do other stuff
  if (millis() - previousmillis_lastSDwrite > interval_SDwrite)
  {
    // Write data so SD
    delay(500);
  }
  
  serialEvent();

  digitalWrite(Status_LED, !digitalRead(Status_LED));
}

 
void serialEvent()
{
   char inChar;
  
   if (mySerial.available() > 0)
   {
      while (mySerial.available()) {
                  
                   // get the new byte:
                   inChar = (char)mySerial.read();
                    
                   // Serial.print(inChar);

                  
                  // Start
                   if (inChar == '!')
                         {
                          Serial.println();Serial.println(F("Receiving..."));
                          ic=0;
                         }
                        
                    //add to character array
                   cArray[ic] = inChar; ic++;
              
              
                  // if the incoming character is a newline, set a flag
                  // so the main loop can do something about it:
                  if (inChar == '$')  {  Serial.println("####");    stringComplete = true;  }
                  
                  // once all data is collected...
                  if (stringComplete == true)
                    {
                      Serial.println(F("******** String Complete ********"));
                       ic=0;
                       // Print the string
                       for(int i=0; i<ARRAYSIZE; i++) Serial.print(cArray[i]);
                       Serial.println();
                       stringComplete = false;
                       // Clear the Array
                       for(int i=0; i<ARRAYSIZE; i++) cArray[i] = 0;
                    }
                 }
      }
    }




Result:
Code:

STARTING LOGGING and WATCHDOG PROGRAM

Receiving...
####
******** String Complete ********
!INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) VALUES (1290972,2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.         00,458.19,1.99,133.9)$

Receiving...

Receiving...
####
******** String Complete ********
!INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) VALUES (1301142,2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00,458.19,1.99,133.9)$

Receiving...

Receiving...

Receiving...

Receiving...
####
******** String Complete ********
!INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,hu02.6925.94,25.00,41.00,3.00,458.19,1.99,133.9)$
65  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 08:56:10 am
Thanks Paul sounds very good. My brain got blocked after so many tries and needed new ideas.

Would it be doable, that the Sender sends whenever it wants? I really didnt want the Sender to have to be checking for authorization. any ideas? This would allow me to use only 2 wires (ground + Tx).
66  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 08:45:31 am
Code:
   String Serial_Data_String = "";      // a string to hold incoming data    //String inputString = "";
What's this for? You never use it.

The delay() on EVERY pass through loop() isn't helping. What the hell is that there for?

Printing every single character received is going to cut the effective read rate in half.

Sorry that was removed now, it was from previous tests. sorry for the misunderstanding.

I need to consider the ArduinoReceiver will be busy every 10 seconds writing information to the SD card. I dont know how to code the Serial function to receive the full line. it always get cut at different places.

is it a good idea to break the line i am sending in different parts? like i did with the 100 ms delay? if not, how to send such a large line?
67  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 08:43:40 am
hello AWOL, thanks.

I left that half a second delay to "simulate" when the Arduino2Receiver is saving data to the SD card and therefore not being able to do anything else. I just made this two test sketches to simplify everything before adding other code (SD saving).

I guess my objective is to come up with a SerialEvent() which handles better the information that arrives through the serial port. The problem, I dont know how to coupe with overflow.
while (serial.available()) sometimes does not kick in and misses the rest of the serial i think
68  Using Arduino / Programming Questions / Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 08:35:02 am
Hello everyone, let see if anyone can help me cause after a week trying different ideas I cant do it by myself  smiley-roll-blue

I have prepared 2 test Sketches to prepare my code before applying it to my real project.

I need Arduino1 to send a large string or chars, to an Arduino2 by Serial port.
Arduino2 needs to store all the line in a char cArray[200]; and will be later saving it to a SD card.

Here is both codes.

Problem is I believe I am filling in the buffer and not receiving the information fast enough, and in some cases, too fast. So either Arduino2Receiver is busy doing other stuff, or its waiting for Serial information that takes time to arraive.
.
Any help? Thanks a lot everyone !!

Arduino1Sender
Code:
//**********************************
    // Send Serial MYSQL
      unsigned long previousmillis_Send_Serial_MYSQL;
      unsigned long interval_Send_Serial_MYSQL = 10000;
//**********************************

    const int Status_LED = 13;
    
void setup()
{
  delay(5000);
  
  // start serial port at 9600 bps:
  Serial.begin(9600);     while (!Serial)  {    ; /* wait for serial port to connect. Needed for Leonardo only */  }
  Serial2.begin(9600);    while (!Serial2) {    ; /* wait for serial port to connect. Needed for Leonardo only */  }
  
  Serial.println();Serial.println();Serial.println(F("STARTING MASTER SYSTEM TESTBENCH SIMULATOR"));
  Serial.print(F("MYSQL data send every: "));  Serial.println(interval_Send_Serial_MYSQL);
  //*****************************
  
  // Visual indication that the Arduino MASTER SYSTEM is resetting...
  for(int i=0; i < 100; i++) { digitalWrite(Status_LED, !digitalRead(Status_LED)); delay(100); }  //delay(10000);
  
  delay(5000);
}





void loop()
{
  digitalWrite(Status_LED, HIGH);   // set the LED on
  
  Send_Serial_MYSQL();
  
  delay(500);                        // Delay to simulate other tasks performed by the main system (SD card saving mainly)

  digitalWrite(Status_LED, LOW);    // set the LED off
  delay(100);                        // Delay to show system is active
}



void Send_Serial_MYSQL()
{
  //************************************************************************************************
  if (millis() - previousmillis_Send_Serial_MYSQL > interval_Send_Serial_MYSQL)
  {
      previousmillis_Send_Serial_MYSQL = millis();
      
    // Using an Arduino MEGA for test. Send it using Serial2
      Serial2.print(F("!INSERT INTO data (B,date_uploaded,temp_box,"));
      delay(100);
      Serial2.print(F("temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      delay(100);
      Serial2.print(F("VALUES ("));
      delay(100);
      Serial2.print(millis());
      Serial2.print(F(",2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00,458.19,1.99,133.9)"));

    // Show it also in the Serial monitor
      Serial.print(F("!INSERT INTO data (B,date_uploaded,temp_box,"));
      delay(100);
      Serial.print(F("temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      delay(100);
      Serial.print(F("VALUES ("));
      delay(100);
      Serial.print(millis());
      Serial.print(F(",2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00,458.19,1.99,133.9)#"));
      Serial.println();
  }
  //************************************************************************************************
}


Arduino2Receiver
Code:
 char foo;    // http://arduino.cc/forum/index.php?topic=84412.0

#include <SoftwareSerial.h>
    SoftwareSerial mySerial(7, 8); // RX, TX

//**************************** SERIAL *******************************************
    boolean stringComplete    = false;   // whether the string is complete
     //Character array used to convert recieved serial characters to floats.
          char cArray[200];
          int ic=0;
//**************************** SERIAL *******************************************


    const int Status_LED = 8;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);   while (!Serial) {    ; /* wait for serial port to connect. Needed for Leonardo only  */  }
  
  delay(5000);
  Serial.println();Serial.println(F("STARTING LOGGING"));
  delay(5000);

  pinMode(Status_LED,        OUTPUT);

  //********************
  mySerial.begin(9600);
}



void loop()
{
  //do other stuff
  delay(500);
  
  serialEvent();

  digitalWrite(Status_LED, !digitalRead(Status_LED));
}

 
void serialEvent()
{
   char inChar;
  
   if (mySerial.available() > 0)
   {
     Serial.println();Serial.println(F("Receiving..."));
    
                   while (mySerial.available()) {
                  
                   // get the new byte:
                   inChar = (char)mySerial.read();
                    
                    Serial.print(inChar);

                   //add to character array
                   cArray[ic] = inChar; ic++;
              
                  // if the incoming character is a newline, set a flag
                  // so the main loop can do something about it:
                  if (inChar == '#')  {      stringComplete = true;  } // if (inChar == '\n') {      stringComplete = true;  }
                  
                  // once all data is collected...
                  if (stringComplete == true)
                    {
                      Serial.println(F("******** String Complete ********"));
                       ic=0;
                       // Print the string
                       for(int i=0; i<200; i++) cArray[i] = 0;
                       Serial.println();
                    }
                 }
  }
}


Receiver output
Code:

STARTING LOGGING and WATCHDOG PROGRAM

Receiving...
!INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,hu
Receiving...
VALUES (593790,2013-09-28 00:17:22,27.69,25.94,25.00,41.00,3.00
Receiving...
!INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,hu
Receiving...
!INSERT INTO d

I attach the files also, for easy view.
I dont know how to send and receive such a large text.
69  International / Software / Re: Sistema de vuelo. on: September 28, 2013, 04:43:39 am
la lata va a caer desde 5000 metros de altura,

Como sube hasta 5km?
70  International / Software / Re: problema al escribir ¨sketch¨ on: September 28, 2013, 04:42:17 am
ni idea, pero puede que el archivo este en "solo lectura"?
71  International / Español / Re: igor on: September 24, 2013, 02:00:53 pm
Hola:

Soy nuevo en esto y estoy intentando comunicar un arduino con una pantalla HMI. Alguien me puede hechar una mano.

Gracias.

que pantalla?
 que arduino?
72  International / Hardware / Re: Cableado instalación Arduino on: September 24, 2013, 01:37:38 pm
En esta vida en ocasiones simplemente hay que -probar-!
Son 10m de cable de red, no es barato pero tampoco te vas a arruinar.

Darte una solución mas exacta es imposible porque no sabemos en que condiciones exteriores estará el cable. -nave industrial- no es muy preciso.
73  International / Hardware / Re: Cableado instalación Arduino on: September 23, 2013, 02:44:00 pm
pues depende mucho donde y que rodee a la instalación
yo he usado ultrasonidos con distancias mucho mayores y en ocasiones fallaba. con 10 metros puede que no te falle casi nunca. usa cable de red y haz pruebas
74  International / Español / Re: Mi utilidad práctica para arduino+LCD SHIELD on: September 23, 2013, 02:24:48 pm
Sirve con uno solo, pero conforme hagas pruebas veras que te pueden hacer falta mas. Al menos esta es mi experiencia.
Un arduino lo montas con el proyecto que estas desarrollando, el otro arduino lo utilizas para hacer pruebas de los diferentes modulos o secciones que quieres aprender para añadir al proyecto.
De esta forma puedes usar el arduino de pruebas junto con el codigo solo de lo que estas probando y el sensor o lo que sea.
75  International / Proyectos / Re: Duda proyecto:Pantalla inalámbrica on: September 23, 2013, 01:24:48 pm
(mis conocimientos son nulos).
 ya que yo no tengo conocimientos de electrónica ni de programación,

Buenas,
Esas dos frases hacen que tu proyecto sea ...mmm...casi imposible. Yo llevo con Arduino unos 4 años, dandole mucha caña y no sabria ni por donde empezar.
Ademas se le queda muy grande lo que pretendes a un arduino.
Empieza encendiendo un led como dice jopapa y ves avanzando, cada vez veras como tu proyecto se aleja de su alcance.
Pages: 1 ... 3 4 [5] 6 7 ... 94