This is an attempt to document the setup of using the hardware serial port on the arduino and a softserialport, using the newsoftserial library, and then send messages between the serial ports using the Terminal in OSX. Not particularly useful in itself, but very helpful for debugging and monitoring.
How can i program my pro mini using the native rs232 Serial port on my Mainboard (aka com1). Arduino Question Idea is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute. To upload a hex file to Arduino over Serial interface, the bootloader. JavaProxy, Simple Java serial proxy source code that further integrates with arduino. Available on the main Arduino software page, probably sourced from here. Original here is older, but the zip has a detailed readme and a more readable config file. Serproxy handles multiple serial ports, configured with a text file. A fast *.exe.
First, the hardware setup, which is extremely simple for this setup. I am using a usbserial adapter connected to the softserial ports on the arduino. I defined the softserial pins to be 2,3 (rx,tx), so the usbserial´s tx is connected to pin 2, and the rx to pin 3, also the ground from the usbserial is connected to the arduino ground. That´s all there is to it really (except plugging both the arduino and usbserial to the computer´s usb ports obviously).
The arduino code is just a slight modification of the softserial example, which echoes whatever comes in from the hardware serialport and prints it out on the softserial port and the opposite way around.
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3); //(rx,tx)
void setup()
{
Serial.begin(9600);
Serial.println(“Hello hardware serial”);
{
Serial.begin(9600);
Serial.println(“Hello hardware serial”);
// set the data rate for the NewSoftSerial port
mySerial.begin(9600);
mySerial.println(“Hello software serial”);
}
mySerial.begin(9600);
mySerial.println(“Hello software serial”);
}
void loop() // run over and over again
{
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
// delay(1000);
}
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
// delay(1000);
}
I use OSX built-in Terminal to communicate with the two serial ports, so open Terminal, and make sure you have two terminal windows (apple-N to create a new one).
![Arduino with 2 serial ports Arduino with 2 serial ports](http://www.zonnepanelen.wouterlood.com/wp-content/uploads/2017/07/figure_01_soft_96.png)
You can query the terminal for available serial ports by typing /dev/tty.*, this will give you a list of ports. You can then copy the name of the serial port you are looking for to open a serial connection. The syntax is screen serialportname baudrate. The text in bold is what I typed in.
localhost:~ hcg$ ls /dev/tty.*
/dev/tty.Bluetooth-Modem /dev/tty.hc-phone-WirelessiAP
/dev/tty.Bluetooth-PDA-Sync /dev/tty.usbserial-A4001mRQ
/dev/tty.SparkFun-BT-COM0 /dev/tty.usbserial-A6008doa
/dev/tty.W810i-SerialPort-1
/dev/tty.Bluetooth-PDA-Sync /dev/tty.usbserial-A4001mRQ
/dev/tty.SparkFun-BT-COM0 /dev/tty.usbserial-A6008doa
/dev/tty.W810i-SerialPort-1
localhost:~ hcg$ screen /dev/tty.usbserial-A6008doa 9600
in the other terminal window you want to open the other usbserialdevice, here named /dev/tty.usbserial-A4001mRQ.
When you have entered the screen command in both terminal windows you should get two empty windows, and you should get the text hardware serial and software serial (you might have to reset the arduino to see this).
now you can start typing in one window and the text will appear in the other window (it is invisible in the window you actually type it into).
One trick on my non-US keyboard layout is that I haven´t been able to find the right keyboard shortcuts to close the screen session properly. So what I do is to enable a US keyboard layout, and then ctrl-A followed by ctrl-@ will give me the option to close the session. This is on a norwegian keyboard, so not sure if this will be the same for other international variations.
Advertisements