# Connection closed by remote host

**URL:** <https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384>\
**Category:** Pi Image\
**Created:** [November 4, 2019, 6:35pm UTC](https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384 "2019-11-04T18:35:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kota](https://forum.ubiquityrobotics.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Kota](https://forum.ubiquityrobotics.com/u/Kota)\
**Post date:** [November 4, 2019, 6:35pm UTC](https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384/1 "2019-11-04T18:35:43Z")

</div>

Hello,  
I’m using ubiquity ROS image and PIGPIO to use GPIO, but when I try to use GPIO with rosrun etc., it shows “connection closed by remote host”. Please tell me the solution.  
thanks

---

<div class="post-metadata">

**Author:** ![rohbotics](https://forum.ubiquityrobotics.com/user_avatar/forum.ubiquityrobotics.com/rohbotics/32/222_2.png) [@rohbotics](https://forum.ubiquityrobotics.com/u/rohbotics)\
**Post date:** [November 4, 2019, 7:09pm UTC](https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384/2 "2019-11-04T19:09:42Z")

</div>

Hi Kota,

This message usually means that the Pi is turning off for some reason. Could you please post the code that you are running?

Rohan

---

<div class="post-metadata">

**Author:** ![Kota](https://forum.ubiquityrobotics.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Kota](https://forum.ubiquityrobotics.com/u/Kota)\
**Post date:** [November 5, 2019, 4:37am UTC](https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384/3 "2019-11-05T04:37:43Z")

</div>

Hi Rohan,  
Thank you. This is the code.  
#include   
#include \<pigpiod\_if2.h\>  
#include \<ros/ros.h\>  
#include \<std\_msgs/Int16MultiArray.h\>

using std::abs;  
using std::cout;  
using std::endl;

constexpr int wheel\_0\_pin[3] = {17, 27, 22};  
constexpr int wheel\_1\_pin[3] = {10, 9, 11};  
constexpr int wheel\_2\_pin[3] = {5, 6, 13};  
constexpr int wheel\_3\_pin[3] = {25, 8, 7};

int pwm\_right\_front, pwm\_left\_front, pwm\_right\_back, pwm\_left\_back;

class l298n {  
private:  
int gpio\_handle;  
int pwm\_pin, change\_pin1, change\_pin2;  
void front(int pwm);  
void back(int pwm);

public:  
l298n(int user\_pwm\_pin, int user\_change\_pin1, int user\_change\_pin2);  
void set(int pwm);  
};

l298n::l298n(int user\_pwm\_pin, int user\_change\_pin1, int user\_change\_pin2) {  
pwm\_pin = user\_pwm\_pin;  
change\_pin1 = user\_change\_pin1;  
change\_pin2 = user\_change\_pin2;  
gpio\_handle = pigpio\_start(0, 0);  
set\_mode(gpio\_handle, change\_pin1, PI\_OUTPUT);  
set\_mode(gpio\_handle, change\_pin2, PI\_OUTPUT);  
set\_mode(gpio\_handle, pwm\_pin, PI\_OUTPUT);  
}

void l298n::set(int pwm) {  
pwm \>= 0 ? this-\>front(abs(pwm)) : this-\>back(abs(pwm));  
}

void l298n::front(int pwm) {  
gpio\_write(gpio\_handle, change\_pin1, 1);  
gpio\_write(gpio\_handle, change\_pin2, 0);  
set\_PWM\_dutycycle(gpio\_handle, pwm\_pin, pwm);  
}

void l298n::back(int pwm) {  
gpio\_write(gpio\_handle, change\_pin1, 0);  
gpio\_write(gpio\_handle, change\_pin2, 1);  
set\_PWM\_dutycycle(gpio\_handle, pwm\_pin, pwm);  
}

void mdCallback(const std\_msgs::Int16MultiArray &msg) {  
pwm\_right\_front = msg.data[0];  
pwm\_left\_front = msg.data[1];  
pwm\_right\_back = msg.data[2];  
pwm\_left\_back = msg.data[3];  
}  
int main(int argc, char \*\*argv) {  
cout \<\< “start” \<\< endl;  
ros::init(argc, argv, “md\_info”);  
ros::NodeHandle n;  
ros::Subscriber md\_sub = n.subscribe(“wheel\_info”, 10, mdCallback);  
l298n right\_front\_wheel(wheel\_0\_pin[0], wheel\_0\_pin[1], wheel\_0\_pin[2]);  
l298n left\_front\_wheel(wheel\_1\_pin[0], wheel\_1\_pin[1], wheel\_1\_pin[2]);  
l298n right\_back\_wheel(wheel\_2\_pin[0], wheel\_2\_pin[1], wheel\_2\_pin[2]);  
l298n left\_back\_wheel(wheel\_3\_pin[0], wheel\_3\_pin[1], wheel\_3\_pin[2]);  
cout \<\< “create object” \<\< endl;  
ros::Rate loop\_rate(1000);  
while (ros::ok()) {  
cout \<\< “in loop” \<\< endl;  
right\_front\_wheel.set(pwm\_right\_front);  
left\_front\_wheel.set(pwm\_left\_front);  
right\_back\_wheel.set(pwm\_right\_back);  
left\_back\_wheel.set(pwm\_left\_back);  
ros::spinOnce();  
loop\_rate.sleep();  
}  
}

---

<div class="post-metadata">

**Author:** ![rohbotics](https://forum.ubiquityrobotics.com/user_avatar/forum.ubiquityrobotics.com/rohbotics/32/222_2.png) [@rohbotics](https://forum.ubiquityrobotics.com/u/rohbotics)\
**Post date:** [November 10, 2019, 5:12pm UTC](https://forum.ubiquityrobotics.com/t/connection-closed-by-remote-host/384/4 "2019-11-10T17:12:21Z")

</div>

Try removing the `ubiquity-leds-buttons` from your `/boot/config.txt` there may be an issue with conflicting GPIO assignments.

Barring that, make sure that your power supply to the Pi is good. Looks like you are turning motors, this may be causing your power supply to dip, and the Pi to shutdown.
