2 microcontrollers, 1 roboclaw

General discussion of using Roboclaw motor controllers
Post Reply
apollo63740
Posts: 7
Joined: Tue Mar 13, 2018 6:47 pm
2 microcontrollers, 1 roboclaw

Post by apollo63740 »

Is it possible to use two raspberry pi (or any other device) to control one roboclaw (particularly the 2x30)?

background: I have a system that was set up with one raspberry pi 3 B+ and a roboclaw 2x30a. It works fine for about 95% of what I need. However, one subsystem causes the programming to have a hiccup that is not acceptable with the current setup. Reading online, I came to the understanding that if you have one device connected via serial connection and using packet serial that another device could also be connected to the same roboclaw via usb and use packet serial also. When I set a different raspberry pi to do one task and control one of the motors, the pi connected via usb seems to get what I can only explain as some kind of feedback from the roboclaw. The first setup still works fine that is connected via UART on raspberry pi. The second system works properly UNTIL I plug in the usb to the roboclaw. At that point, the GPIO pin I am polling seems to go haywire. The physical connection shows that it is acting properly, however the program thinks the button is continuously being changed between high and low. Am I missing something obvious here? The problem occurs even if only have the usb connected to one pi and the other one removed.

I can upload the code if needed, however, I feel like this is more of a hardware issue since everything is operating as expected without the roboclaw plugged in.

Thanks for you help!
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: 2 microcontrollers, 1 roboclaw

Post by Basicmicro Support »

Ill need you to describe this again because Im not following it. You say a GPIO goes nuts but are talking about USB connections. Do you mean a GPIO on the RPi? That would indicate you have a problem on your code side. If so you need to narrow down to the minimum code required to reproduce the problem.
apollo63740
Posts: 7
Joined: Tue Mar 13, 2018 6:47 pm
Re: 2 microcontrollers, 1 roboclaw

Post by apollo63740 »

I have one raspberry pi using packet serial to a roboclaw via the GPIO Rx/Tx pins and all is working fine on that one. I have another raspberry pi hooked to the same roboclaw via USB which is having the problem. The problem is the one and only one GPIO pin using to determine whether a switch is being activated will not behave properly. I can use a multimeter (don't have a scope available can test with) and it reads 2.7V when high and about 13mV when low which is well within what the pi will recognize as logic high and low at all times and all setups I have tried. If I do not have the usb connection to the roboclaw attached, the program reads the state perfectly fine. When I have the usb connection attached to the roboclaw, the program reads as the pin is continually shifting high and low. I have tested with the other pi completely removed and only the usb and motors connected. Also, if this makes a difference, If I power on the roboclaw while the pi is connected via usb, it reboots the pi. I have narrowed it down to just code required to access the roboclaw and display a cmd line message saying on/off depending on the state of the switch and the problem is still there. I don't know if I did any better at explaining it or not.

Below is the simple sample code use for the minimalist testing. RC_SEEN just verifies that can talk to the roboclaw before letting the program continue. With this, I should be getting continual HIGH or LOW but get them alternating whether the button is pressed or not. It works fine when unplug the usb between the roboclaw and the pi.

Code: Select all

#include <wiringPi.h>
#include <stdio.h>
#include "roboclawusb.h"
#include <iostream>


//constants
RoboClaw rc = RoboClaw();

int PIN_NUMBER = 26;

void RC_SEEN()
{
	char version[512];
	int retry = 0;
	
	while (retry < 10)
	{
		if (rc.ReadVersion(version))
		{
			std::cout << "ReadVersion: " << version << std::endl;
			std::cout << "GETVERSION Passes" << std::endl;
			break;
		}
		else
		{
			retry++;
			std::cout << "Failed try " << retry << std::endl;
			delay(100);
		}
	}
	
	if (!rc.ReadVersion(version))
	{
		std::cout << "ReadVersion: " << version << std::endl;
		std::cout << "GETVERSION Failed!" << std::endl;
		while (TRUE)
			delay(5000);
	}

	delay(500);
}

int main()
{
	// setup variables and initializing
	wiringPiSetupSys();  //initialize WiringPi for BCM numbering
	rc.begin(B19200);
	RC_SEEN();

	pinMode(PIN_NUMBER, INPUT);
	pullUpDnControl(PIN_NUMBER, PUD_UP);


	while (TRUE)
	{
		if (digitalRead(PIN_NUMBER) == 0)
			std::cout << "LOW" << std::endl;
		else if (digitalRead(PIN_NUMBER) == 1)
			std::cout << "HIGH" << std::endl;
	}	return 0;
}
apollo63740
Posts: 7
Joined: Tue Mar 13, 2018 6:47 pm
Re: 2 microcontrollers, 1 roboclaw

Post by apollo63740 »

I am not using a usb isolator. Could this be a ground path loop issue?
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: 2 microcontrollers, 1 roboclaw

Post by Basicmicro Support »

Yes, this could be a ground loop problem. Is the Pi powered separately from the Roboclaw? If so the difference in ground levels when you power on the Roboclaw could be causing the Pi reset.

If you are powering the Pi from a PC USB port and the Roboclaw from a bench top power supply, for example, the ground between them can be significantly different.

If you are powering the Roboclaw from a Battery and the only ground connection between the Pi and Roboclaw is the USB this would NOT be a ground loop issue.
apollo63740
Posts: 7
Joined: Tue Mar 13, 2018 6:47 pm
Re: 2 microcontrollers, 1 roboclaw

Post by apollo63740 »

I was using a wall wart style connection on the pi but have switched it to being powered thru the 5v supply of the roboclaw with no change. The only connections to the pi are for the switch (ground and pin both from the gpio with physical pullup to 3.3 rail of pi), the usb connection to the roboclaw. and the power from the roboclaw to the pi.

Any other ideas on what could be causing the issue? I am at a loss currently..... :cry:
User avatar
Basicmicro Support
Posts: 1594
Joined: Thu Feb 26, 2015 9:45 pm
Re: 2 microcontrollers, 1 roboclaw

Post by Basicmicro Support »

After talking with you on the phone the problem appears to be on the RPi itself. There is no reason I can think of, plugging a USB device into the PI would cause any kind of GPIO change on the PI and as you said on the phone you have no other connection from the Roboclaw other than the USB connection.

I recommened changing from WiringPi to RPi.GPIO to see if its some hickup in WiringPI.

Post Reply