Serial COM Ok with Monitor, but Not other programs

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
TomHumbleAndHandsome
 
Posts: 99
Joined: Mon Feb 15, 2021 6:38 pm

Serial COM Ok with Monitor, but Not other programs

Post by TomHumbleAndHandsome »

Serial Communications with my Itsy Bitsy works great with the Serial Monitor in the Arduino environment but not with a program I wrote in C#. However, when I run the Itsy Bitsy program on an Arduino, it communicates with both the Serial Monitor AND the program I wrote in C#.

In other words:

Using the Arduino IDE serial monitor with my Itsy Bitsy, serial communications works perfectly.
Using the program I wrote in C#, the Itsy Bitsy doesn't receive bytes.
However
Using the Arduino IDE serial monitor OR using the program I wrote in C#, the Arduino running the same code as I tried on the Itsy Bitsy, works perfectly.

I've tried multiple Itsy Bitsys, and both the 3v and 5v versions. Always the same results. I see two possibilities:

1. The USB converter that is used for Itsy Bitsy (but not Arduino) doesn't play nice with C# for some reason,
2. I'm not as smart as I thought I was...

I'm including both the Itsy Bitsy / Arduino code.
I'm also including the C# program for reference.

Code: Select all

[attachment=0]Example.txt[/attachment]
Attachments
Example.txt
(1.9 KiB) Downloaded 7 times

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Serial COM Ok with Monitor, but Not other programs

Post by Franklin97355 »

You downloaded it incorrectly. I reloaded it for you

Code: Select all

////////////////////////////////////////////////////
// ARDUINO / ITSY BITSY CODE
////////////////////////////////////////////////////

// My program created in Visual Studio using C# sends and receives
// bytes to Arduino. So I know the code is working. It also works
// if I send/received bytes using the Serial Monitor in the Arduino
// environment.

// However, when I switch to using an Itsy Bitsy (same results with
// 5V or 3V) then it only works with the Serial Monitor; the C# Code
// running in the VS environment doesn't seem to be able to send or
// received bytes.

//	Board		Host				Suspect Line of Code
//	-------------------------------------------------------------------------------====;
//	Arduino		Serial Monitor		'X' is received, serial monitor says "Hello, Host!"
//	Arduino		C# Visual Studio	'X' is received, c# program says "Hello, Host!"
//	Itsy Bitsy	Serial Monitor		'X' is received, serial monitor says "Hello, Host!"
//	Itsy Bitsy	C# Visual Studio	suspect line returns false, nothing received or sent


void setup()
{
	Serial.begin(9600);
	delay(1000);
}


void loop()
{
	char rc;
	if (Serial.available())					// suspect line of code
	{
		rc = Serial.read();
		if (rc == 'X')
		{
			digitalWrite(13, HIGH);
			Serial.print("Hello, Host!");
		}
		else
		{
			digitalWrite(13, LOW);
		}
	}
}




////////////////////////////////////////////////////
// LAPTOP / C# Visual Studio Program
////////////////////////////////////////////////////
public Form1()
{
	InitializeComponent();

	sp.BaudRate = 9600;
	sp.PortName = "COM7";		// this port has Itsy Bitsy
	sp.Open();					// open serial port

	// set serial port callback routine
	sp.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.sp_DataReceived);
}

private void buttTest_Click(object sender, EventArgs e)
{
	sp.WriteLine("X");			// send the letter X to the Itsy Bitsy
}

User avatar
TomHumbleAndHandsome
 
Posts: 99
Joined: Mon Feb 15, 2021 6:38 pm

Re: Serial COM Ok with Monitor, but Not other programs

Post by TomHumbleAndHandsome »

Thanks for that Franklin.

I just ordered a new cable that goes from USB C to micro USB so I don't have to use a converter. I doubt if it will make a difference but it's worth a shot.

Thinking... "What does the Serial Port Monitor do that my C# program does NOT do, and why does it only matter for the Itsy Bitsy."

User avatar
TomHumbleAndHandsome
 
Posts: 99
Joined: Mon Feb 15, 2021 6:38 pm

Re: Serial COM Ok with Monitor, but Not other programs

Post by TomHumbleAndHandsome »

I STUMBLED ONTO THE ANSWER

In My C# Program, I need to set RTS ENABLE to TRUE if I'm using an Itsy Bitsy.

If I'm using an Arduino UNO then it doesn't seem to matter if I enable it or not.

And the Serial Monitor in the Arduino IDE is smart enough to enable RTS all the time, whereas I... was not.

So my last question is to the forum moderator. What do I do now. How do I close this? Or DO I close this or is that your job?


~Nobody ever makes smart mistakes!

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Serial COM Ok with Monitor, but Not other programs

Post by Franklin97355 »

If you want to remove this topic I can do that for you but it might help others with similar problems. Let me know what you want.

User avatar
TomHumbleAndHandsome
 
Posts: 99
Joined: Mon Feb 15, 2021 6:38 pm

Re: Serial COM Ok with Monitor, but Not other programs

Post by TomHumbleAndHandsome »

Hi franklin97355 - I'm new to using this (or any) forum. I wasn't sure what is supposed to be done once a solution has been discovered.
So yes, if you think this will help anyone else then by all means, leave it up. I can't be the only one who makes mistakes :-)

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”