Go Down

Topic: Serial Problem (Arduino Due) - Newbie (Read 263 times) previous topic - next topic

hugof86

Hello Guys,

I'm getting strange valor in serial monitor using this code (and gets worst with different baud rates):

Code: [Select]


#include <SPI.h>
#include <stdlib.h>

#define MISO 1
#define SCK 2
#define MOSI 4
#define CS_ADC_MPPC1 10

byte EnviarMSB = 0;
byte EnviarLSB = 0;
unsigned short EnviarB = 0;
long  Tempo = 0;
long  Contagens = 0;
byte Receber = 0;

unsigned int AContagens[512];

void setup() {
  Serial.begin(9600);
  Tempo = millis();
}


void loop()
{
  delay(250);
  while(Serial.available() == 0){} 
  Receber = Serial.read();
  for(int i = 0; i < 511; i++)AContagens[i] += i;
  delayMicroseconds(100); Serial.write(255); delayMicroseconds(100);
  for(int i = 0; i < 511; i++)
  {
    Serial.println("1231");
  }
}



Data with 9600 baud rate:

ÿ'šŠj
1231
1231
12ó
                         (Line 4)

--> Send a byte by serial.

12óÿ1231                               (Line 4)             
1231
1231
1231
1231
1231
1231
1231
1231

...
Goes well until the end..

If I change the baud rate to other speed it's a lot worst. Someone have a clue of what is going on? I'm using a Arduino Due. Thanks for any answers.

Robin2

Please rewrite the code with one statement on each line and use auto-format to indent it properly so we can read it.

What is the Serial.write(255) for - that is not a printable character ?

When you try to send 512 copies of "1231" without any delay between them you may be overloading the system. As a test, try putting in delay(200);  and see what happens

...R

tammytam

This already in Serial:

Quote
ÿ'šŠj
1231
1231
12ó    
You send a byte with value of 255, which is the character 'ÿ', then you send a load of strings "1231" with new lines after each.

So it is working as intended? Or are you asking where that initial serial output came from?

hugof86

Code: [Select]
So it is working as intended?

Look to the line 4 i got "12ó" should i got 1231 no?


That's the problem, where that initial serial output came from? And how can i delete when i open the serial monitor?

P.S.: When i open the serial monitor i get right a way 4 string. It was expected that i wont get nothing from serial monitor cause of this:

Code: [Select]
while(Serial.available() == 0){}


With a baud rate of 57600 is very strange as u can see. This is the output in serial monitor after send the byte:

Quote
''''''''''''''''''''''
Quote
What is the Serial.write(255) for - that is not a printable character ?
To tell other device that i'm sending the 512 copies. (p.s: 1231 is just a number to test what is wrong)

Quote
When you try to send 512 copies of "1231" without any delay between them you may be overloading the system. As a test, try putting in delay(200);  and see what happens
I think is not overloading but with the delay(200); i get just 1 line when i start serial monitor. I don't want anything.

P.S.: The code seems to work well on Arduino Uno, i'm getting problems with due.

Robin2

P.S.: The code seems to work well on Arduino Uno, i'm getting problems with due.
Now he tells us ....

I don't know anything about a DUE.
I had been assuming that what works on an Uno would also work on a DUE

...R

hugof86

Sorry :( Is in the title "Arduino Due"

tammytam

Yep, Don't know anything about the Due either, think there's a forum dedicated to it and its peculiarities :D.

Just out of curiosity however, you don't have anything connected to the RX line do you?

hugof86

No, the pins are all disconnected. Thanks for the answers :)

MorganS

Is this on the native or programming port?

Native is not really a serial connection. It's a simulation that looks like serial. If you want to see the first characters sent after the Due resets, you need to wait for the PC to connect the USB channel. Use the same code as for a Leonardo or Micro:
Code: [Select]
//this will wait forever until the PC connects:
void setup() {
  Serial.begin(9600);
  while(!Serial);
}

//this will wait up to 5 seconds, then proceed with or without a PC connected:
void setup() {
  Serial.begin(9600);
  unsigned long start = millis();
  while(!Serial && millis()-start < 5000);
}


The programming port is a serial connection like an Uno or most other Arduinos. Sometimes you will see garbage from the Arduino when connecting, as the Arduino was sending data before it was reset by the connect action.
GoForSmoke: "What GShield? You never mentioned a shield."

Go Up