Pages: [1]   Go Down
Author Topic: Problem when using Soft Serial and Serial connections at the same time.  (Read 692 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey! I need some help with a problem I am having when using a serial and a soft serial connection at the same time. First of all for the soft serial connection I am using the USB to TTL Serial Cable from the adafruit store (https://www.adafruit.com/products/954). I have installed all the correct drivers. I am using a Mac running Mountain Lion. I am using an Arduino UNO R3.

What I want to do is send a string using a python script through the soft serial connection and read the string byte by byte on the arduino displaying each value on the serial connection as it reads it.

Here's the code:

Python Script:

Code:

import serial

ser = serial.Serial("/dev/tty.PL2303-00001014", 38400)

ser.write("Hello Adafruit")

ser.close()

Arduino Code:

Code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
     
void setup() {
 
  Serial.begin(9600);
  mySerial.begin(38400);

}

void loop() {
 
  if (mySerial.available() > 0) {
   
    char inByte = mySerial.read();
    Serial.write(inByte);
  }
   
}

On the computer I have the serial monitor opened viewing the communication coming to my serial port. The problem is that when I run the python script sending the string through the soft serial connection to the arduino, when I monitor the serial connection I am getting garbage (aÌäê¥Ñ!•) when I am supposed to get the string "Hello Adafruit". The weird thing is that when I try sending the string through the serial connection and displaying it on the serial connection, or sending the string through the soft serial connection and displaying it on the soft serial connection, the string arrives perfectly fine with no errors. I have also tried sending the string through the serial connection and displaying it on the soft serial connection but that does not work (nothing shows up at the serial monitor). I have also tried using various baud rates and using the same baud rate for the serial and soft serial connections and the results are the same.

At this point I have no idea what might be wrong. The only possible thing I can think of is that the cable I received is somehow defective but that does not make much sense since when I am sending the communication through the soft serial connection in order to display it on the soft serial connection it arrives perfectly fine. I need some help. Thank you very much for your time!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

UPDATE: I've been working all day trying to find what might be happening. I've identified that this issue happens every time with Apple computers running Mountain Lion. I made the exact same test I posted here on three Apple computers running Mountain Lion and got the same results on all of them.

I also tested a Ubuntu system and it worked there. I have yet to test a Windows system. My question is: What might be happening with Apple computers when running this test? Is it something to do with the USB to TTL Serial cable's driver for Mac? Would another method of establishing a soft serial connection (for example the FTDI Friend) work to perform this test on a Mac?

I wish someone would test and confirm these results. I would like to get to the bottom of this problem. Thank you very much for your time!
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I confess: I haven't read your post carefully... but... what may be helpful:

Use the "basic" connection (pins 0 and 1) JUST for uploading programs to your Arduino, and the "built in" serial monitor.

If you have any other serial comms wants, do them across other pins, using NewSoftSerial.

(Lots and lots... some good, some less good... on this from....

http://sheepdogguides.com/arduino/art4SeIntro.htm
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 I would at least match your baud rates. It may not be the problem but, I am a little confused if what your doing will work with the baud rates being so different.

Code:
Serial.begin(9600);
  mySerial.begin(38400);
// change baud rate to 115200 on both serial instances and Python
Logged


Pages: [1]   Go Up
Jump to: