Softwareserial Github

0 views
Skip to first unread message

Millard Winnin

unread,
Aug 4, 2024, 8:44:54 PM8/4/24
to teineacilkiss
Isthere a way to both control a servo and to maintain a softwareserial connection on an Arduino UNO board? I know the two default libraries conflict, because they both need to use timer1 or something like that.

Even if you can't do debug prints to Serial, you might be able to use AltSoftSerial for debug prints. Connect pins 8 & 9 to a TTL Serial-to-USB adapter (aka FTDI). AltSoftSerial is the best software serial library, but it disables PWM on pin 10 (on an UNO).


No, SoftwareSerial does not use a timer. But it's programmed so badly that it blocks the complete CPU during send out and reception of complete bytes. As the timer interrupts are not handled during this time, the signaling for the servos get out of sync.


You might get it to work if you let the hardware PWM do all the servos stuff and use one of the interrupt serial emulations but the best solution is definitely as -dev suggested: use the hardware serial interface. If you need more than one serial interface, change the hardware platform (Leonardo has one additional hardware serial, Mega2560 has 3 additional hardware serial interfaces).


The only thing you need to be aware of is that ServoTimer2.write() takes a pulse length in microseconds not a 0-180 angle, so it is equivalent to Servo.writeMicroseconds() not Servo.write(). If you try doing write(90) nothing will happen because 90 microseconds is below the minimum.


... will not get called for 1 complete character time, because SoftwareSerial disables interrupts. I suppose if your pulse width is much longer than 1 character time (1ms @ 9600), you may not notice the difference. The performance gets worse with slower baud rates and/or shorter pulse width.


If it worked for you, it may be because you weren't receiving much data, or the servo smoothed out some of the spikes... simple inertia. You may not know it without an oscilloscope. Or maybe the servo didn't quite act like you expected, and you added a fudge factor?


I can't use hardware serial because I need both usb serial output and serial communication over bluetooth with a HC-05 module, so yes it's a general serial device. I tried AltSoftSerial as well, but I think that library occasionally dropped serial communication bytes when used together with a servo.


pylon:

No, SoftwareSerial does not use a timer. But it's programmed so badly that it blocks the complete CPU during send out and reception of complete bytes. As the timer interrupts are not handled during this time, the signaling for the servos get out of sync.


I am trying to compile a project with Platformio, using an ESP32 and the Espsoftwareserial library and another that uses a serial connection for communication between devices (FRSKY). When compiling it gives me an error that it cannot find the file included in the library.


First give warning

Library Manager: Installing dok-net/ghostl @ ^1.0.0

Library Manager: Warning! Could not install 'owner': 'dok-net', 'name': 'ghostl', 'version': '^1.0.0' dependency for the EspSoftwareSerial package

and then error

3a8082e126
Reply all
Reply to author
Forward
0 new messages