Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) can't use serial monitor (Read 3855 times)
bb84592357
Junior Member
**
Offline


Posts: 11
Joined: Jun 12th, 2018
can't use serial monitor
Jun 23rd, 2018 at 7:08pm
Print Post  
i used this tutorial https://www.visualmicro.com/page/User-Guide.aspx?doc=Serial-Monitor.html to learn how to do input. however, data doesn't seem to be input, but RX led on arduino is turned on and off when i hit enter.

i can easily do input with arduino ide.
please help.
« Last Edit: Jun 23rd, 2018 at 7:08pm by bb84592357 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12192
Location: United Kingdom
Joined: Apr 10th, 2010
Re: can't use serial monitor
Reply #1 - Jun 24th, 2018 at 12:22pm
Print Post  
Questions

What speed is serial.begin()?

Are you using serial.print() or serial.println()?

Is Debug or Release enabled?
  
Back to top
IP Logged
 
bb84592357
Junior Member
**
Offline


Posts: 11
Joined: Jun 12th, 2018
Re: can't use serial monitor
Reply #2 - Jun 24th, 2018 at 6:18pm
Print Post  
here's the program:

Code
Select All
char buffer[18];
int red, green, blue;

int redPin = 11;
int greenPin = 10;
int bluePin = 9;

// the setup function runs once when you press reset or power the board
void setup()
{
	Serial.begin(10);
	Serial.flush();

	pinMode(redPin, OUTPUT);
	pinMode(greenPin, OUTPUT);
	pinMode(bluePin, OUTPUT);
}

// the loop function runs over and over again until power down or reset
void loop()
{
	if (Serial.available() > 0)
	{
		int idx = 0;
		delay(100);

		int numChar = Serial.available();
		if (numChar > 15)
			numChar = 15;

		while (numChar--)
			buffer[idx++] = Serial.read();

		splitString(buffer);
	}
}

void splitString(char *data)
{
	Serial.print("Data entered: ");
	Serial.println(data);

	auto param = strtok(data, ", ");
	while (param)
	{
		setLED(param);
		param = strtok(data, ", ");
	}

	// clear
	memset(buffer, 0, sizeof buffer);
	Serial.flush();
}

void setLED(char *data)
{
	if (data[0] == 'r' || data[0] == 'R')
	{
		auto ans = strtol(data + 1, nullptr, 10);
		ans = constrain(ans, 0, 255);

		analogWrite(redPin, ans);
		Serial.print("Red is set to: ");
		Serial.println(ans);
	}
	else if (data[0] == 'g' || data[0] == 'G')
	{
		auto ans = strtol(data + 1, nullptr, 10);
		ans = constrain(ans, 0, 255);

		analogWrite(greenPin, ans);
		Serial.print("Green is set to: ");
		Serial.println(ans);
	}
	else if (data[0] == 'b' || data[0] == 'B')
	{
		auto ans = strtol(data + 1, nullptr, 10);
		ans = constrain(ans, 0, 255);

		analogWrite(bluePin, ans);
		Serial.print("Blue is set to: ");
		Serial.println(ans);
	}
} 



i do debug build.

by the way, i could somehow turn on on of the LEDs with "r255" command. but then i tried again and failed.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12192
Location: United Kingdom
Joined: Apr 10th, 2010
Re: can't use serial monitor
Reply #3 - Jun 25th, 2018 at 6:22pm
Print Post  
You can't use serial.begin(10)

That would give baud rate of 10

Use serial.begin(115200)
  
Back to top
IP Logged
 
bb84592357
Junior Member
**
Offline


Posts: 11
Joined: Jun 12th, 2018
Re: can't use serial monitor
Reply #4 - Jun 26th, 2018 at 6:54pm
Print Post  
sorry but it didn't help.

actually i had 9600 there so i just played with numbers.

after changing to 1200, i got some weird chars printed... but the LEDs didn't light up, still.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12192
Location: United Kingdom
Joined: Apr 10th, 2010
Re: can't use serial monitor
Reply #5 - Jun 26th, 2018 at 8:08pm
Print Post  
The serial is working because the debugger uses it and you have debug enabled.

The default speed when debugging is 115200 but you can change it.

For now switch off debug by changing the tool bar from Debug to Release then use serial however you want.
  
Back to top
IP Logged
 
bb84592357
Junior Member
**
Offline


Posts: 11
Joined: Jun 12th, 2018
Re: can't use serial monitor
Reply #6 - Jun 28th, 2018 at 5:09pm
Print Post  
i changed to release and nothing changed. i still get the weird characters printed.
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12192
Location: United Kingdom
Joined: Apr 10th, 2010
Re: can't use serial monitor
Reply #7 - Jun 28th, 2018 at 6:33pm
Print Post  
1)
Change the serial monitor speed from 1200 to 115200 (or whatever your code uses)

2)
If you still see garbage then the serial statements are wrong in your code unless you are expecting non-ascii data then you will see garbage.

Show your code so we don't have to guess Smiley

Thanks



« Last Edit: Jun 28th, 2018 at 6:41pm by Tim@Visual Micro »  
Back to top
IP Logged
 
bb84592357
Junior Member
**
Offline


Posts: 11
Joined: Jun 12th, 2018
Re: can't use serial monitor
Reply #8 - Jul 1st, 2018 at 9:30am
Print Post  
i put the data rate to 120 both in code and serial monitor, and when i enter e.g. "r255" i get the red led light up.

but when i enter "b255" after that, blue led doesn't light up (red is still on). so what? Serial.available() doesn't work?

the code is the same as above, i just changed Serial.begin(10) to Serial.begin(9600)
« Last Edit: Jul 1st, 2018 at 9:30am by bb84592357 »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12192
Location: United Kingdom
Joined: Apr 10th, 2010
Re: can't use serial monitor
Reply #9 - Jul 5th, 2018 at 10:48pm
Print Post  
I don't think you have the exact same code in arduino. You also need to look at which line terminator you are using on the monitor. Plus you have not said why your code only does something after 15 chars have been received.

I think your code can be simplified a lot and then it will work. Add some serial messages to your code to let you know what it is doing and receiving or not processing.

« Last Edit: Jul 5th, 2018 at 10:51pm by Tim@Visual Micro »  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint