Arduino IDE like serial monitor in the Raspberry Pi shell: Unterschied zwischen den Versionen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche
Zeile 1: Zeile 1:
For serial communication with an Arduino I wanted a Arduino IDE like serial monitor in the Raspberry Pi shell. Since I could not a find a terminal that did support “line mode” I found another workaround.
+
For serial communication with an Arduino I wanted an Arduino IDE like serial monitor in the Raspberry Pi shell. Since I could not a find a terminal that did support “line mode” I found another workaround.  
It’s a quite simplistic approach.
+
  
  
Zeile 40: Zeile 39:
  
  
Explenation:
+
 
 +
== Explenation ==
 
<pre>stty -F /dev/ttyAMA0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts</pre>
 
<pre>stty -F /dev/ttyAMA0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts</pre>
 
'''Source:'''[http://playground.arduino.cc/Interfacing/LinuxTTY]
 
'''Source:'''[http://playground.arduino.cc/Interfacing/LinuxTTY]
 +
This one i basicaly copy and pasted it, without understanding it. It gets the serial interface in the right mode to talk to an Arduino (with 115200 baud)
  
  
I use  
+
I use:
 
<pre>cat -A /dev/ttyAMA0</pre>
 
<pre>cat -A /dev/ttyAMA0</pre>
 
to listen to the serial port.  
 
to listen to the serial port.  
Zeile 54: Zeile 55:
  
 
I use tmux split screen to be able to see both at the same time.
 
I use tmux split screen to be able to see both at the same time.
 +
 +
All of this is probably not a clean or nice solution, but it does what I wanted it to do.

Version vom 5. April 2014, 21:12 Uhr

For serial communication with an Arduino I wanted an Arduino IDE like serial monitor in the Raspberry Pi shell. Since I could not a find a terminal that did support “line mode” I found another workaround.


If you want to be able to use the Serial Port of the Raspberry Pi you will have to disable the Linux serial console first.

sudo nano /boot/cmdline.txt

Remove references to console: =ttyAMA0,115200 and kgdboc=ttyAMA0,115200

sudo nano /etc/inittab

Remove or comment the line: T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Reboot the system.

Source:[1]

Then I run the serial.sh script (you need all three for this to work)

serial.sh

#!/bin/bash
stty -F /dev/ttyAMA0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
sleep 1
tmux new-session -d  './serial-in.sh'
tmux split-window -v  './serial-out.sh'
tmux attach-session -d

serial-out.sh

#!/bin/bash
while true
do
	read a
	echo "$a" > /dev/ttyAMA0
done

serial-in.sh

#!/bin/bash
while true
do
        cat -A /dev/ttyAMA0|tr "^M$" " "
done


Explenation

stty -F /dev/ttyAMA0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

Source:[2] This one i basicaly copy and pasted it, without understanding it. It gets the serial interface in the right mode to talk to an Arduino (with 115200 baud)


I use:

cat -A /dev/ttyAMA0

to listen to the serial port. Unfortunately there are some unwanted characters at the end of a line. I’m not sure why, but I just replaced them with a space. (That way they just do not any me anymore)

To get data to the Serial port I use:

echo "$a" > /dev/ttyAMA0

I use tmux split screen to be able to see both at the same time.

All of this is probably not a clean or nice solution, but it does what I wanted it to do.