Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 95
61  Using Arduino / General Electronics / Re: Arduino digital input, 80Vdc on: October 19, 2013, 10:52:45 am
What I can see from your layout you have the indication LED in parallell with the optocoupler.
Connect the indication LED in series with the optocoupler and the current are half of what is now.

One less component (2,2KΩ)

Pelle

Thats a very good idea Pelle !! Just cant believe how easy it was.

I did the simulation in livewire and we went from 402mW to 192mW !! Plus as you say, I can get rid of 6 resistors !!  smiley-money

So whats happening here is that by using only 1 resistor, the current "lost" in the extra resistor to drop the voltage is not required any more. The leds need very little current.
Is this correct? I just want to fully understand whats happening now.

Once again thanks ! When I fully understand whats happening I will modify my PCB to test it. Thank you  smiley
62  Using Arduino / General Electronics / Re: Arduino digital input, 80Vdc on: October 19, 2013, 09:17:26 am
Lower the current and/or lower the voltage drop over the zeners, (change from 2 to 3 zeners)

Pelle

Hello Pelle,

I can not lower the current as it is already powering the minimum things requiered (ie: pcb status led + 4N25).
I can add a third zener diode but I wanted to know if there was any other option as i am already with too many components (2zener+2diodes) per channel. If i add a third diode means another 6 diodes in the pcb + having to make the pcb bigger.

any other option?

thanks for the help
63  Using Arduino / General Electronics / Re: Arduino digital input, 80Vdc on: October 19, 2013, 07:31:53 am
UPDATE !

Sorry to bring this up again, but I need a little further help.

As I said earlier, I finally build this system and works perfectly, however I am a bit concerned on the temperature the diodes are getting up to.

There are 2 diodes (1N4750A with a 27V drop). First one to drop from 72V to 45V and then to 18V.
With a 15mA current.

1st diode)
   Power Dissipated:   
P=I∙E=0.015∙(72.73-45.73)=0.405W=405 mW

2nd diode)
   Power Dissipated:   
P=I∙E=0.015∙(45.73-18.73)=0.405W=405 mW

This diodes are 1 Watt, however they get very hot to the touch.

Any suggestion on how to upgrade the system to prevent them getting so hot?

Thank you very much for your help smiley
64  Using Arduino / Project Guidance / Re: Arduino AC Detector Help on: October 18, 2013, 12:17:50 pm
I wanted to do something similiar aggelos16, with the amazing help of the people at openenergymonitor.org we managed to put together a circuit that comes very handy.

http://openenergymonitor.org/emon/node/1050
Read through it and if you find it interesting and suits your needs let me know and I will post all the info I might find.
65  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 12:02:40 pm
IT'S WORKING !!

I splitted the string into much shorter ones, and added a delay after each of them. Seems to be working now. I will update the post with final results later...

Code:


void Send_Serial_MYSQL()
{
  //************************************************************************************************
  if (millis() - previousmillis_Send_Serial_MYSQL > interval_Send_Serial_MYSQL)
  {
      previousmillis_Send_Serial_MYSQL = millis();
      int delay_t = 100;
    // Using an Arduino MEGA for test. Send it using Serial2
      Serial2.print(F("<INSERT INTO data (B,date_uploaded,"));
      Serial2.print(F("temp_box,temp_amb,tempDHT"));
      delay(delay_t);
      Serial2.print(F(",humDHT,weather_status,Apparent_power,"));
      Serial2.print(F("Irms,ArduinoMeter) "));
      delay(delay_t);
      Serial2.print(F("VALUES ("));
      delay(delay_t);
      Serial2.print(millis());
      delay(delay_t);
      Serial2.print(F(",2013-09-28 11:22:33,44.55,66.77,"));
      delay(delay_t);
      Serial2.print(F("88.99,00.11,2.33,444.55,6.77,888.9)>"));
      
    // Show it also in the Serial monitor
      Serial.print(F("<INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT"));
      Serial.print(F(",humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) "));
      Serial.print(F("VALUES ("));
      Serial.print(millis());
      Serial.print(F(",2013-09-28 11:22:33,44.55,66.77,88.99,00.11,2.33,444.55,6.77,888.9)>"));
      Serial.println();
  }
  //************************************************************************************************
}


Receiver:
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)
      {
       // 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]);
              Serial.print(" Index: ");Serial.println(index);
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Quote
Starting
Ending
INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) VALUES (127083,2013-09-28 11:22:33,44.55,66.77,88.99,00.11,2.33,444.55,6.77,888.9) Index: 198
Starting
Ending
INSERT INTO data (B,date_uploaded,temp_box,temp_amb,tempDHT,humDHT,weather_status,Apparent_power,Irms,ArduinoMeter) VALUES (132529,2013-09-28 11:22:33,44.55,66.77,88.99,00.11,2.33,444.55,6.77,888.9) Index: 198

Thank you so much everyone.
If I confirm its all working good I will post the full sketch with comments for future reference. Then I will try to add the SD card saving function.
THANKS !!
66  Using Arduino / Programming Questions / Re: Receiving a large line by Serial port. Buffer problem on: September 30, 2013, 11:36:18 am
Sending 19 characters back for every one received is killing you. Stop it. At most print one character.

I just did the printing to see if i could figure out what was happening. if I dont print I only get...
Code:
STARTING LOGGING and WATCHDOG PROGRAM
Starting
Starting
Starting
Starting

Thank you for keep trying to help me, I know we are close, but cant make it fully work.
67  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
68  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???
69  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)
70  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)$
71  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).
72  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?
73  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
74  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.
75  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?
Pages: 1 ... 3 4 [5] 6 7 ... 95