philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

GPIO - UART - Getting Weird Serial Output... Stumped...

Tue Feb 12, 2013 9:53 pm

Hi all....

I'm trying to get the GPIO working as a functional UART...

I've read everything i can find online about the setup.... but just cant get it working.

I've got a Arduino UNO on the other end of the UART line, then i plug this into computer to dump serial from the pi.

The output i get is from what i can tell scrabled.... :(

I've checked the baud rate on both UARTS and its fine between comp and uno.

The problem comes from the UNO to the pi.

When i boot with the serial in. i can see via HDMI the kernel is booting, over in serial montior (or minicom or screen) i can see data coming back.... BUT its nonsence....

While Kernel is booting i get this sort of thing....
���e������e������e������e���
���e������e������e������e���

Once the kernel is loaded, i login and get full su -s access...
I then tried just a simple

Code: Select all

echo "hello" > /dev/ttyAMA0
I get more gibberish in monitor.... :(

It looks like some letters are getting through but it not simply replacing chars with '?' its adding some and removing others.... Very weird no...?

If i fire up minicom and start typing it sends every char perfectly to the comp...

Where have i gone wrong..??

Is it because im using SoftwareSerial (TX10,RX11) to talk to RaPi...??
Why does it work with minicom and nothing else....??


Also i've edited the /boot/cmdline.txt and /etc/inittab like the other posts suggest....
But i still get Gibberish on Serial at boot up....

Any ideas what could be causing this...? is it the setup of UART...? have i fried my GPIO....?


#UNO SKETCH#

Code: Select all

#include <SoftwareSerial.h>

#define rxPin 11
#define txPin 10
#define ledPin 13

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup()  {
  Serial.begin(115200);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(115200);
  Serial.println("Hello World - SoftwareSerial");
}
int byt = 0;
void loop() {
  if (mySerial.available()>0){
    byt = mySerial.read();
    Serial.println(byt);
      toggle(ledPin);
 }
}

void toggle(int pinNum) {
  // set the LED pin using the pinState variable:
  digitalWrite(pinNum, pinState); 
  // if pinState = 0, set it to 1, and vice versa:
  pinState = !pinState;
}

Im using the std 115200 for both UARTS.... I know between the UNO and Comp is fine because i dump some text at arduino startup and that text is fine....


Please, any help would be amazing... ^__^

User avatar
daveake
Posts: 184
Joined: Thu Jul 12, 2012 12:07 am

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Tue Feb 12, 2013 11:06 pm

First thing I'd do is to get that baud rate down, on both ends of course, to something more reasonable. 115,200 baud is going to be a bit of a push for the software UART on the Uno, particularly as it will also be servicing h/w interrupts for the real UART. Try 9600 and work up. At a guess 38,400 will work but not higher.

philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Tue Feb 12, 2013 11:25 pm

I've managed to work out that my /dev/ttyAMA0 is set to baud 9600....

This might be causing most the issues...

You can use

Code: Select all

ssty -F /dev/ttyAMA0
in root shell and it'll tell you.

I dont understand this.... All i did was follow the instructions to the word...
Why would it be set to 9600..?
Shouldnt it be on 115200 by default...?

Im just testing the new baud now and its still not right... :(
Im using 9600 on both UNO and pi now and still getting extra bytes with weird data...

here are the dumps from the uno

Code: Select all

echo -e "\x1" > /dev/ttyAMA0
->[]->5->101
->[5]->53->110101
->[R]->82->1010010
->[þ]->254->11111110

Code: Select all

echo -e "\x2" > /dev/ttyAMA0
->[	]->9->1001
->[5]->53->110101
->[R]->82->1010010
->[þ]->254->11111110

Code: Select all

echo -e "\x3" > /dev/ttyAMA0
->[
]->13->1101
->[j]->106->1101010
->[R]->82->1010010
->[þ]->254->11111110

Code: Select all

echo -e "\x4" > /dev/ttyAMA0
->[]->17->10001
->[5]->53->110101
->[R]->82->1010010
->[þ]->254->11111110
WEIRD...!!!!
Why would the first byte of a 4 byte packet go up by 4 when sending 1,2,3,4...??

Code: Select all

echo a > /dev/ttyAMA0
->[…]->133->10000101
->[5]->53->110101
->[)]->41->101001
->[þ]->254->11111110
What is going on...? I'm stuck, 1 byte sent to /dev/ttyAMA0
4 bytes being sent... most garbage

dolson14
Posts: 21
Joined: Sat May 12, 2012 12:20 am
Contact: Website

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Wed Feb 13, 2013 1:27 am

I've been trying to figure out the UART as well; encountered a problem as detailed in this thread: http://www.raspberrypi.org/phpBB3/viewt ... 28&t=33118

Using stty -F /dev/ttyAMA0, I get that my installation is at 38400 baud. I was expecting 115200 as well, as all the tutorials seem to say that's what it should be. Now when I connect at that rate, I see a bit of gibberish while booting, then it gives me the login prompt:

Code: Select all

��K�PY,,��z:�z�;դ�rzfx��=�r�m�������
Arch Linux 3.6.11-5-ARCH+ (ttyAMA0)

alarmpi login: 
You'll note that I'm using Arch; perhaps that has something to do with the different baud rate?

I was also expecting to see the stream of messages during bootup; only got the gibberish.

Once I get to the login, it behaves more or less normally. Every now and then there's a weird byte transmitted, but I'm able to log in and move around.

Does someone have some details on how this is set up? Why is it different than what we expected from all the tutorials out there on this?

philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Wed Feb 13, 2013 1:49 am

Okay i think i've narrowed it down somewhat....

My stty -f /dev/AMA0 -a
is

Code: Select all

speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^H; eof = ^D; eol = <undef>;
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 100; time = 2;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl ixon -ixoff
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
-isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke
as got from here...
http://playground.arduino.cc/Interfacing/LinuxTTY

These settings work like a charm for minicom and screen. Bytes sent as expected. One for each char sent.

When using:

Code: Select all

echo "A" > /dev/ttyAMA0
even when the -n flag is set

Code: Select all

echo -n "A" > /dev/ttyAMA0
returns

Code: Select all

->[]->5->101
->[ÿ]->255->11111111
The "A" comes back as 5 (DEC), 101(BIN)
Followed by the UART Stop Bit

However if i do the same thing from
cat > /dev/ttyAMA0
press "A", then Ctrl + D (to end cat)
I get only the Correct data sent...

Code: Select all

->[A]->65->1000001
No Stop Bit, Correct Value....

I'm stuck again...!!!

Why does cat work but echo fails...?? :(

Where do i go from here...?
Why is echo being stupid and sending stupid data...??
This cant be tty issue because minicom, screen and cat work fine, as expected....

I tried

Code: Select all

echo -en "0x41" > /dev/ttyAMA0
to see if it might be todo with utf8 or multi byte encodings but still came back as 5 (DEC), with 255 stop bit...


Please Please.....Someone out there knows why this is being stupid...It must be software somewhere...

Any ideas...?

philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Wed Feb 13, 2013 1:58 am

dolson14 wrote:I've been trying to figure out the UART as well; encountered a problem as detailed in this thread: http://www.raspberrypi.org/phpBB3/viewt ... 28&t=33118

Code: Select all

��K�PY,,��z:�z�;դ�rzfx��=�r�m�������
I think this is because of 2 possible reasons...
1, the UART on the RasPi is sending stupid data on UART until it is initilized, i think a pull up resistor would solve this if it was that....[Possible]
or
2, the RasPi is changing the baud rate as it likes during boot....
Its the same on mine, even tho i turned off the tty in /boot/cmdline.txt it still dumps rubbish at the start...I played with baud settings and couldnt get it to work....Might take a look at this after i get the echo crap sorted...

:)

philpoore
Posts: 6
Joined: Tue Feb 12, 2013 5:10 pm

Re: GPIO - UART - Getting Weird Serial Output... Stumped...

Wed Feb 13, 2013 2:39 am

I dont know what causes echo to give funny data to serial link....

The wiringPi.h c libs do what i need them todo so im gunna give up on the echo examples...

Just to see, i make a simple program using wiringpi.h
It takes 1 command line arg, a string, and dumps it across UART on the pi...

Simple but Exaclty how the echo examples should have worked....


Phil

Return to “Troubleshooting”