LSS and serial printing commands in Arduino

Hello,

I’m pretty new to Lynxmotion products and Arduino, so I apologize if this is a very trivial question.

I’m working with the LSS-HT1, and using Arduino to send it commands using a Arduino Mega 2560 and the LSS Adapter Board.

In trying to run and debug my own script, I’ve run into the issue of the LSS Communication Protocol commands being printed to the serial monitor every time I send a command to the servo. For example, this is what prints to the serial monitor when I run LSS_Sweep (example from the Arduino library):
LSSserialcommands

In some cases this is convenient, but for my purposes I would rather not see these commands every time. Is there a simple way to suppress this output while being able to print other data to the serial monitor?

My first thought was that it has something to do with this line:

// Initialize the LSS bus
LSS::initBus(Serial, LSS_BAUD);

But messing with this line has lead to the servo not receiving commands at all. I’ve looked at the .h file for the LSS library but haven’t been able to figure it out.

Thanks!

1 Like

Hey @ekjaynes!

It seems what is happening here is that you are using the same serial bus for both communicating with your LSS and also your serial monitor window. Many of the Arduino boards that exist (ex: Arduino Uno and many others based on the ATmega328 chip) have only one hardware serial port. Therefore, using that port (ex: Serial) will lead to everything you do on that bus being shown in the serial monitor since it is the same hardware bus that is used with the USB<>UART interface to program/communicate with the Arduino board.

There are two typical options in this case:

  1. Use a board that has 2 or more hardware UART peripherals, such as an Arduino Mega (ex: boards based on the ATmega2560) or a Teensy (I think version 3.0 & up have 3+ hardware ports!).
  2. Use a software serial port. The LSS Arduino library actually supports software serial ports so you can call the LSS::initBus function with a software serial object instead of the hardware serial one (Serial).

For software serial, you can do so easily if you are using an LSS Adapter Board with your Arduino board and LSS.
Take any example from the LSS Arduino Library, such as LSS_Sweep and modify a few key lines to match the code below.
Main changes are:

  • Add #include for SoftwareSerial.h. This is needed to have the option of using it! :slight_smile:
  • Initiate the SoftwareSerial object (in my case it is called mySoftSerial) for pins 8/9. You can read more on our wiki about the SoftwareSerial access on the LSS Adapter Board, which is done by placing the communication switch in XBee mode.
  • Replace the word Serial with your software serial object (in this example mySoftSerial).
/*
 *	Author:			Sebastien Parent-Charette ([email protected])
 *	Version:		1.1.0
 *	Licence:		LGPL-3.0 (GNU Lesser General Public License version 3)
 *	
 *	Desscription:	Basic example of the LSS moving back and forth.
 */

#include <SoftwareSerial.h>
#include <LSS.h>

// ID set to default LSS ID = 0
#define LSS_ID		(0)
#define LSS_BAUD	(LSS_DefaultBaud)

// Create one LSS object
LSS myLSS = LSS(LSS_ID);

// Create a software serial port (LSS Adapter board used in XBee mode)
SoftwareSerial mySoftSerial(8, 9);

void setup()
{
	// Initialize the LSS bus
	LSS::initBus(mySoftSerial, LSS_BAUD);

	// Initialize LSS to position 0.0 �
	myLSS.move(0);

	// Wait for it to get there
	delay(2000);
}

Try and see if this works for you if you have a LSS Adapter Board.

Sincerely,

1 Like

I see what you’re saying about using the same serial bus for communication and the serial monitor, that makes sense! The code you included does exactly what I’m looking for.

Theoretically, if I wanted to use one of the other hardware ports with my Mega, how could I do that? Or would it just be easier to stick with the software serial port?

Thank you!

1 Like

:+1:

I just noticed you were using an Arduino Mega in your other posts on our community! Yeah, stick to hardware port since they are more reliable (hardware buffering, interrupts, etc.) whereas SoftwareSerial - while very useful - requires much overhead on the CPU to process all the signals coming in and out (basically “bit-banging” the bus using the CPU)!

If you can, it is always much preferred to use hardware peripherals! They exist specifically to reduce CPU processing, overhead, etc.!

Just use Serial2, Serial3, etc. You can find more info here about serial ports on Arduino.

I hope that helps!

Sincerely,

1 Like

hello,
I was trying this code and I keep getting this error.

no matching function for call to ‘LSS::initBus(SoftwareSerial&, long int)’
LSS::initBus(mySoftSerial, LSS_DefaultBaud);
^
static void initBus(HardwareSerial & s, uint32_t baud);
^~~~~~~
note: no known conversion for argument 1 from ‘SoftwareSerial’ to ‘HardwareSerial&’

exit status 1

Compilation error: no matching function for call to ‘LSS::initBus(SoftwareSerial&, long int)’

Did you follow the steps for the LSS Arduino Library?

Yes, I did that.

Specifically with the “LSS_Sweep” example or all of the examples and have you made any changes to it ?
What’s the board you are using ?

The library should be working on its own. I’ve just deleted it from my PC and reinstalled it using the method online and after I was still able to verify the “LSS_Sweep” example without issues.

I would uninstall the library and reinstall, to be sure.

1 Like

All the examples in the library work as expected, but the modified code above, intended to accept serial software input, is not functioning.

I am using an Arduino Uno board and LSS adapter.

Hi RoryGilmore,

I found the problem, it’s a line that need to be commented in the LSS.h file.

If you browse to the Library folder on your PC you will find the LSS.h file, open it using Notepad

File location:
C:\Users"your user name"\Documents\Arduino\libraries\Lynxmotion_Smart_Servo_-LSS-\src

Once in it, find the line 15 and add two “//” at the beginning

Before: #undef LSS_SupportSoftwareSerial
After: //#undef LSS_SupportSoftwareSerial

Save the file and try to compile again.

This is working for me As-Is and you can set the LSS Adapter switch to XBee for SoftwareSerial.

:slight_smile:

I’ve made an example with the LED for testing this.
LSS_Library_SoftSerial.zip (782 Bytes)

2 Likes

Thank you so much! It finally worked! I had been searching for the error for so long, and I couldn’t have done it without your help.

1 Like

Cool…!!

Be sure to share your project on the “Robot” section even if it’s just an idea or not even completed.
It’s always nice to see what people do with our LSS servos.

1 Like