Go Down

Topic: Problem sending raw serial data to arduino (Read 226 times) previous topic - next topic

teito79

Dec 30, 2015, 04:17 am Last Edit: Dec 30, 2015, 03:11 pm by teito79
Hi everyone,
i am trying to comunicate directly to an atmega328 on an arduino uno using serial TX/RX with a usb to TTL device (with a CH340 ic).

I created a simple sketch that accepts a command on serial port and does things according to the command content.

Code: [Select]

int inByte = 0;
bool ledPinStatus = 0;

void setup() {
  Serial.begin(9600);

  Serial.println("Setup done");

  pinMode(13, OUTPUT);
}


void loop() {

  if (Serial.available() > 0) {
    // get incoming byte:
    inByte = Serial.read();
    Serial.write(inByte);
    if (inByte == 65) {
      if (ledPinStatus == 1) {
        ledPinStatus = 0;
        digitalWrite(13, LOW);
      } else {
        ledPinStatus = 1;
        digitalWrite(13, HIGH);
      }
    }
  }

  delay(50);
}


Everything works if i test it with the usb cable: i get a correct "setup done" message when resetting the arduino and it reacts correctly to the commands i send.
When i connect it to the USB to TTL device (unplug usb and power up arduino from usb-ttl) it only gives the "setup completed" message but does not react to the data i send.
This also happens with other serial/COM monitor utilities such as windows terminal.

I tried configuring the COM settings to 9600 baud (and other values) according to the arduino sketch settings and 8 bit length with no parity.
I also tryed some more configurations and also on Linux but always got the same result.
I have the feeling that the arduino to pc communication works because the device in between is doing all the stuff self configuring but it is not configured when sending data to the arduino.

Maybe it is a matter of configuring the COM port properly...?

I tryed with arduino nano and uno rev.3
i also tryed removing the atmega328 ic from an arduino uno and connecting it to the other arduino (with correct pin tx/rx) and i get same result: "setup done" feedback but cant communicate from pc to arduino.

Any idea what am i missing?
Thanks in advance for any help

Robin2

Any idea what am i missing?
A little bit of whitespace between your paragraphs so your text is easier to read.

And, most importantly, your code.
Please use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

teito79

#2
Dec 31, 2015, 01:37 pm Last Edit: Dec 31, 2015, 02:17 pm by teito79
A little update: using SoftwareSerial library and different pins it worked as expected. I just compiled the first example of the library documentation with a little modification to fit my need.

Anyway, the sketch makes compilation fail without an instance of Serial library. Because of this i can't use pin0/1 for serial communications at the moment.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy